-
Notifications
You must be signed in to change notification settings - Fork 8
/
CCameraDriver.h
56 lines (43 loc) · 1.65 KB
/
CCameraDriver.h
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
#pragma once
#include "CCallback.cpp"
struct CameraInfo
{
int id, width, height;
CameraInfo(cv::VideoCapture &cam, int c_id);
};
class CServerDriver;
class CCameraDriver
{
cv::VideoCapture m_currentCamera;
CameraInfo *m_cameraInfo;
std::atomic<int> m_cameraIndex;
cv::Mat m_frame;
std::vector<CameraInfo> m_cameras;
std::atomic<bool> m_working;
void Cleanup();
protected:
float m_resScale;
float m_fps;
friend class CServerDriver;
public:
bool show;
CCameraDriver(CServerDriver *driv, float scale = 1.0);
~CCameraDriver();
void LoadCameras();
void RunAsync();
void DoRunFrame();
void ChangeCamera(int up = 1);
inline const cv::Mat GetImage() const { return m_frame; }
inline const float GetFps() const { return m_cameras.size() > 0 ? m_fps : 0.f; }
inline void SetFps(float mult = 1.0) { m_currentCamera.set(CV_CAP_PROP_FPS, m_currentCamera.get(CV_CAP_PROP_FPS) * mult); }
inline int GetWidth() const { return m_cameras[m_cameraIndex].width; }
inline int GetHeight() const { return m_cameras[m_cameraIndex].height; }
inline int GetScaledWidth() const { return (int)(GetWidth() * m_resScale); }
inline int GetScaledHeight() const { return (int)(GetHeight() * m_resScale); }
inline float GetScale() const { return m_resScale; }
inline int GetIndex() const { return m_cameraIndex; }
inline cv::VideoCaptureModes const GetMode() { return (cv::VideoCaptureModes)(int)m_currentCamera.get(CV_CAP_PROP_MODE); }
CServerDriver *driver;
CCallback<void(const CCameraDriver&, cv::Mat)> imageChanged;
CCallback<void(const CCameraDriver&, int)> cameraChanged;
};