ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
Functions
zed_oc_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[] 
)
Examples
zed_oc_video_example.cpp.

Definition at line 34 of file zed_oc_video_example.cpp.

35 {
36  // ----> Silence unused warning
37  (void)argc;
38  (void)argv;
39  // <---- Silence unused warning
40 
44 
45  // ----> Create Video Capture
47  if( !cap_0.initializeVideo() )
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
57 
58 
59 
60 #ifdef TEST_FPS
61  // Timestamp to check FPS
62  double lastTime = static_cast<double>(getSteadyTimestamp())/1e9;
63  // Frame timestamp to check FPS
64  uint64_t lastFrameTs = 0;
65 #endif
66 
67  // Infinite video grabbing loop
68  while (1)
69  {
70  // Get last available frame
71  const sl_oc::video::Frame frame = cap_0.getLastFrame();
72 
73  // ----> If the frame is valid we can display it
74  if(frame.data!=nullptr)
75  {
76 #ifdef TEST_FPS
77  if(lastFrameTs!=0)
78  {
79  // ----> System time
80  double now = static_cast<double>(getSteadyTimestamp())/1e9;
81  double elapsed_sec = now - lastTime;
82  lastTime = now;
83  std::cout << "[System] Frame period: " << elapsed_sec << "sec - Freq: " << 1./elapsed_sec << " Hz" << std::endl;
84  // <---- System time
85 
86  // ----> Frame time
87  double frame_dT = static_cast<double>(frame.timestamp-lastFrameTs)/1e9;
88  std::cout << "[Camera] Frame period: " << frame_dT << "sec - Freq: " << 1./frame_dT << " Hz" << std::endl;
89  // <---- Frame time
90  }
91  lastFrameTs = frame.timestamp;
92 #endif
93 
94  // ----> Conversion from YUV 4:2:2 to BGR for visualization
95  cv::Mat frameYUV = cv::Mat( frame.height, frame.width, CV_8UC2, frame.data );
96  cv::Mat frameBGR;
97  cv::cvtColor(frameYUV,frameBGR,cv::COLOR_YUV2BGR_YUYV);
98  // <---- Conversion from YUV 4:2:2 to BGR for visualization
99 
100  // Show frame
101  sl_oc::tools::showImage( "Stream RGB", frameBGR, params.res );
102  }
103  // <---- If the frame is valid we can display it
104 
105  // ----> Keyboard handling
106  int key = cv::waitKey( 5 );
107  if(key=='q' || key=='Q') // Quit
108  break;
109  // <---- Keyboard handling
110  }
111 
112  return EXIT_SUCCESS;
113 }
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.
cv::Mat frameBGR
sl_oc::video::VideoParams params
cv::Mat frameYUV

References sl_oc::video::Frame::data, sl_oc::video::VideoParams::fps, sl_oc::video::FPS_60, frameBGR, frameYUV, 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::tools::showImage(), sl_oc::video::Frame::timestamp, and sl_oc::video::Frame::width.