Hi everyone,
I'm having a problem with OpenCV in rectifying stereo images.
After calibration, I performed cvStereoRectify, cvInitUndistortRectifyMap, and cvRemap, respectively.
However, the rectified images became larger than the original one. I don't how I can correct this problem. For example, I hope to save the rectified images without cropping or interpolation.
Here is part of my implementation. Please help !
cvStereoCalibrate(_objectPoints, _imagePoints1, _imagePoints2, _pointCounts, M1, D1, M2, D2, cvGetSize(image1),
R, T, E, F,
cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-5),
CV_CALIB_SAME_FOCAL_LENGTH
+ CV_CALIB_ZERO_TANGENT_DIST
);
...
cvStereoRectify(intrinsic1, intrinsic2, distortion1, distortion2, cvGetSize(image1),
R, T, &_R1, &_R2, &_P1, &_P2, 0,
CV_CALIB_ZERO_DISPARITY + CV_CALIB_ZERO_TANGENT_DIST,
isVerticalStereo = fabs(P2[1][3]) > fabs(P2[0][3]), rectifiedSize
);
cvInitUndistortRectifyMap(intrinsic1, distortion1, &_R1, &_P1, mapx1, mapy1);
cvInitUndistortRectifyMap(intrinsic2, distortion2, &_R2, &_P2, mapx2, mapy2);
IplImage *rectImage1 = 0, *rectImage2 = 0;
for( int frame = 1; frame <= numOfImages; frame++ )
{
if(image1) { cvReleaseImage(&image1); image1 = 0; }
if(image2) { cvReleaseImage(&image2); image2 = 0; }
image1 = cvLoadImage(fileName1, CV_LOAD_IMAGE_COLOR);
image2 = cvLoadImage(fileName2, CV_LOAD_IMAGE_COLOR);
rectImage1 = cvCloneImage(image1);
rectImage2 = cvCloneImage(image2);
cvRemap(image1, rectImage1, mapx1, mapy1, CV_INTER_CUBIC+CV_WARP_FILL_OUTLIERS);
cvRemap(image2, rectImage2, mapx2, mapy2, CV_INTER_CUBIC+CV_WARP_FILL_OUTLIERS);
cvShowImage("image1", image1);
cvShowImage("image2", image2);
cvShowImage("rectImage1", rectImage1);
cvShowImage("rectImage2", rectImage2);
}