First time here? Check out the FAQ!

Ask Your Question
0

disparity map result image size(height& width)

asked Feb 26 '16

AdamIB gravatar image

updated Feb 26 '16

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);
Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Feb 26 '16

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)

Preview: (hide)

Comments

OK solved by using resize:

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

AdamIB gravatar imageAdamIB (Feb 26 '16)edit

Question Tools

1 follower

Stats

Asked: Feb 26 '16

Seen: 590 times

Last updated: Feb 26 '16