Ask Your Question

what kind of reason will lead to this kind of stereorectify result

asked 2016-01-26 00:48:44 -0500

german_iris gravatar image

After calibrate my webcams successfully, I want to stereo rectify views from the two webcams captured at the same time.But the result seems not to be very successful. This is the views before stereo rectify:

image description

And this is undistorted result of the left view(without stereo rectify)

image description

And then ,this is my stereo rectify result:

image description

And this is part of my code:

//estimate position and orientation
cout << "estimate position and orientation of the second camera" << endl
    << "relative to the first camera..." << endl;
stereoCalibrate(ObjectPoints, imagePointsFirst, imagePointsSec, intrMatFirst, distCoeffsFirst,
    intrMatSec, distCoffesSec, imageSize, R, T, E, F,  CV_CALIB_FIX_INTRINSIC ,
    TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, 1e-6));

//stereo rectify
cout << "stereo rectify..." << endl;
stereoRectify(intrMatFirst, distCoeffsFirst, intrMatSec, distCoffesSec, imageSize, R, T, RFirst,
    RSec, PFirst, PSec, Q, 0, 1, imageSize, &validRoi[0], &validRoi[1]);

//cature pictures for 3d-reconstruction
cout << "catch the picture for 3d-reconstruction..." << endl;
VideoCapture captureFirst(cameraIdFirst);
VideoCapture captureSec(cameraIdSec);

if ((!captureFirst.isOpened()) || (!captureSec.isOpened()))
    cout << "can't open the camera..." << endl;
    return -1;

Mat canvas(imageSize.height, imageSize.width * 2, CV_8UC3);
Mat canLeft = canvas(Rect(0, 0, imageSize.width, imageSize.height));
Mat canRight = canvas(Rect(imageSize.width, 0, imageSize.width, imageSize.height));
Mat viewFirst, viewSec;

cout << "push 'c' to catch pictures for 3d-reconstruction" << endl;
namedWindow("canvas", 1);
while (1)
    int key = 0;
    captureFirst >> viewFirst;
    captureSec >> viewSec;
    imshow("canvas", canvas);

    key = 0xff & waitKey(50);

    if (key=='c')
        cout << "catch pictures done..." << endl;

//rectify the catched pictures
Mat rmapFirst[2], rmapSec[2], rviewFirst, rviewSec;
initUndistortRectifyMap(intrMatFirst, distCoeffsFirst, RFirst, PFirst,
    imageSize, CV_16SC2, rmapFirst[0], rmapFirst[1]);
initUndistortRectifyMap(intrMatSec, distCoffesSec, RSec, PSec,
    imageSize, CV_16SC2, rmapSec[0], rmapSec[1]);
remap(viewFirst, rviewFirst, rmapFirst[0], rmapFirst[1], INTER_LINEAR);
remap(viewSec, rviewSec, rmapSec[0], rmapSec[1], INTER_LINEAR);

so what's reason???

edit retag flag offensive close merge delete


stereoCalibrate returns a reprojection error. please try to make this as small as possible.

berak gravatar imageberak ( 2016-01-26 07:24:04 -0500 )edit

so do you mean that it comes from my pool calibration?

german_iris gravatar imagegerman_iris ( 2016-01-26 23:37:50 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-01-26 06:28:19 -0500

Some things to definately check

  1. Make sure the dimensions of your calibration pattern are uneven. Now you have an even amount of cols, which can screw up the calibration setup.
  2. Make sure you have enough calibration images, using 2 images will never yield a good camera calibration.
  3. Be sure to calibrate every single region of your camera range, if not, you will have large deformations towards the non calibrated areas.

Good luck!

edit flag offensive delete link more


At the beginning , I wanna say thx. you are right. The calibration result is not very accurate, and I know that. But I just want to figure out whether the only calibration error will lead to the very ridiculous stereo recitfy result.

german_iris gravatar imagegerman_iris ( 2016-01-27 00:21:42 -0500 )edit

Well in my experience, if the calibration is not accurate, you can get the most weird rectify results ever. We once forgot to calibrate a third of the image, resulting in a completely wrongly warped image. So yes, focus on a good calibration first.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-01-27 02:42:39 -0500 )edit

get it. thx very much!

german_iris gravatar imagegerman_iris ( 2016-01-27 03:09:16 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-01-26 00:48:44 -0500

Seen: 400 times

Last updated: Jan 26 '16