问题描述
我希望将MATLAB StealoParameters结构转换为可在OpenCV的StereteRectify中使用的内在和外在矩阵.
I wish to convert a MATLAB stereoParameters structure to intrinsics and extrinsics matrices to use in OpenCV's stereoRectify.
如果我理解 http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html 和 http: //mathworks.com/help/vision/ref/stereoparameters-class.html ,stereoParameterParameters.CameraParameters1和stereoParameters.CameraParameters2存储本征矩阵,而stereoParameterParameter的其他成员存储本征矩阵.
If I understood http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html and http://mathworks.com/help/vision/ref/stereoparameters-class.html , stereoParameters.CameraParameters1 and stereoParameters.CameraParameters2 store the intrinsic matrices and the other members of stereoParameters the extrinsic ones.
我想我得到了这个映射
本征:
- cameraMatrix1 =立体声参数.CameraParameters1.IntrinsicMatrix'
- cameraMatrix2 =立体声参数.CameraParameters2.IntrinsicMatrix'
- distCoeffs1 = [stereoParameters.CameraParameters1.RadialDistortion(1:2),立体声参数.CameraParameters1.TangentialDistortion,立体声参数.CameraParameters1.RadialDistortion(3)]
- distCoeffs2 = [stereoParameters.CameraParameters2.RadialDistortion(1:2),立体声参数.CameraParameters2.TangentialDistortion,立体声参数.CameraParameters2.RadialDistortion(3)]
外部特性:
- R =立体声参数.RotationOfCamera2'
- T =立体声参数.TranslationOfCamera2'
到目前为止,这正确吗?
Is that correct, so far?
还是,我看不到如何获得
Still, I can't see how to get
- R1(3x3)
- R2(3x3)
- P1(3x4)
- P2(3x4)
- Q(4x4)
其余stereoParameters的矩阵.
matrices from the rest of stereoParameters.
我可以使用现有的转换器吗?如果没有,公式是什么?
Is there an existing converter I can use, and if not, what are the formulas?
推荐答案
在给定cameraMatrix1,cameraMatrix2,distCoeffs1,distCoeffs2,R& amp;的给定条件下,您可以在OpenCV中使用stereoRectify
函数来获取R1,R2,P1,P2,Q. T.
You can use the stereoRectify
function in OpenCV to obtain R1, R2, P1, P2, Q given cameraMatrix1, cameraMatrix2, distCoeffs1, distCoeffs2, R & T.
在C ++中应该是
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]);
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]);
要注意的一件事是,在从其MATLAB副本中复制矩阵CameraMatrix1,cameraMatrix2和R时,需要对其进行转置.
(我将其用黑体表示,因为花了两天的时间才能弄清为什么我将其从MATLAB转换为C ++ OpenCV时,整流无法正常工作)
(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)
这篇关于在MATLAB StereonParameters和OpenCV Sterete之间进行转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!