Passing intrinsic information to stereoCalibrate.

asked 2016-02-15 05:51:48 -0500

stillNovice gravatar image

I am trying to improve my stereo calibration result by calibrating the cameras separately first, then using the CV_CALIB_FIX_INTRINSIC flag with stereoCalibrate. However, I am confused.

I have the Matrices, M1 and M2 (the intrinsic output of the left and right camera calibration)

I have the stereo calibrate code:

    // CALIBRATE THE STEREO CAMERAS
        printf("Running stereo calibration ...");
        fflush(stdout);
        cvStereoCalibrate(&_objectPoints, &_imagePoints1,
            &_imagePoints2, &_npoints,
            &_M1, &_D1, &_M2, &_D2,
            imageSize, &_R, &_T, &_E, &_F,
            //cvTermCriteria(CV_TERMCRIT_ITER +
            //  CV_TERMCRIT_EPS, 100, 1e-5),
            CV_CALIB_FIX_ASPECT_RATIO +
            CV_CALIB_ZERO_TANGENT_DIST +
            CV_CALIB_SAME_FOCAL_LENGTH + CV_CALIB_FIX_INTRINSIC);
        printf(" done\n");
        // CALIBRATION QUALITY CHECK

        vector<CvPoint3D32f> lines[2];
        points[0].resize(N);
        points[1].resize(N);
        _imagePoints1 = cvMat(1, N, CV_32FC2, &points[0][0]);
        _imagePoints2 = cvMat(1, N, CV_32FC2, &points[1][0]);
        lines[0].resize(N);
        lines[1].resize(N);
        CvMat _L1 = cvMat(1, N, CV_32FC3, &lines[0][0]);
        CvMat _L2 = cvMat(1, N, CV_32FC3, &lines[1][0]);
        //Always work in undistorted space
        cvUndistortPoints(&_imagePoints1, &_imagePoints1,
            &_M1, &_D1, 0, &_M1);
        cvUndistortPoints(&_imagePoints2, &_imagePoints2,
            &_M2, &_D2, 0, &_M2);
        cvComputeCorrespondEpilines(&_imagePoints1, 1, &_F, &_L1);
        cvComputeCorrespondEpilines(&_imagePoints2, 2, &_F, &_L2);
        double avgErr = 0;
        for (i = 0; i < N; i++)
        {
            double err = fabs(points[0][i].x*lines[1][i].x +
                points[0][i].y*lines[1][i].y + lines[1][i].z)
                + fabs(points[1][i].x*lines[0][i].x +
                    points[1][i].y*lines[0][i].y + lines[0][i].z);
            avgErr += err;
        }
        printf("avg err = %g\n", avgErr / (nframes*n));
        //COMPUTE AND DISPLAY RECTIFICATION
        if (showUndistorted)
        {

            CvMat* mx1 = cvCreateMat(imageSize.height,
                imageSize.width, CV_32F);
            CvMat* my1 = cvCreateMat(imageSize.height,
                imageSize.width, CV_32F);
            CvMat* mx2 = cvCreateMat(imageSize.height,

                imageSize.width, CV_32F);
            CvMat* my2 = cvCreateMat(imageSize.height,
                imageSize.width, CV_32F);
            CvMat* img1r = cvCreateMat(imageSize.height,
                imageSize.width, CV_8U);
            CvMat* img2r = cvCreateMat(imageSize.height,
                imageSize.width, CV_8U);
            CvMat* disp = cvCreateMat(imageSize.height,
                imageSize.width, CV_16S);
            CvMat* vdisp = cvCreateMat(imageSize.height,
                imageSize.width, CV_8U);
            CvMat* pair;
            double R1[3][3], R2[3][3], P1[3][4], P2[3][4];
            CvMat _R1 = cvMat(3, 3, CV_64F, R1);
            CvMat _R2 = cvMat(3, 3, CV_64F, R2);
            // IF BY CALIBRATED (BOUGUET'S METHOD)
            if (useUncalibrated == 0)
            {
                CvMat _P1 = cvMat(3, 4, CV_64F, P1);
                CvMat _P2 = cvMat(3, 4, CV_64F, P2);
                cvStereoRectify(&_M1, &_M2, &_D1, &_D2, imageSize,
                    &_R, &_T,
                    &_R1, &_R2, &_P1, &_P2, &_Q,
                    0/*CV_CALIB_ZERO_DISPARITY*/);
                isVerticalStereo = fabs(P2[1][3]) > fabs(P2[0][3]);
                //Precompute maps for cvRemap()
                cvInitUndistortRectifyMap(&_M1, &_D1, &_R1, &_P1, mx1, my1);
                cvInitUndistortRectifyMap(&_

M2, &_D2, &_R2, &_P2, mx2, my2);

    }

Where would i pass in the matrix data M1, M2?

Thanks!

edit retag flag offensive close merge delete

Comments

1

Why are you using the C-Interface that is deprecated for about a decade now?

FooBar gravatar imageFooBar ( 2016-02-15 11:03:25 -0500 )edit