-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideostreamer.cpp
67 lines (43 loc) · 1.2 KB
/
videostreamer.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
67
#include "videostreamer.h"
VideoStreamer::VideoStreamer()
{
}
VideoStreamer::~VideoStreamer()
{
cap.release();
tUpdate.stop();
threadStreamer->requestInterruption();
}
void VideoStreamer::catchFrame(cv::Mat emittedFrame)
{
QImage imgIn= QImage((uchar*) emittedFrame.data, emittedFrame.cols, emittedFrame.rows, emittedFrame.step, QImage::Format_RGB888).rgbSwapped();
emit emitQImage(imgIn);
}
void VideoStreamer::openVideoCamera(QString path)
{
if(path.length() == 1)
cap.open(path.toInt());
else
cap.open(path.toStdString());
VideoStreamer* worker = new VideoStreamer();
worker->moveToThread(threadStreamer);
QObject::connect(threadStreamer,SIGNAL(started()),worker,SLOT(streamerThreadSlot()));
QObject::connect(worker,&VideoStreamer::emitThreadImage,this,&VideoStreamer::catchFrame);
threadStreamer->start();
}
void VideoStreamer::streamerThreadSlot()
{
cv::Mat tempFrame;
while (1) {
cap>>tempFrame;
if(tempFrame.data)
{
emit emitThreadImage(tempFrame);
}
if(QThread::currentThread()->isInterruptionRequested())
{
cap.release();
return;
}
}
}