Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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;
    viewFirst.copyTo(canLeft);
    viewSec.copyTo(canRight);
    imshow("canvas", canvas);

    key = 0xff & waitKey(50);

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

//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???