简体   繁体   English

单应性opencv的旋转和平移矩阵

[英]rotation and translation matrix from homography opencv

我正在Java中的android应用程序上工作,我使用findHomography()用opencv计算了单应性,我如何找到包含通过单应性旋转和平移的相机姿势矩阵

 Mat homography = Calib3d.findHomography(ReferencePoints2, ReferencePoints1,0,Calib3d.RANSAC);

You need to know the intrinsic parameters of the camera to do that. 您需要知道相机的固有参数才能做到这一点。

Considers the z=0 plane. 考虑z = 0平面。 The point 重点

 X=(x,y,0,1)'

is projected to the image as 投影到图像为

p=P*X.

Now use the decomposition 现在使用分解

P=K[R t],

where K is the calibration matrix and [R t] are extrinsic parameters. 其中K是校准矩阵,[R t]是外部参数。 Since z=0, the third column vector of R is multiplied by zero. 由于z = 0,R的第三列向量乘以零。 We can now drop the 3rd column to get 现在,我们可以删除第三列以获得

p=K*[r1 r2 t]*(x,y,1)=H*(x,y,1),

where H is a planar homography. 其中H是平面单应性。

You have already computed H from eg known points. 您已经根据已知点计算了H。 The first and second column of R and the vector t can now be recovered 现在可以恢复R的第一和第二列以及向量t

[r1 r2 t]=inv(K)*H.

Make sure that r1 and r2 are unit length, then t is the correct translation vector. 确保r1和r2是单位长度,然后t是正确的转换向量。 The third column vector of R can be recovered because R is orthogonal, for example using the cross product. 因为R是正交的,所以可以恢复R的第三列向量,例如使用叉积。

r3=cross(r1,r2).

Since H is a measurement, the r1 and r2 you computed are not exact. 由于H是度量值,因此您计算出的r1和r2不精确。 You can use the SVD for obtaining the closest rotation matrix to a measurement. 您可以使用SVD获得最接近测量值的旋转矩阵。 You can then compose a projection matrix 然后您可以组成一个投影矩阵

P=K[r1 r2 r3 t]

which projects any 3D point in the coordinate frame based on your 2D coordinate system of the homograohy. 会根据同构的2D坐标系在坐标系中投影任何3D点。

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 https://www.dropbox.com/s/qkulg4j64lyn0qa/2018_proj_geo_for_cv_projcv_assignment.pdf?dl=0

Here is a related question. 这是一个相关的问题。 Computing camera pose with homography matrix based on 4 coplanar points 基于4个共面点的单应矩阵计算相机姿态

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. 正如@nbsrujan(感谢)指出的那样,对于使用OpenCV的用户,有一个函数可以根据内部函数将单应性分解为平移和旋转矩阵。

OpenCV has a function which can decompose Homography to translation and rotation matrices. OpenCV的一个功能,它可以分解单应以平移和旋转矩阵。 But, we have to choose correct translation and rotation matrix pair from array of possible matrices returned by this function. 但是,我们必须从此函数返回的可能矩阵的数组中选择正确的平移和旋转矩阵对。

normal vector is surface normal in first camera's frame. 法线向量是第一个摄像机帧中的表面法线。 If you know camera's rotation in the world for initial frame, it can be used to filter out correct translation and rotation pair from list of possibilities. 如果您知道相机在初始帧中的旋转角度,则可以用来从可能性列表中滤除正确的平移和旋转对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM