disparity map result image size(height& width)
Dears,
I have implemented the following code using SGBM to find the disparity but the result of disparity map looks larger (hight and width) than left and right (original), so is there any idea how to keep the size ?
thanks
Mat imgLeft = imread("left.png"); //,CV_LOAD_IMAGE_GRAYSCALE
Mat imgRight = imread("right.png");
imshow("left", imgLeft);
imshow("right", imgRight);
//-- And create the image in which we will save our disparities
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;
}
//-- 2. Call the constructor for StereoSGBM
int minDisparity = 0;
int numDisparities = 16;
int blockSize = 5;
int P1 = 0;
int P2 = 0;
int disp12MaxDiff = 0;
int preFilterCap = 0;
int uniquenessRatio = 0;
int speckleWindowSize = 0;
int speckleRange = 0;
int mode = StereoSGBM::MODE_SGBM;
Ptr<StereoSGBM> sgbm = StereoSGBM::create(minDisparity, numDisparities, blockSize, P1, P2, disp12MaxDiff, preFilterCap, uniquenessRatio, speckleWindowSize, speckleRange, mode);
//-- 3. Calculate the disparity image
sgbm->compute(imgLeft, imgRight, imgDisparity16S);
//-- Check its extreme values
double minVal; double maxVal;
minMaxLoc(imgDisparity16S, &minVal, &maxVal);
printf("Min disp: %f Max value: %f \n", minVal, maxVal);
//-- 4. Display it as a CV_8UC1 image
imgDisparity16S.convertTo(imgDisparity8U, CV_8UC1, 255 / (maxVal - minVal));
namedWindow(windowDisparity, WINDOW_NORMAL);
imshow(windowDisparity, imgDisparity8U);
//-- 5. Save the image
imwrite("SGBM_sample.png", imgDisparity16S);