Ask Your Question

Cuong's profile - activity

2013-11-26 11:09:56 -0500 commented answer Stereo Rectification - Rectified image larger than original one

thank you. I understand. Thanks a lot :)

2013-11-25 12:44:52 -0500 received badge  Student (source)
2013-11-21 10:34:10 -0500 commented answer Stereo Rectification - Rectified image larger than original one

Hi Josep Bosch,

You mean other pixels are INVALID ? I just set alpha to 1 (and -1) to see all the original pixels as you said. However, I want to manually crop this image (as shown in the above figure, I just updated the question). Can I do that?

Thanks for your reply.

2013-11-21 08:22:48 -0500 received badge  Editor (source)
2013-11-21 07:35:17 -0500 asked a question Stereo Rectification - Rectified image larger than original one

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.

image description

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),  
cvStereoRectify(intrinsic1, intrinsic2, distortion1, distortion2, cvGetSize(image1),
    R, T,  &_R1, &_R2, &_P1, &_P2, 0,
    isVerticalStereo = fabs(P2[1][3]) > fabs(P2[0][3])

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);

I set alpha = -1, and manually crop this image. image description