Regarding CStereoMatcher::Match

  • Nobody/Anonymous

    Hello Sir,
    I am interested in using the function CStereoMatcher::Match for computing matches for individual points in stereo image pairs. The pixels/landmark points are selected in a digital image in left widget and then the "match" function is used to findout a match for the selected point.

    The syntax of the method is : int CStereoMatcher::Match  ( const CByteImage *  pLeftImage,   const CByteImage * pRightImage,   int  x,   int  y,   int  nWindowSize,   int  d1,   int  d2,   Vec2d &  result,  Vec3d &  result_3d,  float  fThreshold,  bool  bInputImagesAreUndistorted = false  )

    I am using the function in this manner :
    If (clicked a point on left widget)

    Vec2d left_point = { (float) left_x, (float) left_y };
    Vec2d right_point;
    Vec3d result_point;

    CStereoMatcher *matcher;
    matcher= new CStereoMatcher();
    int dparity=matcher->Match(&grayImage1,&grayImage2,left_x,left_y,307200,0,1,right_point,result_point,0.0f,false);
    This code is not working. There is something wrong probably. I am also doubtful about 307200 (640 X480) value for nWindowSize. Coule you please let me know how to use the Match function to search for best matching point in another image? One more thing, I am clicking point in a widget, but the Match function accepts only constance CByte image. Could you please let me know how to use the image in the widget for "Match" function?

    Thanking you in anticipation of a favourable response.

  • Pedram Azad

    Pedram Azad - 2010-09-10


    I think you understood two fundamental things about stereo correlation a bit wrong:

    1. The correlation window is the search window. A reasonable size is e.g. 13 x 13, but this depends on your image material. As the documentation says, you would have to use nWindowSize = 13, if you want to use a 13 x 13 window.

    2. The interval  is the disparity search range. Setting d1 = 0 is ok, as a starting point. It depends on your image material, what is reasonable for d2. Try a large d2 first, e.g. 300, then visualize the computed correspondence, and if it is correct, the return value of Match is the disparity. So then you can see what is the reasonable range of disparities in your images. If you try with scene_left.bmp and scene_right.bmp from IVT/files, d1 = 80 and d2 = 140 should do the job.

    Also, as the documentation says, it is strictly recommended to undistort the images first. So simply use the class CUndistortion, load your camera parameter file, and undistort the image pair by calling CUndistortion::Undistort. So then you have to set the last parameter in CStereoMatcher::Match to true.

    Try with scene_left.bmp and scene_right.bmp first, that should perfectly work if you do it right. Once that works, you can try with your own image material. And don't forget to calibrate your stereo camera system with IVT/examples/CalibrationApp. A good calibration is essential for stereo matching to work.

    Hope that helps!


  • Nobody/Anonymous

    Hello Sir,
    Thanks a lot for your quick help. I will get back to you soon.

  • Nobody/Anonymous

    Hello Sir,
    Thanks for the reply. I can now find the correlated match for the clicked point on one image to the corresponding point on the other image. As you mentioned in your previous reply,  the disparity range (d1,d2) depends on the image material. So, with the change of the images, the inital values for d1 and d2 might need to be modified if I am not wrong. Could you please let me know if there is an already exisiting function/method in the IVT /CV library to determine the maximum and minimum range for the disparity map?

    I would be thankful to you if you could let me know about some websites to understand disparity maps and its maximum and minimum range. In addition, can you please share your email address . Thanking you in anticipation of a favourable response.

  • Pedram Azad

    Pedram Azad - 2010-09-16


    the range  really depends on the camera setup and application. That means for instance if you want to measure distances from 0.5 m to 1 m the parameters are different than if you wanted to measure distances from 2 m and 3 m.

    There is a function CStereoMatcher::GetDisparityEstimate, which should be ok for a rough estimate. But still you have to know what is your distance range of interest.

    You find my email address on the contact page on


  • Nobody/Anonymous

    Thanks a lot sir for your quick reply.


Log in to post a comment.