-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencv_threaded_capture.cpp
More file actions
44 lines (40 loc) · 922 Bytes
/
opencv_threaded_capture.cpp
File metadata and controls
44 lines (40 loc) · 922 Bytes
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
#include "opencv_threaded_capture.h"
#include "timer_hd.h"
void Threaded_capture::capture_thread_func()
{
using namespace std;
cout << "\n" << cam_name << " capture thread has started\n";
Timer timer(500, "\n" + cam_name + ":\t");
cv::Mat local_frame;
while (is_running)
{
timer.tick();
if (camera->read(local_frame))
{
mx.lock();
local_frame.copyTo(frame);
mx.unlock();
new_frame = true;
}
else
{
cerr << "failed to read " << cam_name << " frame!" << endl;
return;
}
timer.tock();
cv::waitKey(1); // needed or not ?!
}
cout << cam_name << " capture thread has stopped\n";
}
void Threaded_capture::setup(std::shared_ptr<Camera> cam, std::string cam_name_)
{
cam_name = cam_name_;
camera = cam;
is_running = true;
capture_thread = std::thread(&Threaded_capture::capture_thread_func, this);
}
void Threaded_capture::stop()
{
is_running = false;
capture_thread.join();
}