Ask Your Question
1

Stereo Rectification - Rectified image larger than original one

asked 2013-11-21 07:35:17 -0600

Cuong gravatar image

updated 2013-11-21 10:38:21 -0600

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-11-21 09:05:34 -0600

Josep Bosch gravatar image

What is happening is that only the valid points on the images are shown. Have a look at the documentation of alpha parameter of stereorectify. If you set alpha to 1 you will see all the original pixels in the rectified image.

StereoRectifyDoc

edit flag offensive delete link more

Comments

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.

Cuong gravatar imageCuong ( 2013-11-21 10:34:10 -0600 )edit

Invalid means, that there will be black pixels, as they aren't in the original images... Alpha should go from 0 to 1... -1 it's like default value. I don't get what part of the image you want to cut...

Josep Bosch gravatar imageJosep Bosch ( 2013-11-21 11:13:08 -0600 )edit

thank you. I understand. Thanks a lot :)

Cuong gravatar imageCuong ( 2013-11-26 11:09:56 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-11-21 07:35:17 -0600

Seen: 2,174 times

Last updated: Nov 21 '13