Code the three stereo matching algorithms involved in opencv and their respective advantages and disadvantages:
First, let's take a look at the BM algorithm:
The algorithm code:
Cvstereobmstate * bmstate = cvcreatestereobmstate (); <br/> int sadwindowsize = 15; <br/> bmstate-> sadwindowsize = sadwindowsize> 0? Sadwindowsize: 9; <br/> bmstate-> mindisparity = 0; <br/> bmstate-> numberofdisparities = 32; <br/> bmstate-> texturethreshold = 10; <br/> bmstate-> uniquenessratio = 15; <br/> bmstate-> specklewindowsize = 100; <br/> bmstate-> specklerange = 32; <br/> bmstate-> disp12maxdiff = 1; <br/> values (left, right, left_disp _, bmstate); <br/> cvnormalize (left_disp _, left_vdisp, 0,256, cv_minmax); <br/>
Mindisparity is the first parameter to control the matching search. It indicates where the matching search starts, and numberofdisparities indicates the maximum search parallax number uniquenessratio indicates the matching function. These three parameters are important, parameters can be set based on the experiment.
This method is the fastest. A 320*240 grayscale image has a matching time of 31 Ms. The Parallax is shown below.
The second method is the sgbm method, which is a new algorithm of opencv:
CV: stereosgbm sgbm; <br/> sgbm. prefiltercap = 63; <br/> int sadwindowsize = 11; <br/> int Cn = 1; <br/> sgbm. sadwindowsize = sadwindowsize> 0? Sadwindowsize: 3; <br/> sgbm. p1 = 4 * Cn * sgbm. sadwindowsize * sgbm. sadwindowsize; <br/> sgbm. p2 = 32 * Cn * sgbm. sadwindowsize * sgbm. sadwindowsize; <br/> sgbm. mindisparity = 0; <br/> sgbm. numberofdisparities = 32; <br/> sgbm. uniquenessratio = 10; <br/> sgbm. specklewindowsize = 100; <br/> sgbm. specklerange = 32; <br/> sgbm. disp12maxdiff = 1; </P> <p> sgbm (left, right, left_disp _); <br/> sgbm (right, left, right_disp _);
The parameter settings, such as the BM method, are fast. The grayscale image matching time of 320*240 is 78 ms, and the parallax effect is shown in figure.
The third method is GC:
Cvstereogcstate * State = cvcreatestereogcstate (16, 2); <br/> left_disp _ = cvcreatemat (left-> height, left-> width, cv_32f ); <br/> right_disp _ = cvcreatemat (right-> height, right-> width, cv_32f); <br/> cvfindstereocorrespondencegc (left, right, left_disp _, right_disp _, state, state, 0); <br/> cvreleasestereogcstate (& State );
This method is slow, but the effect is superb.
The theory of each method can be referred to the literature.
Source: http://blog.csdn.net/mailang2008/archive/2010/09/09/5873883.aspx