哈哈哈哈哈
<pre name="code" class="cpp">#include "cv.h"#include "cvaux.h"#include "cxcore.h"#include "highgui.h"#include <highgui.h>#include <cv.h>#include <cxcore.h>#include <iostream>using namespace std;using namespace cv;//reference: OpenCV1.1 cvref.htm//by Gong Peiliang in SIA, CAS;//11-11 //东门吹雪int main( int argc, char** argv){IplImage * cv_left_rectified;IplImage * cv_right_rectified;//note the sequence of the stereo pairscv_left_rectified = cvLoadImage( "right.jpg", CV_LOAD_IMAGE_GRAYSCALE);cv_right_rectified = cvLoadImage( "left.jpg", CV_LOAD_IMAGE_GRAYSCALE);CvSize size = cvGetSize( cv_left_rectified );//the disparity map is an array h*w, with 16bit signed elements.CvMat* disparity_left = cvCreateMat( size.height, size.width, CV_16S );CvMat* disparity_right = cvCreateMat( size.height, size.width, CV_16S );CvStereoGCState* state = cvCreateStereoGCState( 16, 2 );cvFindStereoCorrespondenceGC( cv_left_rectified,cv_right_rectified,disparity_left,disparity_right,state,0 );cvReleaseStereoGCState( &state );//post-progressing the resultCvMat* disparity_left_visual = cvCreateMat( size.height, size.width, CV_8U );cvConvertScale( disparity_left, disparity_left_visual, -16 );cvSave( "disparity.png", disparity_left_visual );cvNamedWindow( "disparity", 1);cvShowImage("disparity", disparity_left_visual );cvWaitKey( 0 );cvDestroyWindow( "disparity" );return 0;}