在给定的Z中进行2D到3D投影 [英] 2D to 3D Projection with given Z in world

查看:107
本文介绍了在给定的Z中进行2D到3D投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,以前是否有人问过我,但是我找不到我问题的正确答案.

I'm sorry if it has been ask before but I couldn't find the proper answer to my question.

为了更好地理解,让我简要说明问题的背景

For a better understanding, let me briefly explain the context of my problem

上下文

我有两个图像(A和B),上面有非平面物体.我希望能够从A获得像素pA的坐标并将其投影到B.由于我的场景不是平面的,所以不能使用单应性.我要做的是先将像素pA投影到3D世界中,然后将结果投影到图像B中以获得pB.pA(2D)-> pWorld(3D)-> pB(2D).幸运的是,我知道pworld的坐标z.我的问题涉及到第一步pA(2D)-> pWorld(3D).

I have two images (A and B) with non planar object on it. I would like to be able to take the coordinate of a pixel pA from A and project it into B. Since my scene is not planar, I can't use homography. What I want to do is first project my pixel pA into the 3D world and then project the result into the image B to get pB. pA (2D) -> pWorld (3D) -> pB (2D). Fortunately, I know the coordinate z of pworld. My question concerns the first step pA (2D) -> pWorld (3D).

问题

在给定Z的情况下,如何将我的2D点pA(u,v)投影到世界(pWorld =(X,Y,Z))中?我也有相机的外部矩阵Rt(3x4)和本征矩阵K(3x3).

How to project my 2D point pA (u,v) into the world (pWorld=(X,Y,Z)), Z being given? I also have the extrinsic matrix Rt (3x4) and the intrinsic matrix K (3x3) of my camera.

我尝试过的事情

我知道: s *(u v 1)'= K * Rt *(X Y Z)'[1]

s是小数位数.但是我想得到相反的过程,给定Z.像这样:

s is the scale. But I would like to have the opposite process, Z being given. Something like:

(X Y)=某些*(u v)

我可以重写[1]来获得 s *(u v 1/s 1/s)'= G *(X Y Z 1)'

I can rewrite [1] to get s*(u v 1/s 1/s)' = G * (X Y Z 1)'

其中G =(l1 l2 l3 l4)(l表示行)

with G = (l1 l2 l3 l4) (l means line)

l1 =(K * Rt)的第一行

l1 = first line of (K*Rt)

l2 =(K * Rt)的第二行

l2 = second line of (K*Rt)

l3 = 0 0 1/Z 0

l3 = 0 0 1/Z 0

l4 = 0 0 0 1

l4 = 0 0 0 1

G是可逆的,然后我可以拥有(X Y Z 1)'= inv(G)*(我们vs 1 1)'

G is invertible and I can then have (X Y Z 1)' = inv(G) * (us vs 1 1)'

但是由于我不知道比例,所以我不能使用它.我觉得我对这种规模的事情有些困惑.我知道通常我们会规范化摆脱它,但在这里,我做不到.

But I can't use that since I don't know the scale. I think I'm a bit confused concerning this scale thing. I know usually we normalized to get rid of it but here, I can't.

也许这不是进行的好方法.如果有人可以向我解释一个好方法,那么我很高兴听到这个消息.

Maybe that's not the good way to proceed. If someone can explain me the good way, I would be really glad to hear about it.

谢谢.

推荐答案

我找到了一个解决方案,但是该死的丑陋.

I found a solution but it is damn ugly.

让我们考虑3x4矩阵M:

Let's consider the 3x4 matrix M:

M = K*Rt = (mij) 1<i<3, 1<j<4

为简单起见,我们还考虑系数A和B:

For simplification, let's also consider the coefficients A and B:

A = (m12-m32*u)/(m22-m32v)
B = (m31*u-m11)/(m31*v-m21)

解释了该符号,让我们继续进行系统操作.如我所说,系统为:

The notation explained, let's move on to the system. As I said, the system is:

s*(u v 1)' = M*(X Y Z 1)'

我们有 3个等式 3个未知数: s,X Y .我们可以注意到:

We have 3 equations and 3 unknowns : s, X and Y. We can notice that:

s = m31*X + m32*Y + m33*Z + m34

请注意,如果要投影到摄像机坐标系中而不是在世界坐标系中(类似于没有旋转和平移的情况),则可以使用s = Z,这是一种更简单的系统解决(此处示例从OpenCV的屏幕坐标)

考虑到这一点,我们可以将原始系统简化为具有 2个未知数( X ):

With this in mind, we can reduce the original system into a system of 2 equations with 2 unknowns (X and Y):

然后,经过一些计算,我们最终得到:

Then, after some calculations, we finally get:

X = [Z*((m23-M33*v)*A-m13+m33*u) + (m24-m34*v)*A-m14+m34*u ] / [A*(m31*v-m21)-m31*u+m11]

Y = [Z*((m13-m33*u)-B*(m23-m33*v)) + m14-m34*u-B*(m24-m34*v)] / [B*(m22-m32*v)-m12+m32*u]

它是u,v和Z函数中X和Y的表达式.我在我的项目中对其进行了测试,并且该项目正在运行.

It is the expression of X and Y in function of u, v and Z. I tested that with my project and it was working.

不知道是否有一种更简便的方法(使用Matrix和其他方法)来计算该值,但这就是我现在能想到的全部内容.

Don't know if there is a cleaner way to compute that (with Matrix and stuff), but that's all I could come up with for now.

这篇关于在给定的Z中进行2D到3D投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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