Ask Your Question
0

disparity map result image size(height& width)

asked 2016-02-25 22:28:57 -0600

AdamIB gravatar image

updated 2016-02-26 04:31:21 -0600

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);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-02-26 09:04:23 -0600

berak gravatar image

no, the disparity image has exactly the same size as the input, try to print it out:

cerr << imgLeft.size() << endl;
cerr << imgDisparity8U.size() << endl;

but i see this in your code:

 namedWindow(windowDisparity, WINDOW_NORMAL);

makes a "resizable" window, can it be, you resized it manually with mouse ? (the size will get saved in the registry or similar)

edit flag offensive delete link more

Comments

OK solved by using resize:

resize(imgDisparity8U, imgDisparity8U, Size(imgLeft.size())); imshow("Disparity grayscale", imgDisparity8U);

AdamIB gravatar imageAdamIB ( 2016-02-26 17:26:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-02-25 22:28:57 -0600

Seen: 552 times

Last updated: Feb 26 '16