-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopencvHandle.cpp
executable file
·86 lines (69 loc) · 1.96 KB
/
opencvHandle.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
80
81
82
83
84
85
86
#include <iostream>
#include <stdio.h>
#include "opencvHandle.h"
//JJV DEBUG - There seems to be a bug with either Linux or my OpenCV version because I cannot release the capture instance properly (webcam appears to still be in use)
OPENCV_HANDLER::OPENCV_HANDLER(void)
{
this->curState = WAIT_FOR_START_CMD;
this->playVideoLoop = 0;
}
void OPENCV_HANDLER::process()
{
cv::Mat incFrame, newFrame;
QPixmap imgToShow;
int w,h;
cv::VideoCapture *videoStream;
for (;;)
{
switch ( this->curState )
{
case WAIT_FOR_START_CMD:
if (this->playVideoLoop) this->curState = INITIALIZE_CAM;
break;
case INITIALIZE_CAM:
videoStream = new cv::VideoCapture(0);
if ( !videoStream->isOpened() )
{
printf("Capture failed!");
delete videoStream;
emit error("No capture");
this->curState = ERROR_STATE;
}
this->curState = GET_FRAME;
break;
case GET_FRAME:
*videoStream >> incFrame;
if ( !incFrame.empty() )
{
//Convert the Mat object to something QT understands
cv::cvtColor(incFrame,newFrame,CV_BGR2RGB);
imgToShow = QPixmap::fromImage(QImage((unsigned char*) newFrame.data, newFrame.cols, newFrame.rows, QImage::Format_RGB888));
emit imageReady(imgToShow);
incFrame.release();
}
this->curState = CHECK_STOP;
break;
case CHECK_STOP:
if (this->playVideoLoop == 0) this->curState = CLEAR_INTERFACE;
else this->curState = GET_FRAME;
break;
case CLEAR_INTERFACE:
videoStream->release();
delete videoStream;
this->curState = WAIT_FOR_START_CMD;
break;
case ERROR_STATE:
this->playVideoLoop = 0;
break;
}
}
emit finished();
}
void OPENCV_HANDLER::startStream(void)
{
this->playVideoLoop = 1;
}
void OPENCV_HANDLER::stopStream(void)
{
this->playVideoLoop = 0;
}