-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvideostreamer.cpp
79 lines (51 loc) · 1.37 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
68
69
70
71
72
73
74
75
76
77
78
79
#include "videostreamer.h"
VideoStreamer::VideoStreamer()
{
connect(&tUpdate,&QTimer::timeout,this,&VideoStreamer::streamVideo);
}
VideoStreamer::~VideoStreamer()
{
cap.release();
tUpdate.stop();
threadStreamer->requestInterruption();
}
void VideoStreamer::streamVideo()
{
if(frame.data)
{
QImage img = QImage(frame.data,frame.cols,frame.rows,QImage::Format_RGB888).rgbSwapped();
emit newImage(img);
}
}
void VideoStreamer::catchFrame(cv::Mat emittedFrame)
{
frame = emittedFrame;
}
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();
double fps = cap.get(cv::CAP_PROP_FPS);
tUpdate.start(1000/fps);
}
void VideoStreamer::streamerThreadSlot()
{
cv::Mat tempFrame;
while (1) {
cap>>tempFrame;
if(tempFrame.data)
emit emitThreadImage(tempFrame);
if(QThread::currentThread()->isInterruptionRequested())
{
cap.release();
return;
}
}
}