单应性opencv的旋转和平移矩阵 [英] rotation and translation matrix from homography opencv
问题描述
我正在用Java开发一个android应用程序,我使用findHomography()用opencv计算了单应性,如何找到包含通过单应性旋转和平移的相机姿势矩阵
I'm working on an android application in java,I calculated homography with opencv using findHomography(), how I can find the matrix of the camera pose containing the rotation and translation through homography
Mat homography = Calib3d.findHomography(ReferencePoints2, ReferencePoints1,0,Calib3d.RANSAC);
推荐答案
您需要知道相机的固有参数.
You need to know the intrinsic parameters of the camera to do that.
考虑z = 0平面.重点
Considers the z=0 plane. The point
X=(x,y,0,1)'
投影到图像上
p=P*X.
现在使用分解
P=K[R t],
其中,K是校准矩阵,[R t]是外部参数.由于z = 0,R的第三列向量乘以零.现在,我们可以删除第三列以获取
where K is the calibration matrix and [R t] are extrinsic parameters. Since z=0, the third column vector of R is multiplied by zero. We can now drop the 3rd column to get
p=K*[r1 r2 t]*(x,y,1)=H*(x,y,1),
其中H是平面单应性.
您已经根据例如已知点.现在可以恢复R的第一和第二列以及向量t
You have already computed H from e.g. known points. The first and second column of R and the vector t can now be recovered
[r1 r2 t]=inv(K)*H.
确保r1和r2是单位长度,然后t是正确的转换向量. R的第三列向量可以恢复,因为R是正交的,例如使用叉积.
Make sure that r1 and r2 are unit length, then t is the correct translation vector. The third column vector of R can be recovered because R is orthogonal, for example using the cross product.
r3=cross(r1,r2).
由于H是测量值,因此您计算出的r1和r2不精确.您可以使用SVD获得最接近测量值的旋转矩阵.然后,您可以组成一个投影矩阵
Since H is a measurement, the r1 and r2 you computed are not exact. You can use the SVD for obtaining the closest rotation matrix to a measurement. You can then compose a projection matrix
P=K[r1 r2 r3 t]
根据您的同构2D坐标系在坐标系中投影任何3D点.
which projects any 3D point in the coordinate frame based on your 2D coordinate system of the homograohy.
这里有一些课程材料,描述了这种情况.
Here is some course material, which describes this situation.
https://www.dropbox.com/s/qkulg4j64lyn0qa /2018_proj_geo_for_cv_projcv_assignment.pdf?dl=0
这是一个相关的问题. 使用基于4个共面的单应矩阵计算相机姿态点
Here is a related question. Computing camera pose with homography matrix based on 4 coplanar points
正如@nbsrujan(感谢)指出的那样,对于使用OpenCV的用户,有一个
As @nbsrujan (thanks) pointed out, for those using OpenCV, there is a function which can decompose a homography into translation and rotation matrices given the intrinsics.
这篇关于单应性opencv的旋转和平移矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!