forked from embeye/QEmbeddedEye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qframecapturethread.cpp
70 lines (52 loc) · 1.78 KB
/
qframecapturethread.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
#include "qframecapturethread.h"
#include <QDebug>
QFrameCaptureThread::QFrameCaptureThread(int camNumber, int timeToSleep, QObject *parent) : QThread(parent)
{
mTimeToSleep = timeToSleep;
mCamNumber = camNumber;
mCam = new cv::VideoCapture();
}
QFrameCaptureThread::~QFrameCaptureThread()
{
if(mCam->isOpened()){
mCam->release();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QFrameCaptureThread::openCamera(int camNum){
if(mCam->isOpened()){
mCam->release();
}
mCamNumber = camNum;
mCam->open(mCamNumber);
mCam->set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
mCam->set(CV_CAP_PROP_FRAME_WIDTH, 640);
mCam->set(CV_CAP_PROP_FRAME_HEIGHT, 480);
}
////////////////////////////////////////////////////////////////////////////////////////////////
bool QFrameCaptureThread::isCameraOpen(){
return mCam->isOpened();
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QFrameCaptureThread::setTimeToSleep(int ts){
mTimeToSleep = ts;
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QFrameCaptureThread::run(){
while(true){
if(mCam && mCam->isOpened()){
mCam->read(mOriginalFrame);
emit sendFrame(&mOriginalFrame);
if(mTimeToSleep>0)
{
msleep(mTimeToSleep); // sleep for some time
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
void QFrameCaptureThread::terminateCamera(){
if(mCam->isOpened()){
mCam->release();
}
}