-
Notifications
You must be signed in to change notification settings - Fork 3
/
RealCameraDriver.h
148 lines (124 loc) · 4.2 KB
/
RealCameraDriver.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
@brief Generic Camera Driver Class
Used when cameras are connected to this computer
directly
@author Shane Yuan
@date Jan 8, 2018
*/
#ifndef __GENERIC_CAMERA_DRIVER_REAL_H__
#define __GENERIC_CAMERA_DRIVER_REAL_H__
#include "GenCameraDriver.h"
// cuda npp JPEG coder
#include "NPPJpegCoder.h"
namespace cam {
class RealCamera : public GenCamera {
protected:
// buffers to save cuda memory pointer
std::vector<Imagedata> bufferImgs_data_ptr;
std::vector<cv::Mat> bufferImgs_host;
std::vector<cv::cuda::GpuMat> bufferImgs_cuda;
// threads to capture images
std::vector<std::thread> ths;
bool isCaptureThreadRunning;
// thread to compress raw image into jpeg
std::thread thJPEG;
bool isCompressThreadRunning;
// status of capturing threads
// 0: stop capturing images
// 1: capturing images
// 2: compress images use jpeg
std::vector<int> thStatus;
// variable to exit all the threads (used for streaming mode)
// thexit == 1, exit thread
// thexit == 0, keep running
int thexit;
// NPP JPEG coders
std::vector<npp::NPPJpegCoder> coders;
// memory status
int isCaptureModeSet;
public:
protected:
/**
@brief multi-thread capturing function (raw buffer)
used for continous mode
thread function to get images from camera and buffer to vector
and wait until the next frame (based on fps)
@param int camInd: index of camera
*/
void capture_thread_raw_(int camInd);
/**
@brief multi-thread captureing function
used for single mode
thread function to get images from camera and buffer to vector
@param int camInd: index of camera
@param Imagedata & img: output captured image
*/
void capture_thread_single_(int camInd, Imagedata & img);
/**
@brief multi-thread capturing function (jpeg buffer)
used for continous mode
thread function to get images from camera and wait for compresss
thread to compress the raw data into jpeg data
@param int camInd: index of camera
*/
void capture_thread_JPEG_(int camInd);
/**
@brief single-thread compressing function
because npp only support single thread, jpeg compress function is not
thread safe
thread function to compress raw image into jpeg data
and wait until the next frame (based on fps)
*/
void compress_thread_JPEG_();
/*************************************************************/
/* virtual capturing function */
/*************************************************************/
/**
@brief capture single image of single camera
@param int camInd: input index of camera
@param Imagedata & img: output captured images
@return int
*/
virtual int captureFrame(int camInd, Imagedata & img) = 0;
public:
RealCamera();
~RealCamera();
/**
@brief set capturing mode
@param GenCamCaptureMode captureMode: capture mode
@param int size: buffer size
@return int
*/
int setCaptureMode(GenCamCaptureMode captureMode,
int bufferSize);
/**
@brief wait for recording threads to finish
@return int
*/
int waitForRecordFinish();
/**
@brief start capture threads
@return int
*/
int startCaptureThreads();
/**
@brief stop capture threads
@return int
*/
int stopCaptureThreads();
/*************************************************************/
/* function to update images in buffer */
/*************************************************************/
/**
@brief buffer next frame
@return int
*/
int reBufferFileCamera();
/**
@brief buffer next frame
@return int
*/
int bufferNextFrame();
};
};
#endif