-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera_thread.h
More file actions
57 lines (40 loc) · 987 Bytes
/
camera_thread.h
File metadata and controls
57 lines (40 loc) · 987 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
45
46
47
48
49
50
51
52
53
54
55
56
//
// Created by YongGyu Lee on 2021/09/16.
//
#ifndef EYEDID_CPP_SAMPLE_CAMERA_THREAD_H_
#define EYEDID_CPP_SAMPLE_CAMERA_THREAD_H_
#include <atomic>
#include <thread>
#include <mutex>
#include <condition_variable>
#include "opencv2/opencv.hpp"
#include "simple_signal.h"
namespace sample {
/**
* A handler that runs camera in concurrent thread.
* Use on_frame_ to add or remove frame listeners
*/
class CameraThread {
public:
CameraThread();
~CameraThread();
bool run(int camera_index = 0);
void resume();
void pause();
void join();
signal<void(cv::Mat frame)> on_frame_;
private:
void run_impl();
bool check_status();
std::unique_lock<std::mutex> pause_wait();
int camera_index_ = 0;
cv::VideoCapture video_;
cv::Mat frame_;
std::thread thread_;
std::atomic_bool pause_{true};
std::mutex mutex_;
std::condition_variable cv_;
std::atomic_bool stop_{false};
};
} // namespace sample
#endif // EYEDID_CPP_SAMPLE_CAMERA_THREAD_H_