ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
Typedefs | Enumerations | Functions | Variables
zed_oc_control_example.cpp File Reference

Go to the source code of this file.

Typedefs

typedef enum _cam_control CamControl
 

Enumerations

enum  _cam_control {
  Brightness , Contrast , Hue , Saturation ,
  Gain , Exposure , WhiteBalance , Sharpness ,
  Gamma
}
 

Functions

int main (int argc, char *argv[])
 

Variables

CamControl activeControl = Brightness
 
cv::String win_name = "Stream RGB"
 
bool selectInProgress = false
 
bool selectLeft = false
 
bool selectRight = false
 
cv::Rect aecagc_roi_left = {0,0,0,0}
 
cv::Rect aecagc_roi_right = {0,0,0,0}
 
cv::Point origin_roi = {0,0}
 
double img_resize_factor = 1.0
 
int img_w = 0
 
int img_h = 0
 
bool logging = false
 
uint8_t brightness_val
 
uint8_t contrast_val
 
uint8_t hue_val
 
uint8_t saturation_val
 
uint8_t gain_val_left
 
uint8_t gain_val_right
 
uint8_t exposure_val_left
 
uint8_t exposure_val_right
 
int whiteBalance_val
 
uint8_t sharpness_val
 
uint8_t gamma_val
 
bool autoAECAGC =false
 
bool autoWB =false
 
bool applyAECAGCrectLeft =false
 
bool applyAECAGCrectRight =false
 

Typedef Documentation

◆ CamControl

typedef enum _cam_control CamControl

Enumeration Type Documentation

◆ _cam_control

Enumerator
Brightness 
Contrast 
Hue 
Saturation 
Gain 
Exposure 
WhiteBalance 
Sharpness 
Gamma 

Definition at line 31 of file zed_oc_control_example.cpp.

32 {
33  Brightness,
34  Contrast,
35  Hue,
36  Saturation,
37  Gain,
38  Exposure,
40  Sharpness,
41  Gamma
42 } CamControl;
enum _cam_control CamControl

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
zed_oc_control_example.cpp.

Definition at line 109 of file zed_oc_control_example.cpp.

