Beispiel #1
0
CvMat * createDisparityMapGC(CvArr * img1, CvArr * img2,
						  int numberOfDisparities, int maxIters)
{
	CvSize imageSize = cvGetSize(img1);

	// image_left and image_right are the input 8-bit single-channel images
	// from the left and the right cameras, respectively
	// CvSize size = cvGetSize(image_left);
	CvMat* disparity_left = cvCreateMat( imageSize.height, imageSize.width,
										 CV_16S );
	CvMat* disparity_right = cvCreateMat( imageSize.height, imageSize.width,
										  CV_16S );

	// (int numberOfDisparities, int maxIters)
	CvStereoGCState* state = cvCreateStereoGCState( 16, // numberOfDisparities
													2   //maxIters
													);

	cvFindStereoCorrespondenceGC( img1, img2,
								  disparity_left, disparity_right, state, 0 );
	cvReleaseStereoGCState( &state );

	CvMat* disparity_left_visual =
		cvCreateMat( imageSize.height, imageSize.width, CV_8U );
	// because the values in the left disparity images are usually negative
	cvConvertScale( disparity_left, disparity_left_visual, -16 );
	// cvSave( "disparity.pgm", disparity_left_visual );
	//cvSaveImage( "disparity.pgm", disparity_left_visual );
	return disparity_left_visual;
}
StereoCorrespondenceCV::~StereoCorrespondenceCV()
{
    if ( m_mode == LocalMatching )
        cvReleaseStereoBMState(&m_bmState);
    else
        cvReleaseStereoGCState(&m_gcState);
}