27 #include <opencv2/opencv.hpp>
55 static void handleMouse(
int event,
int x,
int y,
int,
void*);
109 int main(
int argc,
char *argv[])
129 std::cerr <<
"Cannot open camera video capture" << std::endl;
130 std::cerr <<
"See verbosity level for more details." << std::endl;
134 std::cout <<
"Connected to camera sn: " << cap.
getSerialNumber() << std::endl;
139 cv::setMouseCallback(
win_name, handleMouse);
149 updateAllCtrlValues(cap);
152 uint16_t not_a_new_frame = 0;
153 int frame_timeout_msec = 100;
190 std::cout << std::setprecision(9) <<
"[" << frame.
frame_id <<
"] Ts: " <<
static_cast<double>(frame.
timestamp)/1e9 <<
" sec" << std::endl;
193 double dt = (frame.
timestamp - last_ts)/1e9;
194 std::cout << std::setprecision(9) <<
" * dT: " << dt <<
" sec - FPS: " << 1./dt << std::endl;
213 std::cout <<
"Not a new frame #" << not_a_new_frame << std::endl;
215 if( not_a_new_frame>=(3000/frame_timeout_msec))
217 std::cout <<
"Camera connection lost. Closing..." << std::endl;
224 int key = cv::waitKey( 5 );
228 if(key==
'q' || key==
'Q')
231 handleKeyboard( cap, key );
242 if(key >=
'0' && key <=
'9')
244 int value = key -
'0';
245 setControlValue( cap, value );
251 #ifdef SENSOR_LOG_AVAILABLE
256 std::cout << std::string(
"*** AEC/AGC registers logging: ") << (
logging?std::string(
"ENABLED"):std::string(
"DISABLED")) << std::endl;
264 std::cout << std::string(
"*** AEC/AGC registers reset: ") << (res?std::string(
"OK"):std::string(
"KO")) << std::endl;
273 std::cout << std::string(
" * LED STATUS: ") << (led?std::string(
"ON"):std::string(
"OFF")) << std::endl;
290 setActiveControl( cap,
Hue );
302 setActiveControl( cap,
Gamma );
310 setActiveControl( cap,
Gain );
314 toggleAutomaticControl( cap );
320 updateAllCtrlValues(cap);
322 std::cout <<
"All control settings are reset to default values" << std::endl;
327 changeControlValue(cap,
true);
332 changeControlValue(cap,
false);
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;
388 void handleMouse(
int event,
int x,
int y,
int,
void*)
392 case cv::EVENT_LBUTTONDOWN:
402 case cv::EVENT_LBUTTONUP:
422 case cv::EVENT_RBUTTONDOWN:
447 x = MIN(x,
img_w/2-1);
460 x = MIN(x,
img_w/2-1);
481 ctrlStr =
"Brightness";
484 ctrlStr =
"Contrast";
490 ctrlStr =
"Saturation";
496 ctrlStr =
"White Balance";
499 ctrlStr =
"Sharpness";
505 ctrlStr =
"Exposure";
509 std::cout <<
"Active camera control: " << ctrlStr << std::endl;
523 std::cout <<
"New Brightness value: ";
531 std::cout <<
"New Contrast value: ";
539 std::cout <<
"New Hue value: ";
547 std::cout <<
"New Saturation value: ";
555 std::cout <<
"New White Balance value: ";
563 std::cout <<
"New Sharpness value: ";
571 std::cout <<
"New Gamma value: ";
581 std::cout << newValue << std::endl;
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;
695 setControlValue( cap, ++curValue);
697 setControlValue( cap, --curValue);
710 std::cout <<
"Automatic White Balance control: " << ((!curValue)?
"ENABLED":
"DISABLED") << std::endl;
719 std::cout <<
"Automatic Exposure and Gain control: " << ((!curValue)?
"ENABLED":
"DISABLED") << std::endl;
735 name +=
" [Resize factor 0.6]";
741 name +=
" [Resize factor 0.4]";
754 cv::Rect rescaled_roi;
759 cv::rectangle(resized, rescaled_roi, cv::Scalar(220, 180, 20), 2);
767 cv::Rect rescaled_roi;
772 cv::rectangle(resized, rescaled_roi, cv::Scalar(20, 180, 220), 2);
780 info =
"Brightness: ";
789 info += std::to_string(
hue_val);
792 info =
"Saturation: ";
822 info =
"WhiteBalance: ";
833 info =
"Sharpness: ";
842 cv::putText( resized, info, cv::Point(20,40),cv::FONT_HERSHEY_SIMPLEX, 0.75,
843 cv::Scalar(241,240,236), 2);
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.
bool resetAGCAECregisters()
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.
RESOLUTION
Available resolutions.
@ FPS_15
15 Frames per second. Available for all the resolutions.
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.
int main(int argc, char *argv[])
cv::Rect aecagc_roi_right
uint8_t exposure_val_left
uint8_t exposure_val_right
enum _cam_control CamControl
bool applyAECAGCrectRight
sl_oc::video::VideoParams params