110 {
111  // ----> Silence unused warning
112  (void)argc;
113  (void)argv;
114  // <---- Silence unused warning
115 
117 
118  // ----> Set Video parameters
122  params.verbose = verbose;
123  // <---- Set Video parameters
124 
125  // ----> Create Video Capture
127  if( !cap.initializeVideo(-1) )
128  {
129  std::cerr << "Cannot open camera video capture" << std::endl;
130  std::cerr << "See verbosity level for more details." << std::endl;
131 
132  return EXIT_FAILURE;
133  }
134  std::cout << "Connected to camera sn: " << cap.getSerialNumber() << std::endl;
135  // <---- Create Video Capture
136 
137  // ----> Create rendering window
138  cv::namedWindow(win_name);
139  cv::setMouseCallback(win_name, handleMouse);
140  // <---- Create rendering window
141 
142  // Reset all the controls to default values
143  resetControls(cap);
144 
145  // Set the default camera control setting
146  setActiveControl(cap, Brightness );
147 
148  // Update the values for all the controls
149  updateAllCtrlValues(cap);
150 
151  uint64_t last_ts=0;
152  uint16_t not_a_new_frame = 0;
153  int frame_timeout_msec = 100;
154 
155  // Infinite video grabbing loop
156  while (1)
157  {
158  // 3) Get last available frame
159  const sl_oc::video::Frame frame = cap.getLastFrame(frame_timeout_msec);
160  img_w = frame.width;
161  img_h = frame.height;
162 
163  // 3a) Apply AEC AGC ROI if necessary
165  {
166  applyAECAGCrectLeft = false;
167  cap.setROIforAECAGC( sl_oc::video::CAM_SENS_POS::LEFT,
169  aecagc_roi_left.width, aecagc_roi_left.height);
170  selectLeft=false;
171  selectRight=false;
172  }
174  {
175  applyAECAGCrectRight = false;
176  cap.setROIforAECAGC( sl_oc::video::CAM_SENS_POS::RIGHT,
178  aecagc_roi_right.width, aecagc_roi_right.height);
179  selectLeft=false;
180  selectRight=false;
181  }
182 
183  // ----> If the frame is valid we can display it
184  if(frame.data!=nullptr && frame.timestamp!=last_ts)
185  {
186  not_a_new_frame=0;
187 #if 0
188  // ----> Video Debug information
189 
190  std::cout << std::setprecision(9) << "[" << frame.frame_id << "] Ts: " << static_cast<double>(frame.timestamp)/1e9 << " sec" << std::endl;
191  if( last_ts!=0 )
192  {
193  double dt = (frame.timestamp - last_ts)/1e9;
194  std::cout << std::setprecision(9) << " * dT: " << dt << " sec - FPS: " << 1./dt << std::endl;
195  }
196 
197  // <---- Video Debug information
198 #endif
199  last_ts = frame.timestamp;
200 
201  // ----> Conversion from YUV 4:2:2 to BGR for visualization
202  cv::Mat frameYUV = cv::Mat( frame.height, frame.width, CV_8UC2, frame.data );
203  cv::Mat frameBGR;
204  cv::cvtColor(frameYUV,frameBGR,cv::COLOR_YUV2BGR_YUYV);
205  // <---- Conversion from YUV 4:2:2 to BGR for visualization
206 
207  // 4.c) Show frame
209  }
210  else if(frame.timestamp==last_ts)
211  {
212  not_a_new_frame++;
213  std::cout << "Not a new frame #" << not_a_new_frame << std::endl;
214 
215  if( not_a_new_frame>=(3000/frame_timeout_msec)) // Lost connection for 5 seconds
216  {
217  std::cout << "Camera connection lost. Closing..." << std::endl;
218  break;
219  }
220  }
221  // <---- If the frame is valid we can display it
222 
223  // ----> Keyboard handling
224  int key = cv::waitKey( 5 );
225 
226  if( key != -1 )
227  {
228  if(key=='q' || key=='Q') // Quit
229  break;
230  else
231  handleKeyboard( cap, key );
232  }
233  // <---- Keyboard handling
234  }
235 
236  return EXIT_SUCCESS;
237 }
The VideoCapture class provides image grabbing functions and settings control for all the Stereolabs ...
void showImage(std::string name, cv::UMat &img, sl_oc::video::RESOLUTION res, bool change_name=true, std::string info="")
Rescale the OpenCV T-API images [cv::UMat] according to the selected resolution to better display the...
Definition: ocv_display.hpp:27
@ FPS_15
15 Frames per second. Available for all the resolutions.
@ RIGHT
The right sensor.
@ LEFT
The left sensor.
VERBOSITY
Definition: defines.hpp:85
@ INFO
Definition: defines.hpp:89
The Frame struct containing the acquired video frames.
uint64_t timestamp
Timestamp in nanoseconds.
uint16_t height
Frame height.
uint64_t frame_id
Increasing index of frames.
uint16_t width
Frame width.
uint8_t * data
Frame data in YUV 4:2:2 format.
The camera configuration parameters.
RESOLUTION res
Camera resolution.
FPS fps
Frames per second.
bool applyAECAGCrectLeft
cv::String win_name
cv::Rect aecagc_roi_left
cv::Rect aecagc_roi_right
bool selectLeft
bool selectRight
bool applyAECAGCrectRight
cv::Mat frameBGR
sl_oc::video::VideoParams params
cv::Mat frameYUV

References sl_oc::video::VideoParams::fps, sl_oc::video::FPS_15, sl_oc::video::VideoCapture::getSerialNumber(), sl_oc::video::HD2K, sl_oc::INFO, sl_oc::video::VideoCapture::initializeVideo(), params, sl_oc::video::VideoParams::res, sl_oc::video::VideoParams::verbose, and win_name.

Variable Documentation

◆ activeControl

CamControl activeControl = Brightness
Examples
zed_oc_control_example.cpp.

Definition at line 44 of file zed_oc_control_example.cpp.

◆ aecagc_roi_left

cv::Rect aecagc_roi_left = {0,0,0,0}
Examples
zed_oc_control_example.cpp.

Definition at line 81 of file zed_oc_control_example.cpp.

