11

The application of Konolige's block matching algorithm is not sufficiantly explained in the OpenCV documentation. The parameters of CvStereoBMState influence the accuracy of the disparities calculated by cv::StereoBM. However, those parameters are not documented. I will list those parameters below and describe, what I understand. Maybe someone can add a description of the parameters, which are unclear.

  • preFilterType: Determines, which filter is applied on the image before the disparities are calculated. Can be CV_STEREO_BM_XSOBEL (Sobel filter) or CV_STEREO_BM_NORMALIZED_RESPONSE (maybe differences to mean intensity???)
  • preFilterSize: Window size of the prefilter (width = height of the window, negative value)
  • preFilterCap: Clips the output to [-preFilterCap, preFilterCap]. What happens to the values outside the interval?
  • SADWindowSize: Size of the compared windows in the left and in the right image, where the sums of absolute differences are calculated to find corresponding pixels.
  • minDisparity: The smallest disparity, which is taken into account. Default is zero, should be set to a negative value, if negative disparities are possible (depends on the angle between the cameras views and the distance of the measured object to the cameras).
  • numberOfDisparities: The disparity search range [minDisparity, minDisparity+numberOfDisparities].
  • textureThreshold: Calculate the disparity only at locations, where the texture is larger than (or at least equal to?) this threshold. How is texture defined??? Variance in the surrounding window???
  • uniquenessRatio: Cited from calib3d.hpp: "accept the computed disparity d* only ifSAD(d) >= SAD(d*)(1 + uniquenessRatio/100.) for any d != d+/-1 within the search range."
  • speckleRange: Unsure.
  • trySmallerWindows: ???
  • roi1, roi2: Calculate the disparities only in these regions??? Unsure.
  • speckleWindowSize: Unsure.
  • disp12MaxDiff: Unsure, but a comment in calib3d.hpp says, that a left-right check is performed. Guess: Pixels are matched from the left image to the right image and from the right image back to the left image. The disparities are only valid, if the distance between the original left pixel and the back-matched pixel is smaller than disp12MaxDiff.
3
  • 1
    "minDisparity: [...] should be set to a negative value, since negative disparities are possible." > it depends whether you used the flag CV_CALIB_ZERO_DISPARITY in stereoRectify. If you did, then minDisparity should be set to zero or to a positive number, because in this case the disparity cannot be negative. For the other variables, I don't know.
    – BConic
    Mar 25, 2014 at 12:09
  • 2
    @AldurDisciple, As for minDisparity parameter I'm using CV_CALIB_ZERO_DISPARITY in stereoRectify, yet the minimum of the calculated disparity is negative (e.g. -16).
    – Basel
    May 7, 2014 at 19:37
  • Is the algorithm itself explained anywhere? Feb 21, 2018 at 17:53

2 Answers 2

3

speckleWindowSize and speckleRange are parameters for the function cv::filterSpeckles. Take a look at OpenCV's documentation. cv::filterSpeckles is used to post-process the disparity map. It replaces blobs of similar disparities (the difference of two adjacent values does not exceed speckleRange) whose size is less or equal speckleWindowSize (the number of pixels forming the blob) by the invalid disparity value (either short -16 or float -1.f).

0

The parameters are better described in the Python tutorial on depth map from stereo images. The parameters seem to be the same.

texture_threshold: filters out areas that don't have enough texture for reliable matching

Speckle range and size: Block-based matchers often produce "speckles" near the boundaries of objects, where the matching window catches the foreground on one side and the background on the other. In this scene it appears that the matcher is also finding small spurious matches in the projected texture on the table. To get rid of these artifacts we post-process the disparity image with a speckle filter controlled by the speckle_size and speckle_range parameters. speckle_size is the number of pixels below which a disparity blob is dismissed as "speckle." speckle_range controls how close in value disparities must be to be considered part of the same blob.

Number of disparities: How many pixels to slide the window over. The larger it is, the larger the range of visible depths, but more computation is required.

min_disparity: the offset from the x-position of the left pixel at which to begin searching.

uniqueness_ratio: Another post-filtering step. If the best matching disparity is not sufficiently better than every other disparity in the search range, the pixel is filtered out. You can try tweaking this if texture_threshold and the speckle filtering are still letting through spurious matches.

prefilter_size and prefilter_cap: The pre-filtering phase, which normalizes image brightness and enhances texture in preparation for block matching. Normally you should not need to adjust these.

Also check out this ROS tutorial on choosing stereo parameters.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.