OpenCV:计算 StereoRectify 的旋转矩阵
我想计算旋转和平移矩阵以用于开放式CV中的stereoRectify。校正后的图像看起来扭曲且完全不正确(就像图像中心的两个方向完全扭曲的圆锥体一样)
我有两个相机的旋转和平移矩阵......
此外,这是一篇类似的帖子,但它没有帮助: 查找两个相机之间的旋转矩阵对于“Stereorectify”,
我在下面分享我的代码......
// Create interinsic parameters matrix given the translation and rotation matrecis
Mat CreateExternsicParamsMat(Mat R, Mat T)
{
Mat ext1(4,4,T.type());
Mat ext2(4,4,T.type());
for(int i=0; i<3;i++)
for(int j=0;j<3; j++)
ext1.at<double>(i,j) = R.at<double>(i,j);
for(int i=0; i<3;i++)
ext1.at<double>(i,3) = T.at<double>(i,0);
ext1.at<double>(3,3) = 1;
ext1.at<double>(3,2) = 0;
ext1.at<double>(3,1) = 0;
ext1.at<double>(3,0) = 0;
return ext1;
}
Mat ext1 = CreateExternsicParamsMat(R1,T1);
Mat ext2 = CreateExternsicParamsMat(R2,T2);
Mat ext1inv;
invert(ext1,ext1inv);
Mat ext = ext1inv*ext2;
for(int i=0; i<3;i++)
for(int j=0;j<3; j++)
R.at<double>(i,j) = ext.at<double>(i,j);
for(int i=0; i<3;i++)
T.at<double>(i,0)=ext.at<double>(i,3);
stereoRectify( M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q);
I want to compute the rotation and translation matrices to use for stereoRectify in open CV. The rectified images look twisted and totally incorrect (Like completely twisted cone at the center of the image going both directions)
I have the rotation and translation matrices of both cameras....
Also, this is a smilar post but it is not helping: Finding Rotation matrices between two cameras for "Stereorectify"
I am sharing my code below...
// Create interinsic parameters matrix given the translation and rotation matrecis
Mat CreateExternsicParamsMat(Mat R, Mat T)
{
Mat ext1(4,4,T.type());
Mat ext2(4,4,T.type());
for(int i=0; i<3;i++)
for(int j=0;j<3; j++)
ext1.at<double>(i,j) = R.at<double>(i,j);
for(int i=0; i<3;i++)
ext1.at<double>(i,3) = T.at<double>(i,0);
ext1.at<double>(3,3) = 1;
ext1.at<double>(3,2) = 0;
ext1.at<double>(3,1) = 0;
ext1.at<double>(3,0) = 0;
return ext1;
}
Mat ext1 = CreateExternsicParamsMat(R1,T1);
Mat ext2 = CreateExternsicParamsMat(R2,T2);
Mat ext1inv;
invert(ext1,ext1inv);
Mat ext = ext1inv*ext2;
for(int i=0; i<3;i++)
for(int j=0;j<3; j++)
R.at<double>(i,j) = ext.at<double>(i,j);
for(int i=0; i<3;i++)
T.at<double>(i,0)=ext.at<double>(i,3);
stereoRectify( M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论