◆ aecagc_roi_right

cv::Rect aecagc_roi_right = {0,0,0,0}
Examples
zed_oc_control_example.cpp.

Definition at line 82 of file zed_oc_control_example.cpp.

◆ applyAECAGCrectLeft

bool applyAECAGCrectLeft =false
Examples
zed_oc_control_example.cpp.

Definition at line 104 of file zed_oc_control_example.cpp.

◆ applyAECAGCrectRight

bool applyAECAGCrectRight =false
Examples
zed_oc_control_example.cpp.

Definition at line 105 of file zed_oc_control_example.cpp.

◆ autoAECAGC

bool autoAECAGC =false
Examples
zed_oc_control_example.cpp.

Definition at line 101 of file zed_oc_control_example.cpp.

◆ autoWB

bool autoWB =false
Examples
zed_oc_control_example.cpp.

Definition at line 102 of file zed_oc_control_example.cpp.

◆ brightness_val

uint8_t brightness_val
Examples
zed_oc_control_example.cpp.

Definition at line 90 of file zed_oc_control_example.cpp.

◆ contrast_val

uint8_t contrast_val
Examples
zed_oc_control_example.cpp.

Definition at line 91 of file zed_oc_control_example.cpp.

◆ exposure_val_left

uint8_t exposure_val_left
Examples
zed_oc_control_example.cpp.

Definition at line 96 of file zed_oc_control_example.cpp.

◆ exposure_val_right

uint8_t exposure_val_right
Examples
zed_oc_control_example.cpp.

Definition at line 97 of file zed_oc_control_example.cpp.

◆ gain_val_left

uint8_t gain_val_left
Examples
zed_oc_control_example.cpp.

Definition at line 94 of file zed_oc_control_example.cpp.

◆ gain_val_right

uint8_t gain_val_right
Examples
zed_oc_control_example.cpp.

Definition at line 95 of file zed_oc_control_example.cpp.

◆ gamma_val

uint8_t gamma_val
Examples
zed_oc_control_example.cpp.

Definition at line 100 of file zed_oc_control_example.cpp.

◆ hue_val

uint8_t hue_val
Examples
zed_oc_control_example.cpp.

Definition at line 92 of file zed_oc_control_example.cpp.

◆ img_h

int img_h = 0
Examples
zed_oc_control_example.cpp.

Definition at line 86 of file zed_oc_control_example.cpp.

◆ img_resize_factor

double img_resize_factor = 1.0
Examples
zed_oc_control_example.cpp.

Definition at line 84 of file zed_oc_control_example.cpp.

◆ img_w

int img_w = 0
Examples
zed_oc_control_example.cpp.

Definition at line 85 of file zed_oc_control_example.cpp.

◆ logging

bool logging = false
Examples
zed_oc_control_example.cpp.

Definition at line 88 of file zed_oc_control_example.cpp.

◆ origin_roi

cv::Point origin_roi = {0,0}
Examples
zed_oc_control_example.cpp.

Definition at line 83 of file zed_oc_control_example.cpp.

◆ saturation_val

uint8_t saturation_val
Examples
zed_oc_control_example.cpp.

Definition at line 93 of file zed_oc_control_example.cpp.

◆ selectInProgress

bool selectInProgress = false
Examples
zed_oc_control_example.cpp.

Definition at line 78 of file zed_oc_control_example.cpp.

◆ selectLeft

bool selectLeft = false
Examples
zed_oc_control_example.cpp.

Definition at line 79 of file zed_oc_control_example.cpp.

◆ selectRight

bool selectRight = false
Examples
zed_oc_control_example.cpp.

Definition at line 80 of file zed_oc_control_example.cpp.

◆ sharpness_val

uint8_t sharpness_val
Examples
zed_oc_control_example.cpp.

Definition at line 99 of file zed_oc_control_example.cpp.

◆ whiteBalance_val

int whiteBalance_val
Examples
zed_oc_control_example.cpp.

Definition at line 98 of file zed_oc_control_example.cpp.

◆ win_name

cv::String win_name = "Stream RGB"
Examples
zed_oc_control_example.cpp.

Definition at line 77 of file zed_oc_control_example.cpp.

Referenced by main().