OpenCV
Open Source Computer Vision
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
cv::StereoBM Class Referenceabstract

Class for computing stereo correspondence using the block matching algorithm, introduced and contributed to OpenCV by K. Konolige. More...

#include <opencv2/calib3d.hpp>

Collaboration diagram for cv::StereoBM:

Public Types

enum  {
  PREFILTER_NORMALIZED_RESPONSE = 0 ,
  PREFILTER_XSOBEL = 1
}
 Pre-filter types for the stereo matching algorithm. More...
 
- Public Types inherited from cv::StereoMatcher
enum  {
  DISP_SHIFT = 4 ,
  DISP_SCALE = (1 << DISP_SHIFT)
}
 

Public Member Functions

virtual int getPreFilterCap () const =0
 Gets the current truncation value for prefiltered pixels.
 
virtual int getPreFilterSize () const =0
 Gets the current size of the pre-filter kernel.
 
virtual int getPreFilterType () const =0
 Gets the type of pre-filtering currently used in the algorithm.
 
virtual Rect getROI1 () const =0
 Gets the current Region of Interest (ROI) for the left image.
 
virtual Rect getROI2 () const =0
 Gets the current Region of Interest (ROI) for the right image.
 
virtual int getSmallerBlockSize () const =0
 Gets the current size of the smaller block used for texture check.
 
virtual int getTextureThreshold () const =0
 Gets the current texture threshold value.
 
virtual int getUniquenessRatio () const =0
 Gets the current uniqueness ratio value.
 
virtual void setPreFilterCap (int preFilterCap)=0
 Sets the truncation value for prefiltered pixels.
 
virtual void setPreFilterSize (int preFilterSize)=0
 Sets the size of the pre-filter kernel.
 
virtual void setPreFilterType (int preFilterType)=0
 Sets the type of pre-filtering used in the algorithm.
 
virtual void setROI1 (Rect roi1)=0
 Sets the Region of Interest (ROI) for the left image.
 
virtual void setROI2 (Rect roi2)=0
 Sets the Region of Interest (ROI) for the right image.
 
virtual void setSmallerBlockSize (int blockSize)=0
 Sets the size of the smaller block used for texture check.
 
virtual void setTextureThreshold (int textureThreshold)=0
 Sets the threshold for filtering low-texture regions.
 
virtual void setUniquenessRatio (int uniquenessRatio)=0
 Sets the uniqueness ratio for filtering ambiguous matches.
 
- Public Member Functions inherited from cv::StereoMatcher
virtual void compute (InputArray left, InputArray right, OutputArray disparity)=0
 Computes disparity map for the specified stereo pair.
 
virtual int getBlockSize () const =0
 
virtual int getDisp12MaxDiff () const =0
 
virtual int getMinDisparity () const =0
 
virtual int getNumDisparities () const =0
 
virtual int getSpeckleRange () const =0
 
virtual int getSpeckleWindowSize () const =0
 
virtual void setBlockSize (int blockSize)=0
 
virtual void setDisp12MaxDiff (int disp12MaxDiff)=0
 
virtual void setMinDisparity (int minDisparity)=0
 
virtual void setNumDisparities (int numDisparities)=0
 
virtual void setSpeckleRange (int speckleRange)=0
 
virtual void setSpeckleWindowSize (int speckleWindowSize)=0
 
- Public Member Functions inherited from cv::Algorithm
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 Clears the algorithm state.
 
virtual bool empty () const
 Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 Reads algorithm parameters from a file storage.
 
virtual void save (const String &filename) const
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 
virtual void write (FileStorage &fs) const
 Stores algorithm parameters in a file storage.
 
void write (FileStorage &fs, const String &name) const
 

Static Public Member Functions

static Ptr< StereoBMcreate (int numDisparities=0, int blockSize=21)
 Creates StereoBM object.
 
- Static Public Member Functions inherited from cv::Algorithm
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 Loads algorithm from the file.
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 Loads algorithm from a String.
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 Reads algorithm from the file node.
 

Additional Inherited Members

- Protected Member Functions inherited from cv::Algorithm
void writeFormat (FileStorage &fs) const
 

Detailed Description

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.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Pre-filter types for the stereo matching algorithm.

These constants define the type of pre-filtering applied to the images before computing the disparity map.

  • PREFILTER_NORMALIZED_RESPONSE: Uses normalized response for pre-filtering.
  • PREFILTER_XSOBEL: Uses the X-Sobel operator for pre-filtering.
Enumerator
PREFILTER_NORMALIZED_RESPONSE 

Normalized response pre-filter.

PREFILTER_XSOBEL 

X-Sobel pre-filter.

Member Function Documentation

◆ create()

