Package org.opencv.calib3d
Class StereoBM
java.lang.Object
org.opencv.core.Algorithm
org.opencv.calib3d.StereoMatcher
org.opencv.calib3d.StereoBM
Class for computing stereo correspondence using the block matching algorithm, introduced and contributed to OpenCV by K. Konolige.
This class implements a block matching algorithm for stereo correspondence, which is used to compute disparity maps from stereo image pairs. It provides methods to fine-tune parameters such as pre-filtering, texture thresholds, uniqueness ratios, and regions of interest (ROIs) to optimize performance and accuracy.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intFields inherited from class org.opencv.calib3d.StereoMatcher
DISP_SCALE, DISP_SHIFT -
Method Summary
Modifier and TypeMethodDescriptionstatic StereoBM__fromPtr__(long addr) static StereoBMcreate()Creates StereoBM objectstatic StereoBMcreate(int numDisparities) Creates StereoBM objectstatic StereoBMcreate(int numDisparities, int blockSize) Creates StereoBM objectintGets the current truncation value for prefiltered pixels.intGets the current size of the pre-filter kernel.intGets the type of pre-filtering currently used in the algorithm.getROI1()Gets the current Region of Interest (ROI) for the left image.getROI2()Gets the current Region of Interest (ROI) for the right image.intGets the current size of the smaller block used for texture check.intGets the current texture threshold value.intGets the current uniqueness ratio value.voidsetPreFilterCap(int preFilterCap) Sets the truncation value for prefiltered pixels.voidsetPreFilterSize(int preFilterSize) Sets the size of the pre-filter kernel.voidsetPreFilterType(int preFilterType) Sets the type of pre-filtering used in the algorithm.voidSets the Region of Interest (ROI) for the left image.voidSets the Region of Interest (ROI) for the right image.voidsetSmallerBlockSize(int blockSize) Sets the size of the smaller block used for texture check.voidsetTextureThreshold(int textureThreshold) Sets the threshold for filtering low-texture regions.voidsetUniquenessRatio(int uniquenessRatio) Sets the uniqueness ratio for filtering ambiguous matches.Methods inherited from class org.opencv.calib3d.StereoMatcher
compute, getBlockSize, getDisp12MaxDiff, getMinDisparity, getNumDisparities, getSpeckleRange, getSpeckleWindowSize, setBlockSize, setDisp12MaxDiff, setMinDisparity, setNumDisparities, setSpeckleRange, setSpeckleWindowSizeMethods inherited from class org.opencv.core.Algorithm
clear, empty, getDefaultName, getNativeObjAddr, save
-
Field Details
-
PREFILTER_NORMALIZED_RESPONSE
public static final int PREFILTER_NORMALIZED_RESPONSE- See Also:
-
PREFILTER_XSOBEL
public static final int PREFILTER_XSOBEL- See Also:
-
-
Method Details
-
__fromPtr__
-
getPreFilterType
public int getPreFilterType()Gets the type of pre-filtering currently used in the algorithm.- Returns:
- The current pre-filter type: 0 for PREFILTER_NORMALIZED_RESPONSE or 1 for PREFILTER_XSOBEL.
-
setPreFilterType
public void setPreFilterType(int preFilterType) Sets the type of pre-filtering used in the algorithm.- Parameters:
preFilterType- The type of pre-filter to use. Possible values are: - PREFILTER_NORMALIZED_RESPONSE (0): Uses normalized response for pre-filtering. - PREFILTER_XSOBEL (1): Uses the X-Sobel operator for pre-filtering. The pre-filter type affects how the images are prepared before computing the disparity map. Different pre-filtering methods can enhance specific image features or reduce noise, influencing the quality of the disparity map.
-
getPreFilterSize
public int getPreFilterSize()Gets the current size of the pre-filter kernel.- Returns:
- The current pre-filter size.
-
setPreFilterSize
public void setPreFilterSize(int preFilterSize) Sets the size of the pre-filter kernel.- Parameters:
preFilterSize- The size of the pre-filter kernel. Must be an odd integer, typically between 5 and 255. The pre-filter size determines the spatial extent of the pre-filtering operation, which prepares the images for disparity computation by normalizing brightness and enhancing texture. Larger sizes reduce noise but may blur details, while smaller sizes preserve details but are more susceptible to noise.
-
getPreFilterCap
public int getPreFilterCap()Gets the current truncation value for prefiltered pixels.- Returns:
- The current pre-filter cap value.
-
setPreFilterCap
public void setPreFilterCap(int preFilterCap) Sets the truncation value for prefiltered pixels.- Parameters:
preFilterCap- The truncation value. Typically in the range [1, 63]. This value caps the output of the pre-filter to [-preFilterCap, preFilterCap], helping to reduce the impact of noise and outliers in the pre-filtered image.
-
getTextureThreshold
public int getTextureThreshold()Gets the current texture threshold value.- Returns:
- The current texture threshold.
-
setTextureThreshold
public void setTextureThreshold(int textureThreshold) Sets the threshold for filtering low-texture regions.- Parameters:
textureThreshold- The threshold value. Must be non-negative. This parameter filters out regions with low texture, where establishing correspondences is difficult, thus reducing noise in the disparity map. Higher values filter more aggressively but may discard valid information.
-
getUniquenessRatio
public int getUniquenessRatio()Gets the current uniqueness ratio value.- Returns:
- The current uniqueness ratio.
-
setUniquenessRatio
public void setUniquenessRatio(int uniquenessRatio) Sets the uniqueness ratio for filtering ambiguous matches.- Parameters:
uniquenessRatio- The uniqueness ratio value. Typically in the range [5, 15], but can be from 0 to 100. This parameter ensures that the best match is sufficiently better than the next best match, reducing false positives. Higher values are stricter but may filter out valid matches in difficult regions.
-
getSmallerBlockSize
public int getSmallerBlockSize()Gets the current size of the smaller block used for texture check.- Returns:
- The current smaller block size.
-
setSmallerBlockSize
public void setSmallerBlockSize(int blockSize) Sets the size of the smaller block used for texture check.- Parameters:
blockSize- The size of the smaller block. Must be an odd integer between 5 and 255. This parameter determines the size of the block used to compute texture variance. Smaller blocks capture finer details but are more sensitive to noise, while larger blocks are more robust but may miss fine details.
-
getROI1
Gets the current Region of Interest (ROI) for the left image.- Returns:
- The current ROI for the left image.
-
setROI1
Sets the Region of Interest (ROI) for the left image.- Parameters:
roi1- The ROI rectangle for the left image. By setting the ROI, the stereo matching computation is limited to the specified region, improving performance and potentially accuracy by focusing on relevant parts of the image.
-
getROI2
Gets the current Region of Interest (ROI) for the right image.- Returns:
- The current ROI for the right image.
-
setROI2
Sets the Region of Interest (ROI) for the right image.- Parameters:
roi2- The ROI rectangle for the right image. Similar to setROI1, this limits the computation to the specified region in the right image.
-
create
Creates StereoBM object- Parameters:
numDisparities- The disparity search range. For each pixel, the algorithm will find the best disparity from 0 (default minimum disparity) to numDisparities. The search range can be shifted by changing the minimum disparity.blockSize- The linear size of the blocks compared by the algorithm. The size should be odd (as the block is centered at the current pixel). Larger block size implies smoother, though less accurate disparity map. Smaller block size gives more detailed disparity map, but there is a higher chance for the algorithm to find a wrong correspondence.- Returns:
- A pointer to the created StereoBM object. The function creates a StereoBM object. You can then call StereoBM::compute() to compute disparity for a specific stereo pair.
-
create
Creates StereoBM object- Parameters:
numDisparities- The disparity search range. For each pixel, the algorithm will find the best disparity from 0 (default minimum disparity) to numDisparities. The search range can be shifted by changing the minimum disparity.- Returns:
- A pointer to the created StereoBM object. The function creates a StereoBM object. You can then call StereoBM::compute() to compute disparity for a specific stereo pair.
-
create
Creates StereoBM object- Returns:
- A pointer to the created StereoBM object. The function creates a StereoBM object. You can then call StereoBM::compute() to compute disparity for a specific stereo pair.
-