This source file includes following definitions.
- main
- readme
#include <stdio.h>
#include <iostream>
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
const char *windowDisparity = "Disparity";
void readme();
int main( int argc, char** argv )
{
if( argc != 3 )
{ readme(); return -1; }
Mat imgLeft = imread( argv[1], IMREAD_GRAYSCALE );
Mat imgRight = imread( argv[2], IMREAD_GRAYSCALE );
Mat imgDisparity16S = Mat( imgLeft.rows, imgLeft.cols, CV_16S );
Mat imgDisparity8U = Mat( imgLeft.rows, imgLeft.cols, CV_8UC1 );
if( imgLeft.empty() || imgRight.empty() )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
int ndisparities = 16*5;
int SADWindowSize = 21;
Ptr<StereoBM> sbm = StereoBM::create( ndisparities, SADWindowSize );
sbm->compute( imgLeft, imgRight, imgDisparity16S );
double minVal; double maxVal;
minMaxLoc( imgDisparity16S, &minVal, &maxVal );
printf("Min disp: %f Max value: %f \n", minVal, maxVal);
imgDisparity16S.convertTo( imgDisparity8U, CV_8UC1, 255/(maxVal - minVal));
namedWindow( windowDisparity, WINDOW_NORMAL );
imshow( windowDisparity, imgDisparity8U );
imwrite("SBM_sample.png", imgDisparity16S);
waitKey(0);
return 0;
}
void readme()
{ std::cout << " Usage: ./SBMSample <imgLeft> <imgRight>" << std::endl; }