-
Notifications
You must be signed in to change notification settings - Fork 2
/
detectviewer.cpp
68 lines (53 loc) · 1.3 KB
/
detectviewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "detectviewer.h"
DetectViewer::DetectViewer(QWidget *parent) :
QOpenGLWidget{ parent },
dtcr(Detector(235, 15)),
_isFill(true)
{
}
DetectViewer::~DetectViewer()
{
}
void DetectViewer::initializeGL()
{
if (!dtcr.initPLC())
{
#ifdef _DEBUG
qDebug("%s", "无法初始化通信模块");
#endif // _DEBUG
QMessageBox::information(nullptr, "error", u8"无法初始化通信模块,请检查与触摸屏的网线连接", QMessageBox::Ok, QMessageBox::Ok);
}
auto adaptor = std::make_shared<AverCaptureAdaptor>();//初始化一个Aver采集卡视频适配器
if (!adaptor->init())//采集卡初始化
{
#ifdef _DEBUG
qDebug("%s", adaptor->errorMsg().c_str());
#endif // _DEBUG
}
dtcr.setAdaptor(adaptor);//将采集卡适配器设置到探测器类对象
dtcr.setRunning(true);
}
void DetectViewer::paintGL()
{
update();
Mat& frame = dtcr.frame();
if (frame.empty())return;
cvtColor(frame, frame, COLOR_BGR2RGB);
QImage qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
if (_isFill)
{
qframe = qframe.scaled(this->size());
}
QPainter painter;
painter.begin(this);
painter.drawImage(QPoint(0, 0), qframe);
painter.end();
}
void DetectViewer::mouseMoveEvent(QMouseEvent * event)
{
QPoint p = event->pos();
float x = p.x();
float y = p.y();
Point2f temp{ x,y };
dtcr.setMousePos(temp);
}