Documentation of CvStereoBMState for disparity calculation with cv::StereoBM
Asked Answered
R

2

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.
Rikkiriksdag answered 25/3, 2014 at 9:31 Comment(3)
"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.Toxicity
@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).Shutdown
Is the algorithm itself explained anywhere?Albertina
B
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).

Brahms answered 10/2, 2015 at 15:15 Comment(0)
R
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.

Rhodarhodamine answered 22/5, 2019 at 10:48 Comment(1)
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.Wheelhouse

© 2022 - 2024 — McMap. All rights reserved.