OpenCV:从翻译和翻译中获取透视矩阵回转 [英] OpenCV: get perspective matrix from translation & rotation

查看:95
本文介绍了OpenCV:从翻译和翻译中获取透视矩阵回转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证我的相机校准,因此我想更正校准图像.我希望这会涉及到对warpPerspective的调用,但是我看不到一个明显的函数采用相机矩阵以及旋转和平移矢量来生成此调用的透视矩阵.

I'm trying to verify my camera calibration, so I'd like to rectify the calibration images. I expect that this will involve using a call to warpPerspective but I do not see an obvious function that takes the camera matrix, and the rotation and translation vectors to generate the perspective matrix for this call.

本质上,我想执行此处(尤其是靠近末端的图像),但从已知的相机型号和姿势开始.

Essentially I want to do the process described here (see especially the images towards the end) but starting with a known camera model and pose.

是否有一个简单的函数调用来获取相机的内在和外在参数,并计算用于warpPerspective的透视矩阵?

Is there a straightforward function call that takes the camera intrinsic and extrinsic parameters and computes the perspective matrix for use in warpPerspective?

在图像上调用undistort后,我将调用warpPerspective.

I'll be calling warpPerspective after having called undistort on the image.

原则上,我可以通过求解在 opencv摄像机校准文档在指定了约束Z=0之后,但是我认为必须有一个固定的例程才能使我对测试图像进​​行矫正.

In principle, I could derive the solution by solving the system of equations defined at the top of the opencv camera calibration documentation after specifying the constraint Z=0, but I figure that there must be a canned routine that will allow me to orthorectify my test images.

在我的透视图中,我很难遍历所有的立体校准结果-我只有一台摄像机,但想在我只看一个平面测试图案的约束下校正图像.

In my seearches, I'm finding it hard to wade through all of the stereo calibration results -- I only have one camera, but want to rectify the image under the constraint that I'm only looking a a planar test pattern.

推荐答案

实际上,不需要使用正交摄影机.这是获取适当的透视变换的方法.

Actually there is no need to involve an orthographic camera. Here is how you can get the appropriate perspective transform.

如果使用cv::calibrateCamera校准了相机,则将获得相机矩阵K镜头畸变系数D的矢量,以及使用的每个图像的旋转矢量rvec(其中您可以使用cv::rodrigues doc转换为3x3矩阵R )和翻译向量T.考虑这些图像之一以及关联的RT.使用失真系数调用cv::undistort后,图像将类似于由投影矩阵K * [ R | T ]的相机获取的图像.

If you calibrated the camera using cv::calibrateCamera, you obtained a camera matrix K a vector of lens distortion coefficients D for your camera and, for each image that you used, a rotation vector rvec (which you can convert to a 3x3 matrix R using cv::rodrigues, doc) and a translation vector T. Consider one of these images and the associated R and T. After you called cv::undistort using the distortion coefficients, the image will be like it was acquired by a camera of projection matrix K * [ R | T ].

基本上(如@DavidNilosek所暗示的那样),您想取消旋转并获得图像,就好像它是由格式为K * [ I | -C ]的投影矩阵获取的,其中C=-R.inv()*T是相机位置.为此,您必须应用以下转换:

Basically (as @DavidNilosek intuited), you want to cancel the rotation and get the image as if it was acquired by the projection matrix of form K * [ I | -C ] where C=-R.inv()*T is the camera position. For that, you have to apply the following transformation:

Hr = K * R.inv() * K.inv()

唯一的潜在问题是,变形的图像可能会超出图像平面的可见部分.因此,您可以使用其他翻译来解决该问题,如下所示:

The only potential problem is that the warped image might go outside the visible part of the image plane. Hence, you can use an additional translation to solve that issue, as follows:

     [ 1  0  |         ]
Ht = [ 0  1  | -K*C/Cz ]
     [ 0  0  |         ]

其中Cz是C沿着Oz轴的分量.

where Cz is the component of C along the Oz axis.

最后,对于上述定义,H = Ht * Hr是所考虑图像的矫正透视变换.

Finally, with the definitions above, H = Ht * Hr is a rectifying perspective transform for the considered image.

这篇关于OpenCV:从翻译和翻译中获取透视矩阵回转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