Example of how to use the VideoCapture class and OpenCV GUI controls to tune the depth extraction process.
#include <iostream>
#include <sstream>
#include <string>
#include <mutex>
#include <opencv2/opencv.hpp>
#define USE_HALF_SIZE_DISPARITY
int main(
int argc,
char *argv[])
{
(void)argc;
(void)argv;
#ifdef EMBEDDED_ARM
#else
#endif
if( !cap.initializeVideo(-1) )
{
std::cerr << "Cannot open camera video capture" << std::endl;
std::cerr << "See verbosity level for more details." << std::endl;
return EXIT_FAILURE;
}
int sn = cap.getSerialNumber();
std::cout << "Connected to camera sn: " << sn << std::endl;
std::string calibration_file;
unsigned int serial_number = sn;
{
std::cerr << "Could not load calibration file from Stereolabs servers" << std::endl;
return EXIT_FAILURE;
}
std::cout << "Calibration file found. Loading..." << std::endl;
int w,h;
cap.getFrameSize(w,h);
cv::Mat map_left_x, map_left_y;
cv::Mat map_right_x, map_right_y;
cv::Mat cameraMatrix_left, cameraMatrix_right;
cameraMatrix_left, cameraMatrix_right);
std::cout << " Camera Matrix L: \n" << cameraMatrix_left << std::endl << std::endl;
std::cout << " Camera Matrix R: \n" << cameraMatrix_right << std::endl << std::endl;
while (1)
{
{
break;
}
cv::waitKey(10);
}
#ifdef USE_HALF_SIZE_DISPARITY
#endif
while(1)
{
int key = cv::waitKey( 5 );
if(key=='q' || key==27)
{
std::cout << "Save current stereo parameters? [Y/N]" << std::endl;
key = cv::waitKey(-1);
if(key=='Y' || key=='y')
{
}
break;
}
if(key=='l' || key=='L')
{
{
}
}
if(key=='s' || key=='S')
{
}
if(key=='r' || key=='R')
{
}
}
return EXIT_SUCCESS;
}
{
return;
#ifdef USE_HALF_SIZE_DISPARITY
#else
#endif
#ifdef USE_HALF_SIZE_DISPARITY
#endif
std::cout << "Start stereo matching..." << std::endl;
std::cout << "... finished stereo matching" << std::endl;
double elapsed = stereo_clock.
toc();
std::cout << "Stereo processing: " << elapsed << " sec - Freq: " << 1./elapsed << std::endl;
#ifdef USE_HALF_SIZE_DISPARITY
#endif
}
{
bool fixed = false;
return;
if(newBlockSize%2!=1)
{
++newBlockSize;
else
--newBlockSize;
fixed=true;
}
if(newBlockSize<1)
{
newBlockSize=1;
fixed=true;
}
if(newBlockSize>255)
{
newBlockSize=255;
fixed=true;
}
if(fixed)
{
}
}
{
return;
{
}
}
{
bool fixed = false;
return;
if(newNumDisparities%16!=0)
{
newNumDisparities = newNumDisparities/16;
else
newNumDisparities = newNumDisparities/16 + 1;
newNumDisparities*=16;
fixed=true;
}
if(fixed)
{
}
{
}
}
{
return;
std::cout <<
"New 'mode' value: " <<
stereoPar.
mode << std::endl;
}
{
return;
}
{
return;
}
{
return;
}
{
return;
}
{
return;
}
The VideoCapture class provides image grabbing functions and settings control for all the Stereolabs ...
@ FPS_30
30 Frames per second. Not available for RESOLUTION::HD2K.
The Frame struct containing the acquired video frames.
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.
int main(int argc, char *argv[])
sl_oc::tools::StereoSgbmPar stereoPar
std::string preFiltDispWinName
void on_trackbar_mode(int newMode, void *)
void on_trackbar_speckleRange(int newSpeckleRange, void *)
void on_trackbar_num_disparities(int newNumDisparities, void *)
sl_oc::video::VideoParams params
void applyStereoMatching()
cv::Mat right_for_matcher
void on_trackbar_min_disparities(int newMinDisparities, void *)
void on_trackbar_preFilterCap(int newPreFilterCap, void *)
void on_trackbar_disp12MaxDiff(int newDisp12MaxDiff, void *)
void on_trackbar_block_size(int newBlockSize, void *)
void on_trackbar_uniquenessRatio(int newUniquenessRatio, void *)
void on_trackbar_speckleWindowSize(int newSpeckleWindowSize, void *)
cv::Ptr< cv::StereoSGBM > left_matcher