OpenCV估算距离单应性法线向量 [英] OpenCV estimate distance & normal vector from homography

查看:340
本文介绍了OpenCV估算距离单应性法线向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在匹配一个模板,据此我可以知道与&的距离我的法线向量.

I'm matching a template from which I know my distance to & my normal vector to.

即如果我的单应性是单位矩阵,则我的相机的距离= 1.0m&我的正常值为0.

i.e. if my homography is the identity matrix then my camera is at Distance = 1.0m & my normal is at 0.

现在,我有第二张图像,其中我成功对齐了模板,并提供了单应性:

Now I have a second image in which I successfully aligned my template giving an homography:

     [0.82072, 0.05685, 66.75024]
 H = [0.02006, 0.86092, 39.34907]
     [0.00003, 0.00017, 01.00000]

我也有我的相机矩阵.

opencv函数:

cv::decomposeHomographyMat()

为我提供了4种旋转(3x3垫),平移(3x1垫)&法向向量(3x1).

gives me 4 solutions for the Rotation(3x3 mat),Translation(3x1 mat) & Normal vector(3x1).

cv::warpPerspective()

能够将相机的当前视图几乎完美地映射到我的模板上.

Is able to map nearly perfectly the current view of the camera to my template.

因此,应该有可能获得实际的缩放比例(要对齐的模板)&正常向量.

So it should be possible to get the actual scaling (template to alignment) & the normal vector.

但是我无法弄清楚如何真正选择cv :: decomposeHomographyMat()的正确解决方案,我缺少什么了?

But I can't figure it out how to actually choose the correct solutions of cv::decomposeHomographyMat(), I'm I missing something?

发布问题"而没有问题...

Posted "question" without the question...

推荐答案

我知道了.

第一步:

我在ROI中创建了一组点,可以映射到我的模板(由ROI角定义的区域中的点).

I create a set of point in the ROI I can map to my template (points in the area defined by the corners of the ROI).

第二步:

使用cv :: decomposeHomographyMat()的所有解决方案使ROI中的点(从第一步开始;在我的所有测试和用例中,只有8点就足够了)

Warp the points in ROI (from step one; 8 points are enough in all my tests & use case) with all the solutions of cv::decomposeHomographyMat()

排除所有给出z值<的point3D(x,y,z)的解. 0(即点位于相机后面).

Exclude all solutions that give a point3D(x, y, z) with a z value < 0 (i.e. point is behind the camera).

第三步:

这时您应该有一到两个解决方案. 所有旋转矩阵都应该相同,只有法线&翻译矩阵应该不同.

At this point you should have one to two solutions left. All rotations matrixes should be the same, only the normal & translation matrix should differ.

翻译矩阵应验证:

Translation_Solution1 = -1* Translation_Solution2

然后将您的ROI区域与模板区域进行比较. 如果您的ROI区域小于模板,则表示您的模板已按比例缩小",即您的相机在z上以负值进行了平移. 否则,您的相机会对z的正值进行平移.

Then compare your ROI area to you template area. If you ROI area is smaller than your template, it means that you template as been "scaled down", i.e. your camera did a translation on z in the negative values. Else you camera did a translation on the positive z values.

选择合适的解决方案.

我的错误是认为warpPerspective()实际上在解决同形分解,但事实并非如此.

My error was to think that warpPerspective() was actually solving the Homography decomposition, but its not.

这篇关于OpenCV估算距离单应性法线向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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