-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCaptureCam.cpp
More file actions
81 lines (65 loc) · 1.68 KB
/
Copy pathCaptureCam.cpp
File metadata and controls
81 lines (65 loc) · 1.68 KB
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
#include "CaptureCam.hpp"
#include <iostream>
#include <pthread.h>
//CRITICAL_SECTION _critSection;
pthread_mutex_t mutex_lock;
CaptureCam::CaptureCam():capture( CV_CAP_ANY ),queueMat()
{
//capture = cvCaptureFromCAM( CV_CAP_ANY ); //old way
if( !capture.isOpened() )
std::cout << "ERROR: capture is NULL \n"<<std::endl;
// Grab the device
//capture.grab();
//InitializeCriticalSection (& _critSection);
//pthread_mutex_init(&mutex_lock, NULL);
}
CaptureCam::~CaptureCam(void)
{
capture.release();
glfwDestroyThread(this->t_id);
//glfwDestroyMutex(this->m_mutex);
//DeleteCriticalSection (& _critSection);
//pthread_mutex_destroy(&mutex_lock);
}
cv::Mat CaptureCam::getMat()
{
#ifdef __WIN32__
cv::Mat retMat = queueMat.front();
queueMat.pop();
return retMat;
#else
capture >> camFrame;
cv::flip(camFrame,camFrame,-1 );
return camFrame.clone();
#endif
}
bool CaptureCam::ready()
{
return !queueMat.empty();
}
//void *cameraThread(void* param)
void cameraThread(void* param)
{
CaptureCam *cc = (CaptureCam*)param;
// Retrieve desired sensor data (in this case the standard camera image)
cc->setThreadId(glfwGetThreadID());
while(1)
{
cc->getFrame();
}
//glfwDestroyThread(glfwGetThreadID());
}
void CaptureCam::getFrame()
{
//glfwLockMutex(m_mutex);
//EnterCriticalSection (& _critSection);
pthread_mutex_lock (&mutex_lock);
//capture.retrieve(camFrame);
capture >> camFrame;
cv::flip(camFrame,camFrame,-1 );
queueMat.push(camFrame);
//cv::imshow("show",camFrame);
pthread_mutex_unlock (&mutex_lock);
//LeaveCriticalSection (& _critSection);
//glfwUnlockMutex(m_mutex);
}