-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapturethread.cpp
100 lines (78 loc) · 3.12 KB
/
capturethread.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//#include "opencv/highgui.h"
#include "capturethread.h"
#include "QDebug"
CaptureThread::CaptureThread(){
//returnFrame = cvCreateImage( cvSize(640, 480), IPL_DEPTH_8U, 3); //DEFAULT
}
IplImage * CaptureThread::getLatestFrame(){
//returnFrame = cvCreateImage( cvGetSize(freshFrame), IPL_DEPTH_8U, 3);
//returnFrame = cvCreateImage( cvSize(640, 480), IPL_DEPTH_8U, 3);
//frameMutex.lock();
//frameLock.lockForWrite();
//RESETTING ROI of returnimage, to make it possible copy between picture from camera and img iplimage
currentROI = cvGetImageROI(returnFrame);
cvResetImageROI(returnFrame);
if(lastWasBufferOne){
//lastWasBufferOne = true;
//qDebug() << cvGetSize(freshFrame_one).width << "x" << cvGetSize(freshFrame_one).height;
//qDebug() << cvGetSize(returnFrame).width << "x" << cvGetSize(returnFrame).height;
//qDebug() << "reading from one \n";
cvCopy(freshFrame_one, returnFrame);
}else{
//qDebug() << cvGetSize(freshFrame_two).width << "x" << cvGetSize(freshFrame_two).height;
//qDebug() << cvGetSize(returnFrame).width << "x" << cvGetSize(returnFrame).height;
//qDebug() << "reading from two \n";
//lastWasBufferOne = false;
cvCopy(freshFrame_two, returnFrame);
}
cvSetImageROI(returnFrame, currentROI);
//frameLock.unlock();
//frameMutex.unlock();
//qDebug() << "Putting thread sleep for 10ms \n";
//msleep(10);
goSleep();
//qDebug() << "Put thread sleep for 10ms \n";
return returnFrame;
}
void CaptureThread::startAcquisition(CvCapture * setCap){
cap = setCap;
lastWasBufferOne = false;
freshFrame_two = cvQueryFrame(cap); //DEFAULT VALUES
freshFrame_one = cvQueryFrame(cap);
returnFrame = cvCreateImage( cvGetSize(freshFrame_two), IPL_DEPTH_8U, 3);
//returnFrame = cvCreateImage( cvSize(640, 480), IPL_DEPTH_8U, 3);
//qDebug() << "FRESH1: " << cvGetSize(freshFrame_one).width << "x" << cvGetSize(freshFrame_one).height;
//qDebug() << "FRESH2: " << cvGetSize(freshFrame_two).width << "x" << cvGetSize(freshFrame_two).height;
//qDebug() << "RETURN: " << cvGetSize(returnFrame).width << "x" << cvGetSize(returnFrame).height;
//qDebug() << "@init written to two \n";
start(QThread::InheritPriority);
//start(QThread::LowestPriority);
//start(QThread::TimeCriticalPriority);
qDebug() << "Started Capturing thread \n";
}
void CaptureThread::goSleep(){
sleep = true;
}
void CaptureThread::run(){
while(1){
if(sleep = true){
msleep(20);
sleep = false;
}
//frameMutex.lock();
//frameLock.lockForRead();
if(!lastWasBufferOne){
freshFrame_one = cvQueryFrame(cap);
freshFrame_one = cvQueryFrame(cap);
lastWasBufferOne = true;
//qDebug() << "written to one \n";
}else{
freshFrame_two = cvQueryFrame(cap);
freshFrame_two = cvQueryFrame(cap);
lastWasBufferOne = false;
//qDebug() << "written to two \n";
}
//frameMutex.unlock();
//frameLock.unlock();
}
}