ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
Functions
zed_oc_rectify_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_rectify_example.cpp.

Definition at line 37 of file zed_oc_rectify_example.cpp.

38 {
39  // ----> Silence unused warning
40  (void)argc;
41  (void)argv;
42  // <---- Silence unused warning
43 
45 
46  // ----> Set Video parameters
50  params.verbose = verbose;
51  // <---- Set Video parameters
52 
53  // ----> Create Video Capture
55  if( !cap.initializeVideo(-1) )
56  {
57  std::cerr << "Cannot open camera video capture" << std::endl;
58  std::cerr << "See verbosity level for more details." << std::endl;
59 
60  return EXIT_FAILURE;
61  }
62  int sn = cap.getSerialNumber();
63  std::cout << "Connected to camera sn: " << sn << std::endl;
64  // <---- Create Video Capture
65 
66  // ----> Retrieve calibration file from Stereolabs server
67  std::string calibration_file;
68  // ZED Calibration
69  unsigned int serial_number = sn;
70  // Download camera calibration file
71  if( !sl_oc::tools::downloadCalibrationFile(serial_number, calibration_file) )
72  {
73  std::cerr << "Could not load calibration file from Stereolabs servers" << std::endl;
74  return EXIT_FAILURE;
75  }
76  std::cout << "Calibration file found. Loading..." << std::endl;
77 
78  // ----> Frame size
79  int w,h;
80  cap.getFrameSize(w,h);
81  // <---- Frame size
82 
83  // ----> Initialize calibration
84  cv::Mat map_left_x, map_left_y;
85  cv::Mat map_right_x, map_right_y;
86  cv::Mat cameraMatrix_left, cameraMatrix_right;
87  sl_oc::tools::initCalibration(calibration_file, cv::Size(w/2,h), map_left_x, map_left_y, map_right_x, map_right_y,
88  cameraMatrix_left, cameraMatrix_right);
89 
90  std::cout << " Camera Matrix L: \n" << cameraMatrix_left << std::endl << std::endl;
91  std::cout << " Camera Matrix R: \n" << cameraMatrix_right << std::endl << std::endl;
92  // ----> Initialize calibration
93 
95 
96  uint64_t last_ts=0;
97 
98  // Infinite video grabbing loop
99  while (1)
100  {
101  // Get a new frame from camera
102  const sl_oc::video::Frame frame = cap.getLastFrame();
103 
104  // ----> If the frame is valid we can convert, rectify and display it
105  if(frame.data!=nullptr && frame.timestamp!=last_ts)
106  {
107  last_ts = frame.timestamp;
108 
109  // ----> Conversion from YUV 4:2:2 to BGR for visualization
110  cv::Mat frameYUV = cv::Mat( frame.height, frame.width, CV_8UC2, frame.data );
111  cv::cvtColor(frameYUV,frameBGR,cv::COLOR_YUV2BGR_YUYV);
112  // <---- Conversion from YUV 4:2:2 to BGR for visualization
113 
114  // ----> Extract left and right images from side-by-side
115  left_raw = frameBGR(cv::Rect(0, 0, frameBGR.cols / 2, frameBGR.rows));
116  right_raw = frameBGR(cv::Rect(frameBGR.cols / 2, 0, frameBGR.cols / 2, frameBGR.rows));
117  // Display images
120  // <---- Extract left and right images from side-by-side
121 
122  // ----> Apply rectification
123  cv::remap(left_raw, left_rect, map_left_x, map_left_y, cv::INTER_LINEAR );
124  cv::remap(right_raw, right_rect, map_right_x, map_right_y, cv::INTER_LINEAR );
125 
128  // <---- Apply rectification
129  }
130 
131  // ----> Keyboard handling
132  int key = cv::waitKey( 5 );
133  if(key=='q' || key=='Q') // Quit
134  break;
135  // <---- Keyboard handling
136  }
137 
138  return EXIT_SUCCESS;
139 }
The VideoCapture class provides image grabbing functions and settings control for all the Stereolabs ...
bool initCalibration(std::string calibration_file, cv::Size2i image_size, cv::Mat &map_left_x, cv::Mat &map_left_y, cv::Mat &map_right_x, cv::Mat &map_right_y, cv::Mat &cameraMatrix_left, cv::Mat &cameraMatrix_right, double *baseline=nullptr)
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
bool downloadCalibrationFile(unsigned int serial_number, std::string &calibration_file)
@ FPS_15
15 Frames per second. Available for all the resolutions.
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.
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 left_raw
cv::Mat frameBGR
sl_oc::video::VideoParams params
cv::Mat right_raw
cv::Mat frameYUV
cv::Mat left_rect
cv::Mat right_rect

References sl_oc::video::Frame::data, sl_oc::tools::downloadCalibrationFile(), sl_oc::video::VideoParams::fps, sl_oc::video::FPS_15, frameBGR, frameYUV, sl_oc::video::VideoCapture::getFrameSize(), sl_oc::video::VideoCapture::getLastFrame(), sl_oc::video::VideoCapture::getSerialNumber(), sl_oc::video::HD2K, sl_oc::video::Frame::height, sl_oc::INFO, sl_oc::tools::initCalibration(), sl_oc::video::VideoCapture::initializeVideo(), left_raw, left_rect, params, sl_oc::video::VideoParams::res, right_raw, right_rect, sl_oc::tools::showImage(), sl_oc::video::Frame::timestamp, sl_oc::video::VideoParams::verbose, and sl_oc::video::Frame::width.