static Ptr< StereoBM > cv::StereoBM::create ( int numDisparities = 0,
int blockSize = 21 )
static
Python:
cv.StereoBM.create([, numDisparities[, blockSize]]) -> retval
cv.StereoBM_create([, numDisparities[, blockSize]]) -> retval

Creates StereoBM object.

Parameters
numDisparitiesThe 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.
blockSizeThe 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.

◆ getPreFilterCap()

virtual int cv::StereoBM::getPreFilterCap ( ) const
pure virtual
Python:
cv.StereoBM.getPreFilterCap() -> retval

Gets the current truncation value for prefiltered pixels.

Returns
The current pre-filter cap value.

◆ getPreFilterSize()

virtual int cv::StereoBM::getPreFilterSize ( ) const
pure virtual
Python:
cv.StereoBM.getPreFilterSize() -> retval

Gets the current size of the pre-filter kernel.

Returns
The current pre-filter size.

◆ getPreFilterType()

virtual int cv::StereoBM::getPreFilterType ( ) const
pure virtual
Python:
cv.StereoBM.getPreFilterType() -> retval

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.

◆ getROI1()

virtual Rect cv::StereoBM::getROI1 ( ) const
pure virtual
Python:
cv.StereoBM.getROI1() -> retval

Gets the current Region of Interest (ROI) for the left image.

Returns
The current ROI for the left image.

◆ getROI2()

virtual Rect cv::StereoBM::getROI2 ( ) const
pure virtual
Python:
cv.StereoBM.getROI2() -> retval

Gets the current Region of Interest (ROI) for the right image.

Returns
The current ROI for the right image.

◆ getSmallerBlockSize()

virtual int cv::StereoBM::getSmallerBlockSize ( ) const
pure virtual
Python:
cv.StereoBM.getSmallerBlockSize() -> retval

Gets the current size of the smaller block used for texture check.

Returns
The current smaller block size.

◆ getTextureThreshold()

virtual int cv::StereoBM::getTextureThreshold ( ) const
pure virtual
Python:
cv.StereoBM.getTextureThreshold() -> retval

Gets the current texture threshold value.

Returns
The current texture threshold.

◆ getUniquenessRatio()

virtual int cv::StereoBM::getUniquenessRatio ( ) const
pure virtual
Python:
cv.StereoBM.getUniquenessRatio() -> retval

Gets the current uniqueness ratio value.

Returns
The current uniqueness ratio.

◆ setPreFilterCap()

virtual void cv::StereoBM::setPreFilterCap ( int preFilterCap)
pure virtual
Python:
cv.StereoBM.setPreFilterCap(preFilterCap) -> None

Sets the truncation value for prefiltered pixels.

Parameters
preFilterCapThe 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.

◆ setPreFilterSize()

virtual void cv::StereoBM::setPreFilterSize ( int preFilterSize)
pure virtual
Python:
cv.StereoBM.setPreFilterSize(preFilterSize) -> None

Sets the size of the pre-filter kernel.

Parameters
preFilterSizeThe 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.

◆ setPreFilterType()

virtual void cv::StereoBM::setPreFilterType ( int preFilterType)
pure virtual
Python:
cv.StereoBM.setPreFilterType(preFilterType) -> None

Sets the type of pre-filtering used in the algorithm.

Parameters
preFilterTypeThe 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.

◆ setROI1()

virtual void cv::StereoBM::setROI1 ( Rect roi1)
pure virtual
Python:
cv.StereoBM.setROI1(roi1) -> None

Sets the Region of Interest (ROI) for the left image.

Parameters
roi1The 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.

◆ setROI2()

virtual void cv::StereoBM::setROI2 ( Rect roi2)
pure virtual
Python:
cv.StereoBM.setROI2(roi2) -> None

Sets the Region of Interest (ROI) for the right image.

Parameters
roi2The ROI rectangle for the right image.

Similar to setROI1, this limits the computation to the specified region in the right image.

◆ setSmallerBlockSize()

virtual void cv::StereoBM::setSmallerBlockSize ( int blockSize)
pure virtual
Python:
cv.StereoBM.setSmallerBlockSize(blockSize) -> None

Sets the size of the smaller block used for texture check.

Parameters
blockSizeThe 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.

◆ setTextureThreshold()

virtual void cv::StereoBM::setTextureThreshold ( int textureThreshold)
pure virtual
Python:
cv.StereoBM.setTextureThreshold(textureThreshold) -> None

Sets the threshold for filtering low-texture regions.

Parameters
textureThresholdThe 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.

◆ setUniquenessRatio()

virtual void cv::StereoBM::setUniquenessRatio ( int uniquenessRatio)
pure virtual
Python:
cv.StereoBM.setUniquenessRatio(uniquenessRatio) -> None

Sets the uniqueness ratio for filtering ambiguous matches.

Parameters
uniquenessRatioThe 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.


The documentation for this class was generated from the following file: