Convert between MATLAB stereoParameters and OpenCV stereoRectify stereo calibration

后端 未结 3 1510
南旧
南旧 2021-02-03 15:07

I wish to convert a MATLAB stereoParameters structure to intrinsics and extrinsics matrices to use in OpenCV\'s stereoRectify.

If I understood http://docs.opencv.org/2.4

3条回答
  •  不知归路
    2021-02-03 15:56

    You can use the stereoRectify function in OpenCV to obtain R1, R2, P1, P2, Q given cameraMatrix1, cameraMatrix2, distCoeffs1, distCoeffs2, R & T.

    In C++ it would be

    cv::Mat R1, R2, P1, P2, Q; cv::Rect validRoi[2]; cv::stereoRectify(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imSize, R, T, R1, R2, P1, P2, Q, CV_CALIB_ZERO_DISPARITY, 0, imSize, &validRoi[0], &validRoi[1]);

    One important thing to note is that the matrices cameraMatrix1, cameraMatrix2 and R need to be transposed when copying them from their MATLAB counterparts.

    (I put this in bold as it cost 2 days to figure out why my rectification wasn't working when I converted it from MATLAB to C++ OpenCV)

提交回复
热议问题