Three stereo matching algorithms are implemented in OPENCV:
BM algorithm
SGBM algorithm
GC algorithm
Reference: http://blog.csdn.net/wqvbjhc/article/details/6260844
First introduced:SGBM algorithm , as a global matching algorithm, the effect of stereo matching is better than the local matching algorithm, but at the same time the complexity is much larger than the local matching algorithm. The algorithm is mainly referred to stereo processing by Semiglobal Matching and Mutual information
Reference: http://www.opencv.org.cn/forum.php?mod=viewthread&tid=23854
#include #include<cv.h>#include<cxcore.h>#include<iostream>using namespacestd;using namespaceCV;intMain () {Iplimage* IMG1 = Cvloadimage ("Left.png",0); Iplimage* Img2 = Cvloadimage ("Right.png",0); CV::STEREOSGBM SGBM; intSadwindowsize =9; Sgbm.prefiltercap= the; SGBM. Sadwindowsize= sadwindowsize >0? Sadwindowsize:3; intCN = img1->nchannels; intnumberofdisparities= -; SGBM. P1=8*CN*SGBM. sadwindowsize*SGBM. Sadwindowsize; SGBM. P2= +*CN*SGBM. sadwindowsize*SGBM. Sadwindowsize; Sgbm.mindisparity=0; Sgbm.numberofdisparities=numberofdisparities; Sgbm.uniquenessratio=Ten; Sgbm.specklewindowsize= -; Sgbm.specklerange= +; Sgbm.disp12maxdiff=1; Mat disp, DISP8; Int64 T=GetTickCount (); SGBM (MAT) IMG1, (MAT) Img2, disp); T= GetTickCount ()-T; cout<<"Time Elapsed:"<<t* +/gettickfrequency () <<Endl; Disp.convertto (DISP8, cv_8u,255/(numberofdisparities* -.)); Namedwindow (" Left",1); Cvshowimage (" Left", IMG1); Namedwindow (" Right",1); Cvshowimage (" Right", IMG2); Namedwindow ("Disparity",1); Imshow ("Disparity", DISP8); Waitkey (); Imwrite ("Sgbm_disparity.png", DISP8); Cvdestroyallwindows (); return 0;}
Stereo Matching algorithm