简体   繁体   English

运动重投影问题中的OpenCV结构

[英]OpenCV Structure from Motion Reprojection Issue

I am currently facing an issue with my Structure from Motion program based on OpenCv. 我目前在基于OpenCv的Motion程序中遇到“结构”问题。 I'm gonna try to depict you what it does, and what it is supposed to do. 我将尝试向您描述它的作用以及应该做什么。

This program lies on the classic "structure from motion" method. 该程序基于经典的“运动构造”方法。

The basic idea is to take a pair of images, detect their keypoints and compute the descriptors of those keypoints. 基本思想是拍摄一对图像,检测其关键点并计算这些关键点的描述符。 Then, the keypoints matching is done, with a certain number of tests to insure the result is good. 然后,完成关键点匹配,并进行一定数量的测试以确保结果良好。 That part works perfectly. 该部分工作完美。

Once this is done, the following computations are performed : fundamental matrix, essential matrix, SVD decomposition of the essential matrix, camera matrix computation and finally, triangulation. 完成此操作后,将执行以下计算:基本矩阵,基本矩阵,基本矩阵的SVD分解,相机矩阵计算以及最后的三角剖分。

The result for a pair of images is a set of 3D coordinates, giving us points to be drawn in a 3D viewer. 一对图像的结果是一组3D坐标,为我们提供了在3D查看器中绘制的点。 This works perfectly, for a pair. 这对一对来说效果很好。

Indeed, here is my problem : for a pair of images, the 3D points coordinates are calculated in the coordinate system of the first image of the image pair , taken as the reference image. 确实,这是我的问题: 对于一对图像,在图像对的第一幅图像的坐标系中将3D点坐标作为参考图像进行计算。 When working with more than two images, which is the objective of my program, I have to reproject the 3D points computed in the coordinate system of the very first image , in order to get a consistent result. 当处理两个以上的图像(这是我的程序的目标)时, 我必须重新投影在第一张图像的坐标系中计算出的3D点 ,以便获得一致的结果。

My question is : How do I reproject 3D points coordinate given in a camera related system, into an other camera related system ? 我的问题是: 如何将与摄像机相关的系统中给定的3D点坐标重新投影到另一个与摄像机相关的系统中? With the camera matrices ? 用相机矩阵?

My idea was to take the 3D point coordinates, and to multiply them by the inverse of each camera matrix before. 我的想法是获取3D点坐标,并将其乘以之前每个相机矩阵的逆。

I clarify : 我澄清一下:

Suppose I am working on the third and fourth image (hence, the third pair of images, because I am working like 1-2 / 2-3 / 3-4 and so on). 假设我正在处理第三张和第四张图像(因此,第三对图像,因为我正在像1-2 / 2-3 / 3-4等工作)。

I get my 3D point coordinates in the coordinate system of the third image, how do I do to reproject them properly in the very first image coordinate system ? 我在第三个图像的坐标系中获得3D点坐标,如何在第一个图像坐标系中正确地重新投影它们?

I would have done the following : 我将执行以下操作:

Get the 3D points coordinates matrix, apply the inverse of the camera matrix for image 2 to 3, and then apply the inverse of the camera matrix for image 1 to 2. Is that even correct ? 获取3D点坐标矩阵,对图像2到3应用相机矩阵的逆,然后对图像1到2应用相机矩阵的逆。这是否正确?

Because those camera matrices are non square matrices, and I can't inverse them. 因为这些相机矩阵是非正方形矩阵,所以我无法将它们求逆。

I am surely mistaking somewhere, and I would be grateful if someone could enlighten me, I am pretty sure this is a relative easy one, but I am obviously missing something... 我肯定会误会某个地方,如果有人能启发我,我将不胜感激,我敢肯定这是一个相对容易的事情,但是我显然缺少了一些东西...

Thanks a lot for reading :) 非常感谢您的阅读:)

Let us say you have a 3 * 4 extrinsic parameter matrix called P . 假设您有一个称为P的3 * 4外在参数矩阵。 To match the notations of OpenCV documentation , this is [R|t] . 为了匹配OpenCV文档的符号,此为[R|t]

This matrix P describes the projection from world space coordinates to the camera space coordinates. 该矩阵P描述了从世界空间坐标到摄像机空间坐标的投影。 To quote the documentation: 引用文档:

[R|t] translates coordinates of a point (X, Y, Z) to a coordinate system, fixed with respect to the camera. [R | t]将点(X,Y,Z)的坐标转换为相对于相机固定的坐标系。

You are wondering why this matrix is non-square. 您想知道为什么此矩阵是非正方形的。 That is because in the usual context of OpenCV, you are not expecting homogeneous coordinates as output. 这是因为在OpenCV的通常情况下,您不希望将齐次坐标作为输出。 Therefore, to make it square, just add a fourth row containing (0,0,0,1) . 因此,要使其变为正方形,只需添加包含(0,0,0,1)的第四行。 Let's call this new square matrix Q . 我们称这个新的方阵Q

You have one such matrix for each pair of cameras, that is you have one Qk matrix for each pair of images {k,k+1} that describes the projection from the coordinate space of camera k to that of camera k+1 . 每对摄像机都有一个这样的矩阵,也就是说,每对图像{k,k+1}都有一个Qk矩阵,描述了从摄像机k的坐标空间到摄像机k+1的坐标空间的投影。 Those matrices are inversible because they describe isometries in homogeneous coordinates. 这些矩阵是不可逆的,因为它们描述的是同构坐标中的等距。

To go from the coordinate space of camera 3 to that of camera 1, just apply to your points the inverse of Q2 and then the inverse of Q1 . 要从摄像机3的坐标空间移到摄像机1的坐标空间,只需将Q2的倒数, 然后Q1的倒数应用于您的点。

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

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