StereoMatching module
This section briefly introduces the functions and usage of StereoMatching.cpp and StereoMatching.h files.
Module Function
The StereoMatching
module is the core of disparity map generation, including:
Generate disparity map using left and right images.
Post-process the disparity results, such as morphological operations or WLS filtering.
Core function analysis
1. SetParamOCVStereo(StereoCamParam_t&)
SetParamOCVStereo(StereoCamParam_t&)
Initialize StereoBM or StereoSGBM matcher according to the passed camera parameters, for example:
bm->setBlockSize(objStereoParam.m_nWindowSize);
bm->setNumDisparities(objStereoParam.m_nNumberOfDisp);
2. MakeDisparity(Mat& imgLeft, Mat& imgRight, bool flgUseWLSFilter)
MakeDisparity(Mat& imgLeft, Mat& imgRight, bool flgUseWLSFilter)
Calculate the disparity map and provide WLS filter optimization options.
3. ImproveDisparity_Naive
and ImproveDisparity_WLSFilter
ImproveDisparity_Naive
and ImproveDisparity_WLSFilter
Naive: morphological filtering and hole filling, fast but average effect.
WLSFilter: Use weighted least squares filter to remove noise and generate a smoother disparity map.
Example
CStereoMatching stereoMatcher(objStereoParam);
stereoMatcher.MakeDisparity(imgLeft, imgRight, true);
Mat disp8 = stereoMatcher.m_imgDisp8; // Get the optimized disparity map
Notes
Parameter setting:
BlockSize
andNumOfDisparities
inSetParamOCVStereo
have a great impact on the result.Version compatibility: The OpenCV version can be determined by macros.
Last updated