Take the aloe image pair with OpenCV as an example:
1.BM Algorithm (Block Matching)
The parameters are set as follows:
intNumberofdisparities = ((Imgsize.width/8) + the) &- -; CV::P TR<cv::StereoBM> BM = Cv::stereobm::create ( -,9); Cv::rect Roi1, Roi2; BM-setROI1 (ROI1); BM-setROI2 (ROI2); BM->setprefiltercap ( to); BM->setblocksize (9); BM->setmindisparity (0); BM-setnumdisparities (numberofdisparities); BM->settexturethreshold (Ten); BM->setuniquenessratio ( the); BM->setspecklewindowsize ( -); BM->setspecklerange ( +); BM->setdisp12maxdiff (1); BM->compute (IMGL, imgr, disp);
The effect is as follows:
The parallax map (left) obtained by the BM algorithm, and the disparity map (right) resulting from the cavity filling.
2.SGBM (semi-global Block matching) algorithm:
The parameters are set as follows:
enum{STEREO_BM =0, STEREO_SGBM =1, stereo_hh =2, Stereo_var =3, Stereo_3way =4 }; intNumberofdisparities = ((Imgsize.width/8) + the) &- -; CV::P TR<cv::StereoSGBM> SGBM = Cv::stereosgbm::create (0, -,3); SGBM->setprefiltercap ( the); intSadwindowsize =9; intSgbmwinsize = sadwindowsize >0? Sadwindowsize:3; SGBM-setblocksize (sgbmwinsize); intCN =imgl.channels (); SGBM->SETP1 (8* cn*sgbmwinsize*sgbmwinsize); SGBM->SETP2 ( +* cn*sgbmwinsize*sgbmwinsize); SGBM->setmindisparity (0); SGBM-setnumdisparities (numberofdisparities); SGBM->setuniquenessratio (Ten); SGBM->setspecklewindowsize ( -); SGBM->setspecklerange ( +); SGBM->setdisp12maxdiff (1); intALG =STEREO_SGBM; if(ALG = =stereo_hh) SGBM-SetMode (CV::STEREOSGBM::MODE_HH); Else if(ALG = =STEREO_SGBM) SGBM-SetMode (CV::STEREOSGBM::MODE_SGBM); Else if(ALG = =stereo_3way) SGBM-SetMode (Cv::stereosgbm::mode_sgbm_3way); SGBM->compute (IMGL, imgr, disp);
Effect
The disparity map (left) obtained by the SGBM algorithm, and the disparity map (right) resulting from the hole filling.
It can be seen that the disparity map obtained by the SGBM algorithm reduces a lot of inaccurate matching points compared to the BM algorithm, especially in the depth discontinuous region, the speed SGBM is slower than the BM algorithm. OpenCV3.0 later did not implement the GC algorithm, may be due to speed considerations, later find time to fill the comparison chart, as well as the detailed principle of each algorithm analysis.
I fill the void after the effect is not very good, if there is a better way, hope to enlighten.
Comparison of the effect of two stereo matching algorithms in OpenCV3.4