Repository navigation
Expand file tree
/
Copy pathVideoThread.cpp
More file actions
85 lines (65 loc) · 1.68 KB
/
Copy pathVideoThread.cpp
File metadata and controls
85 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
82
83
84
85
#include "VideoThread.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace boost::posix_time;
VideoThread::VideoThread()
{
m_frame_buffer_length = 10;
}
VideoThread::~VideoThread()
{
Done();
}
void VideoThread::Run()
{
m_thread = boost::thread(boost::bind(&VideoThread::DoWork, this));
}
void VideoThread::DoWork()
{
cv::VideoCapture cap(0); // open the default camera
//cv::VideoCapture cap("/home/nghia/Projects/NAR_Demo/video/out.avi");
cv::Mat grey;
if(!cap.isOpened()) {
cerr << "Failed to initialise webcam :(" << endl;
exit(-1);
}
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
m_done = false;
m_fps = 0.0;
m_frame_count = 0;
m_last_time = boost::posix_time::microsec_clock::local_time();
m_NAR.Run();
while(!m_done) {
cv::Mat frame;
cap >> frame; // get a new frame from camera
if(frame.rows == 0 || frame.cols == 0) {
continue;
}
m_NAR.SetCameraCentre(frame.cols/2, frame.rows/2);
m_NAR.AddNewJob(frame);
m_frame_count++;
if(m_frame_count >= 8) {
boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
time_duration::tick_type t = (now - m_last_time).total_milliseconds();
m_fps = m_frame_count*1000.0f/t;
m_frame_count = 0;
m_last_time = now;
}
}
}
void VideoThread::Done()
{
m_done = true;
m_thread.join();
}
float VideoThread::GetFPS()
{
boost::mutex::scoped_lock lock(m_mutex);
return m_fps;
}
NAR& VideoThread::GetNAR()
{
return m_NAR;
}