ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
zed_oc_control_example.cpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2021, STEREOLABS.
4 //
5 // All rights reserved.
6 //
7 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
8 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
10 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
15 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
16 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
17 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 //
20 
21 // ----> Includes
22 #include "videocapture.hpp"
23 
24 #include <iostream>
25 #include <iomanip>
26 
27 #include <opencv2/opencv.hpp>
28 // <---- Includes
29 
30 // ----> Camera settings control
31 typedef enum _cam_control
32 {
35  Hue,
41  Gamma
43 
45 // <---- Camera settings control
46 
47 // ----> Global functions to control settings
48 // Rescale the images according to the selected resolution to better display them on screen
49 static void showImage( std::string name, cv::Mat& img, sl_oc::video::RESOLUTION res );
50 
51 // Handle Keyboard
52 static void handleKeyboard( sl_oc::video::VideoCapture &cap, int key );
53 
54 // Handle Mouse events
55 static void handleMouse(int event, int x, int y, int, void*);
56 
57 // Change active control
58 static void setActiveControl(sl_oc::video::VideoCapture &cap, CamControl control );
59 
60 // Set new value for the active control
61 static void setControlValue( sl_oc::video::VideoCapture &cap, int value );
62 
63 // '+' or '-' pressed
64 static void changeControlValue( sl_oc::video::VideoCapture &cap, bool increase );
65 
66 // 'a' or 'A' pressed to enable automatic WhiteBalanse or Gain/Exposure
67 static void toggleAutomaticControl( sl_oc::video::VideoCapture &cap );
68 
69 // Retrieve all the control values from the camera
70 static void updateAllCtrlValues(sl_oc::video::VideoCapture &cap);
71 
72 // Reset all the control values to default
73 static void resetControls( sl_oc::video::VideoCapture &cap );
74 // <---- Global functions to control settings
75 
76 // ----> Global variables
77 cv::String win_name = "Stream RGB"; // Name of the stream window
78 bool selectInProgress = false; // Indicates that an AECAGC ROI is being drawn
79 bool selectLeft = false;
80 bool selectRight = false;
81 cv::Rect aecagc_roi_left = {0,0,0,0}; // The current agcaec ROI rectangle
82 cv::Rect aecagc_roi_right = {0,0,0,0}; // The current agcaec ROI rectangle
83 cv::Point origin_roi = {0,0}; // Click point for AECAGC ROI
84 double img_resize_factor = 1.0; // Image resize factor for drawing
85 int img_w = 0; // Camera image width
86 int img_h = 0; // Camera image height
87 
88 bool logging = false; // Indicates if AEG/AGC registers logging is enabled
89 
91 uint8_t contrast_val;
92 uint8_t hue_val;
94 uint8_t gain_val_left;
99 uint8_t sharpness_val;
100 uint8_t gamma_val;
101 bool autoAECAGC=false;
102 bool autoWB=false;
103 
106 // <---- Global variables
107 
108 // The main function
109 int main(int argc, char *argv[])
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;
169  aecagc_roi_left.width, aecagc_roi_left.height);
170  selectLeft=false;
171  selectRight=false;
172  }
174  {
175  applyAECAGCrectRight = false;
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
208  showImage( win_name, frameBGR, params.res );
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 }
238 
239 // Handle Keyboard
240 void handleKeyboard( sl_oc::video::VideoCapture &cap, int key )
241 {
242  if(key >= '0' && key <= '9')
243  {
244  int value = key - '0';
245  setControlValue( cap, value );
246  return;
247  }
248 
249  switch(key)
250  {
251 #ifdef SENSOR_LOG_AVAILABLE
252  case 'L':
253  {
254  logging = !logging;
256  std::cout << std::string("*** AEC/AGC registers logging: ") << (logging?std::string("ENABLED"):std::string("DISABLED")) << std::endl;
257  }
258  break;
259 
260  case 'f':
261  case 'F':
262  {
263  bool res = cap.resetAGCAECregisters();
264  std::cout << std::string("*** AEC/AGC registers reset: ") << (res?std::string("OK"):std::string("KO")) << std::endl;
265  }
266  break;
267 #endif
268 
269  case 'l':
270  {
271  bool led;
272  cap.toggleLED( &led );
273  std::cout << std::string(" * LED STATUS: ") << (led?std::string("ON"):std::string("OFF")) << std::endl;
274  }
275  break;
276 
277  case 'b':
278  setActiveControl( cap, Brightness );
279  break;
280 
281  case 'S':
282  setActiveControl( cap, Sharpness );
283  break;
284 
285  case 'c':
286  setActiveControl( cap, Contrast );
287  break;
288 
289  case 'h':
290  setActiveControl( cap, Hue );
291  break;
292 
293  case 's':
294  setActiveControl( cap, Saturation );
295  break;
296 
297  case 'w':
298  setActiveControl( cap, WhiteBalance );
299  break;
300 
301  case 'g':
302  setActiveControl( cap, Gamma );
303  break;
304 
305  case 'e':
306  setActiveControl( cap, Exposure );
307  break;
308 
309  case 'G':
310  setActiveControl( cap, Gain );
311  break;
312 
313  case 'a':
314  toggleAutomaticControl( cap );
315  break;
316 
317  case 'r':
318  case 'R':
319  resetControls(cap);
320  updateAllCtrlValues(cap);
321 
322  std::cout << "All control settings are reset to default values" << std::endl;
323  break;
324 
325  case '+':
326  case 171:
327  changeControlValue(cap,true);
328  break;
329 
330  case '-':
331  case 173:
332  changeControlValue(cap,false);
333  break;
334 
335  case '?':
336  std::cout << "COMMANDS HELP" << std::endl;
337  std::cout << " * 'q' or 'Q' -> Quit the example" << std::endl;
338  std::cout << " * '?' -> This help menu" << std::endl;
339  std::cout << " * 'l' -> Toggle camera led" << std::endl;
340  std::cout << " * 'b' -> Brightness control" << std::endl;
341  std::cout << " * 's' -> Saturation control" << std::endl;
342  std::cout << " * 'c' -> Contrast control" << std::endl;
343  std::cout << " * 'h' -> Hue control" << std::endl;
344  std::cout << " * 'S' -> Sharpness control" << std::endl;
345  std::cout << " * 'w' -> White Balance control" << std::endl;
346  std::cout << " * 'g' -> Gamma control" << std::endl;
347  std::cout << " * 'e' -> Exposure control" << std::endl;
348  std::cout << " * 'G' -> Gain control" << std::endl;
349  std::cout << " * 'a' -> Toggle automatic for White Balance or Exposure and Gain" << std::endl;
350  std::cout << " * 'r' or 'R' -> Reset to default configuration" << std::endl;
351  std::cout << " * '+' -> Increase the current control value" << std::endl;
352  std::cout << " * '-' -> Decrease the current control value" << std::endl;
353  std::cout << " * '0' .. '9' -> Set the current control value" << std::endl;
354 #ifdef SENSOR_LOG_AVAILABLE
355  std::cout << " * 'L' -> Toggle AGC/AEC registers logging" << std::endl;
356  std::cout << " * 'f' -> Fix AGC/AEC registers" << std::endl;
357 #endif
358  }
359 }
360 
361 void updateAllCtrlValues(sl_oc::video::VideoCapture &cap)
362 {
364  sharpness_val = cap.getSharpness();
365  contrast_val = cap.getContrast();
366  hue_val = cap.getHue();
368  gamma_val = cap.getGamma();
369  autoAECAGC = cap.getAECAGC();
370  autoWB = cap.getAutoWhiteBalance();
374 
375  uint16_t x,y,w,h;
377  aecagc_roi_left.x = x;
378  aecagc_roi_left.y = y;
379  aecagc_roi_left.width = w;
380  aecagc_roi_left.height = h;
382  aecagc_roi_right.x = x;
383  aecagc_roi_right.y = y;
384  aecagc_roi_right.width = w;
385  aecagc_roi_right.height = h;
386 }
387 
388 void handleMouse(int event, int x, int y, int, void*)
389 {
390  switch (event)
391  {
392  case cv::EVENT_LBUTTONDOWN: // AEC AGC ROI drawing started
393  {
395  {
396  origin_roi = cv::Point(x, y);
397  selectInProgress = true;
398  }
399  break;
400  }
401 
402  case cv::EVENT_LBUTTONUP: // AECAGC ROI drawing completed
403  {
404  selectInProgress = false;
405 
407  {
408  if(selectLeft)
409  {
410  selectLeft=false;
411  applyAECAGCrectLeft = true;
412  }
413  if(selectRight)
414  {
415  selectRight=false;
416  applyAECAGCrectRight = true;
417  }
418  }
419  break;
420  }
421 
422  case cv::EVENT_RBUTTONDOWN: // Reset AECAGC ROI with right button
423  {
424  //Reset selection
425  selectInProgress = false;
426  aecagc_roi_left = cv::Rect(0,0,img_w/2,img_h);
427  aecagc_roi_right = cv::Rect(0,0,img_w/2,img_h);
428  applyAECAGCrectLeft = true;
429  applyAECAGCrectRight = true;
430  break;
431  }
432  }
433 
434  if(selectInProgress) // AECAGC ROI drawing in progress
435  {
436  x /= img_resize_factor;
437  y /= img_resize_factor;
438 
439  int or_x = origin_roi.x/img_resize_factor;
440  int or_y = origin_roi.y/img_resize_factor;
441 
442  y = MAX(y,0);
443  y = MIN(y,img_h);
444  if(or_x<img_w/2) // AECAGC ROI for the left image
445  {
446  x = MAX(x,0);
447  x = MIN(x,img_w/2-1);
448  selectLeft = true;
449 
450  aecagc_roi_left.x = MIN(x, or_x);
451  aecagc_roi_left.y = MIN(y, or_y);
452  aecagc_roi_left.width = abs(x - or_x) + 1;
453  aecagc_roi_left.height = abs(y - or_y) + 1;
454  }
455  else // AECAGC ROI for the right image
456  {
457  or_x -= img_w/2;
458  x -= img_w/2;
459  x = MAX(x,0);
460  x = MIN(x,img_w/2-1);
461  selectRight = true;
462 
463  aecagc_roi_right.x = MIN(x, or_x);
464  aecagc_roi_right.y = MIN(y, or_y);
465  aecagc_roi_right.width = abs(x - or_x) + 1;
466  aecagc_roi_right.height = abs(y - or_y) + 1;
467  }
468  }
469 }
470 
471 // Change active control
472 void setActiveControl(sl_oc::video::VideoCapture &cap, CamControl control )
473 {
474  activeControl = control;
475 
476  std::string ctrlStr;
477 
478  switch( activeControl )
479  {
480  case Brightness:
481  ctrlStr = "Brightness";
482  break;
483  case Contrast:
484  ctrlStr = "Contrast";
485  break;
486  case Hue:
487  ctrlStr = "Hue";
488  break;
489  case Saturation:
490  ctrlStr = "Saturation";
491  break;
492  case Gain:
493  ctrlStr = "Gain";
494  break;
495  case WhiteBalance:
496  ctrlStr = "White Balance";
497  break;
498  case Sharpness:
499  ctrlStr = "Sharpness";
500  break;
501  case Gamma:
502  ctrlStr = "Gamma";
503  break;
504  case Exposure:
505  ctrlStr = "Exposure";
506  break;
507  }
508 
509  std::cout << "Active camera control: " << ctrlStr << std::endl;
510 }
511 
512 // Set new value for the active control
513 void setControlValue(sl_oc::video::VideoCapture &cap, int value )
514 {
515  int newValue;
516  switch( activeControl )
517  {
518  case Brightness:
519  cap.setBrightness( value );
520  newValue = cap.getBrightness();
521  brightness_val = newValue;
522 
523  std::cout << "New Brightness value: ";
524  break;
525 
526  case Contrast:
527  cap.setContrast( value );
528  newValue = cap.getContrast();
529  contrast_val = newValue;
530 
531  std::cout << "New Contrast value: ";
532  break;
533 
534  case Hue:
535  cap.setHue( value );
536  newValue = cap.getHue();
537  hue_val = newValue;
538 
539  std::cout << "New Hue value: ";
540  break;
541 
542  case Saturation:
543  cap.setSaturation( value );
544  newValue = cap.getSaturation();
545  saturation_val = newValue;
546 
547  std::cout << "New Saturation value: ";
548  break;
549 
550  case WhiteBalance:
551  cap.setWhiteBalance( 2800+value*411 );
552  newValue = cap.getWhiteBalance();
553  whiteBalance_val = newValue;
554 
555  std::cout << "New White Balance value: ";
556  break;
557 
558  case Sharpness:
559  cap.setSharpness( value );
560  newValue = cap.getSharpness();
561  sharpness_val = newValue;
562 
563  std::cout << "New Sharpness value: ";
564  break;
565 
566  case Gamma:
567  cap.setGamma( value);
568  newValue = cap.getGamma();
569  gamma_val = newValue;
570 
571  std::cout << "New Gamma value: ";
572  break;
573 
574  case Gain:
575  case Exposure:
576  default:
577  // Nothing to do here
578  return;
579  }
580 
581  std::cout << newValue << std::endl;
582 }
583 
584 // '+' or '-' pressed
585 void changeControlValue( sl_oc::video::VideoCapture &cap, bool increase )
586 {
587  int curValue=0;
588  switch( activeControl )
589  {
590  case Brightness:
591  curValue = cap.getBrightness();
592  brightness_val = curValue;
593  break;
594 
595  case Contrast:
596  curValue = cap.getContrast();
597  contrast_val = curValue;
598  break;
599 
600  case Hue:
601  curValue = cap.getHue();
602  hue_val = curValue;
603  break;
604 
605  case Saturation:
606  curValue = cap.getSaturation();
607  saturation_val = curValue;
608  break;
609 
610  case Gain:
611  {
612  int curValueLeft = cap.getGain(sl_oc::video::CAM_SENS_POS::LEFT);
613  int curValueRight = cap.getGain(sl_oc::video::CAM_SENS_POS::RIGHT);
614 
615  if(increase)
616  {
617  cap.setGain(sl_oc::video::CAM_SENS_POS::LEFT,++curValueLeft);
618  cap.setGain(sl_oc::video::CAM_SENS_POS::RIGHT,++curValueRight);
619  }
620  else
621  {
622  cap.setGain(sl_oc::video::CAM_SENS_POS::LEFT,--curValueLeft);
623  cap.setGain(sl_oc::video::CAM_SENS_POS::RIGHT,--curValueRight);;
624  }
625 
628 
629  std::cout << "New Left Gain value: " << (int)gain_val_left << std::endl;
630  std::cout << "New Right Gain value: " << (int)gain_val_right << std::endl;
631 
632  autoAECAGC = cap.getAECAGC();
633  }
634  break;
635 
636  case Exposure:
637  {
638  int curValueLeft = cap.getExposure(sl_oc::video::CAM_SENS_POS::LEFT);
639  int curValueRight = cap.getExposure(sl_oc::video::CAM_SENS_POS::RIGHT);
640 
641  if(increase)
642  {
643  cap.setExposure(sl_oc::video::CAM_SENS_POS::LEFT,++curValueLeft);
644  cap.setExposure(sl_oc::video::CAM_SENS_POS::RIGHT,++curValueRight);
645  }
646  else
647  {
648  cap.setExposure(sl_oc::video::CAM_SENS_POS::LEFT,--curValueLeft);
649  cap.setExposure(sl_oc::video::CAM_SENS_POS::RIGHT,--curValueRight);;
650  }
651 
654 
655  std::cout << "New Left Exposure value: " << (int)exposure_val_left << std::endl;
656  std::cout << "New Right Exposure value: " << (int)exposure_val_right << std::endl;
657 
658  autoAECAGC = cap.getAECAGC();
659  }
660  break;
661 
662  case WhiteBalance:
663  cap.setAutoWhiteBalance(false);
664  curValue = cap.getWhiteBalance();
665  whiteBalance_val = curValue;
666  autoWB = cap.getAutoWhiteBalance();
667  break;
668 
669  case Sharpness:
670  curValue = cap.getSharpness();
671  sharpness_val = curValue;
672  break;
673 
674  case Gamma:
675  curValue = cap.getGamma();
676  gamma_val = curValue;
677  break;
678  }
679 
681  {
682  if(increase)
683  curValue += 100;
684  else
685  curValue -= 100;
686 
687  cap.setWhiteBalance( curValue );
688 
690  std::cout << "New White Balance value: " << whiteBalance_val << std::endl;
691  }
692  else if(activeControl != Gain && activeControl != Exposure)
693  {
694  if(increase)
695  setControlValue( cap, ++curValue);
696  else
697  setControlValue( cap, --curValue);
698  }
699 }
700 
701 // 'a' or 'A' pressed to enable automatic WhiteBalanse or Gain/Exposure
702 void toggleAutomaticControl( sl_oc::video::VideoCapture &cap )
703 {
705  {
706  bool curValue = cap.getAutoWhiteBalance();
707  cap.setAutoWhiteBalance( !curValue );
708  autoWB = cap.getAutoWhiteBalance();
709 
710  std::cout << "Automatic White Balance control: " << ((!curValue)?"ENABLED":"DISABLED") << std::endl;
711  }
712 
714  {
715  bool curValue = cap.getAECAGC();
716  cap.setAECAGC( !curValue );
717  autoAECAGC = cap.getAECAGC();
718 
719  std::cout << "Automatic Exposure and Gain control: " << ((!curValue)?"ENABLED":"DISABLED") << std::endl;
720  }
721 }
722 
723 // Rescale the images according to the selected resolution to better display them on screen
724 void showImage( std::string name, cv::Mat& img, sl_oc::video::RESOLUTION res )
725 {
726  cv::Mat resized;
727  switch(res)
728  {
729  default:
731  img_resize_factor = 1.0;
732  resized = img;
733  break;
735  name += " [Resize factor 0.6]";
736  img_resize_factor = 0.6;
737  cv::resize( img, resized, cv::Size(), img_resize_factor, img_resize_factor );
738  break;
741  name += " [Resize factor 0.4]";
742  img_resize_factor = 0.4;
743  cv::resize( img, resized, cv::Size(), img_resize_factor, img_resize_factor );
744  break;
745  }
746 
748  {
749  // Check that left selection rectangle is valid and draw it on the image
750  if ( (aecagc_roi_left.area()>0) &&
751  (aecagc_roi_left.width-aecagc_roi_left.x)<=img_w/2 &&
753  {
754  cv::Rect rescaled_roi;
755  rescaled_roi.x = aecagc_roi_left.x*img_resize_factor;
756  rescaled_roi.y = aecagc_roi_left.y*img_resize_factor;
757  rescaled_roi.width = aecagc_roi_left.width*img_resize_factor;
758  rescaled_roi.height = aecagc_roi_left.height*img_resize_factor;
759  cv::rectangle(resized, rescaled_roi, cv::Scalar(220, 180, 20), 2);
760  }
761 
762  // Check that right selection rectangle is valid and draw it on the image
763  if ( (aecagc_roi_right.area()>0) &&
764  (aecagc_roi_right.width-aecagc_roi_right.x)<=img_w/2 &&
766  {
767  cv::Rect rescaled_roi;
768  rescaled_roi.x = (img_w/2+aecagc_roi_right.x)*img_resize_factor;
769  rescaled_roi.y = aecagc_roi_right.y*img_resize_factor;
770  rescaled_roi.width = aecagc_roi_right.width*img_resize_factor;
771  rescaled_roi.height = aecagc_roi_right.height*img_resize_factor;
772  cv::rectangle(resized, rescaled_roi, cv::Scalar(20, 180, 220), 2);
773  }
774  }
775 
776  std::string info;
777  switch (activeControl)
778  {
779  case Brightness:
780  info = "Brightness: ";
781  info += std::to_string(brightness_val);
782  break;
783  case Contrast:
784  info = "Contrast: ";
785  info += std::to_string(contrast_val);
786  break;
787  case Hue:
788  info = "Hue: ";
789  info += std::to_string(hue_val);
790  break;
791  case Saturation:
792  info = "Saturation: ";
793  info += std::to_string(saturation_val);
794  break;
795  case Gain:
796  info = "Gain: ";
797  if(autoAECAGC)
798  {
799  info += "AUTO";
800  }
801  else
802  {
803  info += std::to_string(gain_val_left);
804  info += " - ";
805  info += std::to_string(gain_val_right);
806  }
807  break;
808  case Exposure:
809  info = "Exposure: ";
810  if(autoAECAGC)
811  {
812  info += "AUTO";
813  }
814  else
815  {
816  info += std::to_string(exposure_val_left);
817  info += " - ";
818  info += std::to_string(exposure_val_right);
819  }
820  break;
821  case WhiteBalance:
822  info = "WhiteBalance: ";
823  if(autoWB)
824  {
825  info += "AUTO";
826  }
827  else
828  {
829  info += std::to_string(whiteBalance_val);
830  }
831  break;
832  case Sharpness:
833  info = "Sharpness: ";
834  info += std::to_string(sharpness_val);
835  break;
836  case Gamma:
837  info = "Gamma: ";
838  info += std::to_string(gamma_val);
839  break;
840  }
841 
842  cv::putText( resized, info, cv::Point(20,40),cv::FONT_HERSHEY_SIMPLEX, 0.75,
843  cv::Scalar(241,240,236), 2);
844 
845  cv::imshow( win_name, resized );
846 }
847 
848 void resetControls( sl_oc::video::VideoCapture &cap )
849 {
850  cap.resetBrightness();
851  cap.resetSharpness();
852  cap.resetContrast();
853  cap.resetHue();
854  cap.resetSaturation();
855  cap.resetGamma();
856  cap.resetAECAGC();
857  cap.resetAutoWhiteBalance();
860 }
The VideoCapture class provides image grabbing functions and settings control for all the Stereolabs ...
void setHue(int hue)
Set the Hue value.
int getBrightness()
Get the Brightness value.
bool setROIforAECAGC(CAM_SENS_POS side, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Set Region Of Interest (ROI) for AECAGC control.
void resetBrightness()
Reset the Brightness value to default value.
const Frame & getLastFrame(uint64_t timeout_msec=100)
Get the last received camera image.
int getSharpness()
Get the Sharpness value.
void resetGamma()
Reset the Gamma value to default value.
void resetHue()
Reset the Hue value to default value.
void setSaturation(int saturation)
Set the Saturation value.
int getGain(CAM_SENS_POS cam)
Get the current Gain value.
void resetAutoWhiteBalance()
Reset the automatic White Balance control value to default value.
int getSaturation()
Get the Saturation value.
int getHue()
Get the Hue value.
void resetSharpness()
Reset the Sharpness value to default value.
bool getAutoWhiteBalance()
Get the status of the automatic White Balance control.
int getGamma()
Get the Gamma value.
int getWhiteBalance()
Get the White Balance value.
void setSharpness(int sharpness)
Set the Sharpness value.
void setWhiteBalance(int wb)
Set the White Balance value (disable auto White Balance if active)
void setExposure(CAM_SENS_POS cam, int exposure)
Set the Exposure value (disable Exposure and Gain control if active)
bool initializeVideo(int devId=-1)
Open a ZED camera using the specified ID or searching for the first available.
void setContrast(int contrast)
Set the Contrast value.
int setAECAGC(bool active)
Enable/Disable the automatic Exposure and Gain control.
int getContrast()
Get the Contrast value.
bool enableAecAgcSensLogging(bool enable, int frame_skip=10)
Start logging to file of AEG/AGC camera registers.
void resetSaturation()
Reset the Saturation value to default value.
void resetAECAGC()
Reset the automatic Exposure and Gain control value to default value.
int getExposure(CAM_SENS_POS cam)
Get the current Exposure value.
bool getROIforAECAGC(CAM_SENS_POS side, uint16_t &x, uint16_t &y, uint16_t &w, uint16_t &h)
Get the coordinates of the current ROI for AECAGC control.
void setGamma(int gamma)
Set the Gamma value.
void setBrightness(int brightness)
Set the Brightness value.
bool getAECAGC()
Get the status of the automatic Exposure and Gain control.
void setAutoWhiteBalance(bool active)
Enable/Disable the automatic White Balance control.
void setGain(CAM_SENS_POS cam, int gain)
Set the Gain value (disable Exposure and Gain control if active)
bool resetROIforAECAGC(CAM_SENS_POS side)
Reset the ROI for AECAGC control.
int getSerialNumber()
Retrieve the serial number of the connected camera.
void resetContrast()
Reset the Contrast value to default value.
int toggleLED(bool *value)
Toggle the status of the camera led.
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
RESOLUTION
Available resolutions.
@ 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
int main(int argc, char *argv[])
uint8_t hue_val
uint8_t gain_val_left
uint8_t gain_val_right
bool autoAECAGC
double img_resize_factor
cv::String win_name
cv::Rect aecagc_roi_left
cv::Rect aecagc_roi_right
CamControl activeControl
int whiteBalance_val
uint8_t exposure_val_left
uint8_t gamma_val
uint8_t contrast_val
cv::Point origin_roi
bool selectLeft
uint8_t brightness_val
uint8_t exposure_val_right
uint8_t saturation_val
enum _cam_control CamControl
bool selectRight
bool selectInProgress
uint8_t sharpness_val
bool logging
bool applyAECAGCrectRight
cv::Mat frameBGR
sl_oc::video::VideoParams params
cv::Mat frameYUV