ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
Functions
zed_oc_multi_video_example.cpp File Reference

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 34 of file zed_oc_multi_video_example.cpp.

35 {
36  // ----> Silence unused warning
37  (void)argc;
38  (void)argv;
39  // <---- Silence unused warning
40 
44 
45  // ----> Create Video Capture 0
47  if( !cap_0.initializeVideo(0) )
48  {
49  std::cerr << "Cannot open camera video capture" << std::endl;
50  std::cerr << "See verbosity level for more details." << std::endl;
51 
52  return EXIT_FAILURE;
53  }
54 
55  std::cout << "Connected to camera sn: " << cap_0.getSerialNumber() << " [" << cap_0.getDeviceName() << "]" << std::endl;
56  // <---- Create Video Capture 0
57 
58  // ----> Create Video Capture 1
60  if( !cap_1.initializeVideo(2) )
61  {
62  std::cerr << "Cannot open camera video capture" << std::endl;
63  std::cerr << "See verbosity level for more details." << std::endl;
64 
65  return EXIT_FAILURE;
66  }
67 
68  std::cout << "Connected to camera sn: " << cap_1.getSerialNumber() << " [" << cap_1.getDeviceName() << "]" << std::endl;
69  // <---- Create Video Capture 1
70 
71  // Set video parameters
72  bool autoSettingEnable = true;
73  cap_0.setAutoWhiteBalance(autoSettingEnable);
74  cap_0.setAECAGC(autoSettingEnable);
75 
76  cap_1.setAutoWhiteBalance(autoSettingEnable);
77  cap_1.setAECAGC(autoSettingEnable);
78 
79 #ifdef TEST_FPS
80  // Timestamp to check FPS
81  double lastTime = static_cast<double>(getSteadyTimestamp())/1e9;
82  // Frame timestamp to check FPS
83  uint64_t lastFrameTs = 0;
84 #endif
85 
86  // Infinite video grabbing loop
87  while (1)
88  {
89  // Get last available frame
90  const sl_oc::video::Frame frame_0 = cap_0.getLastFrame();
91  const sl_oc::video::Frame frame_1 = cap_1.getLastFrame();
92 
93  // ----> If the frame is valid we can display it
94  if(frame_0.data!=nullptr && frame_1.data!=nullptr)
95  {
96 #ifdef TEST_FPS
97  if(lastFrameTs!=0)
98  {
99  // ----> System time
100  double now = static_cast<double>(getSteadyTimestamp())/1e9;
101  double elapsed_sec = now - lastTime;
102  lastTime = now;
103  std::cout << "[System] Frame period: " << elapsed_sec << "sec - Freq: " << 1./elapsed_sec << " Hz" << std::endl;
104  // <---- System time
105 
106  // ----> Frame time
107  double frame_dT = static_cast<double>(frame.timestamp-lastFrameTs)/1e9;
108  std::cout << "[Camera] Frame period: " << frame_dT << "sec - Freq: " << 1./frame_dT << " Hz" << std::endl;
109  // <---- Frame time
110  }
111  lastFrameTs = frame.timestamp;
112 #endif
113 
114  // ----> Conversion from YUV 4:2:2 to BGR for visualization
115  cv::Mat frameYUV_0 = cv::Mat( frame_0.height, frame_0.width, CV_8UC2, frame_0.data );
116  cv::Mat frameBGR_0;
117  cv::Mat frameYUV_1 = cv::Mat( frame_1.height, frame_1.width, CV_8UC2, frame_1.data );
118  cv::Mat frameBGR_1;
119  cv::cvtColor(frameYUV_0,frameBGR_0,cv::COLOR_YUV2BGR_YUYV);
120  cv::cvtColor(frameYUV_1,frameBGR_1,cv::COLOR_YUV2BGR_YUYV);
121  // <---- Conversion from YUV 4:2:2 to BGR for visualization
122 
123  // Show frame
124  sl_oc::tools::showImage( "Stream RGB #0", frameBGR_0, params.res );
125  sl_oc::tools::showImage( "Stream RGB #1", frameBGR_1, params.res );
126  }
127  // <---- If the frame is valid we can display it
128 
129  // ----> Keyboard handling
130  int key = cv::waitKey( 5 );
131  if(key=='q' || key=='Q') // Quit
132  break;
133  if(key=='a' || key=='A')
134  {
135  autoSettingEnable = !autoSettingEnable;
136  cap_0.setAutoWhiteBalance(autoSettingEnable);
137  cap_0.setAECAGC(autoSettingEnable);
138 
139  cap_1.setAutoWhiteBalance(autoSettingEnable);
140  cap_1.setAECAGC(autoSettingEnable);
141 
142  std::cout << "Auto GAIN/EXPOSURE and Auto White Balance: " << (autoSettingEnable?"ENABLED":"DISABLED") << std::endl;
143  }
144  // <---- Keyboard handling
145  }
146 
147  return EXIT_SUCCESS;
148 }
The VideoCapture class provides image grabbing functions and settings control for all the Stereolabs ...
uint64_t getSteadyTimestamp()
Get the current system clock as steady clock, so with no jumps even if the system time changes.
Definition: defines.hpp:63
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_60
60 Frames per second. Not available for RESOLUTION::HD2K and RESOLUTION::HD1080.
The Frame struct containing the acquired video frames.
uint64_t timestamp
Timestamp in nanoseconds.
uint16_t height
Frame height.
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.
sl_oc::video::VideoParams params

References sl_oc::video::Frame::data, sl_oc::video::VideoParams::fps, sl_oc::video::FPS_60, sl_oc::video::VideoCapture::getDeviceName(), sl_oc::video::VideoCapture::getLastFrame(), sl_oc::video::VideoCapture::getSerialNumber(), getSteadyTimestamp(), sl_oc::video::HD720, sl_oc::video::Frame::height, sl_oc::video::VideoCapture::initializeVideo(), params, sl_oc::video::VideoParams::res, sl_oc::video::VideoCapture::setAECAGC(), sl_oc::video::VideoCapture::setAutoWhiteBalance(), sl_oc::tools::showImage(), sl_oc::video::Frame::timestamp, and sl_oc::video::Frame::width.