使用任意已知的几何关系计算单应矩阵
我正在使用 OpenCV 作为光学测量系统。我需要在数码相机拍摄的两个图像之间进行透视变换。在相机的视野中,我放置了一组标记(位于公共平面上),我将其用作两个图像中的对应点。使用标记的位置我可以计算单应性矩阵。问题是,我实际上想要变换其图像的测量对象位于距标记很近的位置,并且与标记平面平行。我可以测量这个距离。
我的问题是,在计算单应矩阵时如何考虑该距离,这是执行透视变换所必需的。
在我的解决方案中,强烈要求不要使用测量的对象点来计算单应性(这就是为什么我需要在视野中使用其他标记)。
如果描述不准确,请告诉我。
图中呈现的是示例图像。
红色矩形为被测物体。它实际上放置在圆形标记后面一小段距离处。
我从不同相机的位置捕捉物体的图像。被测物体在每次采集之间可能会变形。使用圆形标记,我想将对象的图像转换为相同的坐标。我可以测量对象和标记之间的距离,但我不知道应该如何修改单应性矩阵才能处理测量对象(而不是标记)。
I am using OpenCV for an optical measurement system. I need to carry out a perspective transformation between two images, captured by a digital camera. In the field of view of the camera I placed a set of markers (which lie in a common plane), which I use as corresponding points in both images. Using the markers' positions I can calculate the homography matrix. The problem is, that the measured object, whose images I actually want to transform is positioned in a small distance from the markers and in parallel to the markers' plane. I can measure this distance.
My question is, how to take that distance into account when calculating the homography matrix, which is necessary to perform the perspective transformation.
In my solution it is a strong requirement not to use the measured object points for calculation of homography (and that is why I need other markers in the field of view).
Please let me know if the description is not precise.
Presented in the figure is the exemplary image.
The red rectangle is the measured object. It is physically placed in a small distance behind the circular markers.
I capture images of the object from different camera's positions. The measured object can deform between each acquisition. Using circular markers, I want to transform the object's image to the same coordinates. I can measure the distance between object and markers but I do not know, how should I modify the homography matrix in order to work on the measured object (instead of the markers).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题很老了,但是很有趣,并且可能对某人有用。
首先,这是我对问题中提出的问题的理解:
您有两张由同一台数码相机拍摄的图像 I1 和 I2在两个不同的位置。这些图像都显示了一组标记,它们都位于一个公共平面 pm 中。还有一个被测物体,其可见表面位于与标记平面平行但有较小偏移的平面 po 中。您计算了将 I1 中的标记位置映射到 I2 中相应标记位置的单应性 Hm12您测量了平面 po 和 pm 之间的偏移 dmo。由此,您需要计算 I1 中测量对象上的单应性 Ho12 映射点到 I< 中的相应点子>2。
关于这个问题的几点说明:
首先,请注意,单应性是图像点之间的关系,而标记平面和对象平面之间的距离是世界坐标中的距离。使用后者来推断前者需要对相机姿势进行度量估计,即您需要确定欧几里得和高达比例 相对位置&两个图像中每个图像的相机方向。 欧几里德要求意味着必须校准数码相机,这对于“光学测量系统”来说不应该是问题。 按比例要求意味着必须知道两个给定 3D 点之间的真实 3D 距离。例如,您需要知道两个任意标记之间的真实距离 l0。
由于我们只需要每个图像的相机的相对位姿,因此我们可以选择使用以相机坐标系为中心并对齐的 3D 坐标系,用于 I1 。因此,我们将 I1 的投影矩阵表示为 P1 = K1 * [ I | 0]。然后,我们将 I2(在同一 3D 坐标系中)的投影矩阵表示为 P2 = K2 * [ R2 | t2]。我们还将分别用 D1 和 D2 表示 I1 和 I2 的镜头畸变建模系数。
由于单个数码相机同时采集了 I1 和 I2,您可以假设 K1 = K2 = K 且 D1 = D2 = D。但是,如果 I1 和 I2 是通过以下方式获取的采集之间的长时间延迟(或使用不同的变焦等),考虑到这一点会更准确涉及两个不同的相机矩阵和两组畸变系数。
解决此类问题的方法如下:
估计 P1 和 P2 的步骤如下:
估计K1、K2 和 D1、D2 通过数码相机校准
使用 D1 和 D2 进行校正图像 I1 和 I2 进行镜头畸变,然后确定校正图像中的标记位置
计算基本矩阵 F12(映射点在 I1 从相应的标记位置到 I2 中的表线)并推断基本矩阵 E12 = K2T * F12 * K1
推断来自 E12 的 R2 和 t2 以及一点对应(请参阅 此答案相关 问题)。此时,您对相机姿势有了一个仿射估计,但不是一个按比例估计,因为 t2 具有单位范数.
使用两个任意标记之间测量的距离 l0 来推断 t2 的正确范数。
为了获得最佳精度,您可以使用捆绑调整来细化 P1 和 P2,其中 K1 和 ||t<子>2||固定,基于 I1 和 I2 中相应的标记位置。
此时,您已经对相机姿势进行了准确的度量估计 P1 = K1 * [ I | 0 ] 和 P2 = K2 * [ R2 | t2]。现在,估计 Ho12 的步骤如下:
使用 D1 和 D2校正图像 I1 和 I2 的镜头畸变,然后确定校正图像中的标记位置(与上面 2. 相同,无需重新执行)并估计Hm12 从这些相应位置
通过求解以下线性方程来计算描述标记平面 pm 的 3x1 向量 v:Z * Hm12 = K<子>2 * ( R2 - t2 * vT ) * K1< support>-1(参见 HZ00第 13 章,结果 13.5 和方程 13.2(供参考),其中 Z 是比例因子。推断到原点的距离 dm = ||v||和法线 n = v / ||v||,它在 3D 中描述标记平面 pm。
由于物平面 po 与 pm 平行,因此它们具有相同的法线 n。因此,您可以从 pm 到原点 dm 的距离推断出 po 到原点 do 的距离sub> 和距测量平面的偏移 dmo,如下所示: do = dm ± dmo (符号取决于平面的相对位置:如果为正,则对于 I1,pm 比 po 更靠近相机,否则为负)。
根据 3D 中描述物平面的 n 和 do,推断出单应性 Ho12 = K2 * ( R2 - t2 * nT / do ) * K1-1(参见 HZ00 第 13 章,方程 13.2)
单应性 Ho12 将 I1 中被测物体上的点映射到 I2 中的对应点,其中两者假设 I1 和 I2 已针对镜头畸变进行校正。如果您需要将点映射到原始扭曲图像,请不要忘记使用扭曲系数 D1 和 D2 来变换输入和输出点Ho12。
我使用的参考文献:
[HZ00]“计算机视觉的多视图几何”,R.Hartley 和 A.Zisserman,2000 年。
This question is quite old, but it is interesting and it might be useful to someone.
First, here is how I understood the problem presented in the question:
You have two images I1 and I2 acquired by the same digital camera at two different positions. These images both show a set of markers which all lie in a common plane pm. There is also a measured object, whose visible surface lies in a plane po parallel to the marker's plane but with a small offset. You computed the homography Hm12 mapping the markers positions in I1 to the corresponding markers positions in I2 and you measured the offset dm-o between the planes po and pm. From that, you would like to calculate the homography Ho12 mapping points on the measured object in I1 to the corresponding points in I2.
A few remarks on this problem:
First, notice that an homography is a relation between image points, whereas the distance between the markers' plane and the object's plane is a distance in world coordinates. Using the latter to infer something about the former requires to have a metric estimation of the camera poses, i.e. you need to determine the euclidian and up-to-scale relative position & orientation of the camera for each of the two images. The euclidian requirement implies that the digital camera must be calibrated, which should not be a problem for an "optical measurement system". The up-to-scale requirement implies that the true 3D distance between two given 3D points must be known. For instance, you need to know the true distance l0 between two arbitrary markers.
Since we only need the relative pose of the camera for each image, we may choose to use a 3D coordinate system centered and aligned with the coordinate system of the camera for I1. Hence, we will denote the projection matrix for I1 by P1 = K1 * [ I | 0 ]. Then, we denote the projection matrix for I2 (in the same 3D coordinate system) by P2 = K2 * [ R2 | t2 ]. We will also denote by D1 and D2 the coefficients modeling lens distortion respectively for I1 and I2.
As a single digital camera acquired both I1 and I2, you may assume that K1 = K2 = K and D1 = D2 = D. However, if I1 and I2 were acquired with a long delay between the acquisitions (or with a different zoom, etc), it will be more accurate to consider that two different camera matrices and two sets of distortion coefficients are involved.
Here is how you could approach such a problem:
The steps in order to estimate P1 and P2 are as follows:
Estimate K1, K2 and D1, D2 via calibration of the digital camera
Use D1 and D2 to correct images I1 and I2 for lens distortion, then determine the marker positions in the corrected images
Compute the fundamental matrix F12 (mapping points in I1 to epilines in I2) from the corresponding markers positions and infer the essential matrix E12 = K2T * F12 * K1
Infer R2 and t2 from E12 and one point correspondence (see this answer to a related question). At this point, you have an affine estimation of the camera poses, but not an up-to-scale one since t2 has unit norm.
Use the measured distance l0 between two arbitrary markers to infer the correct norm for t2.
For the best accuracy, you may refine P1 and P2 using a bundle adjustment, with K1 and ||t2|| fixed, based on the corresponding marker positions in I1 and I2.
At this point, you have an accurate metric estimation of the camera poses P1 = K1 * [ I | 0 ] and P2 = K2 * [ R2 | t2 ]. Now, the steps to estimate Ho12 are as follows:
Use D1 and D2 to correct images I1 and I2 for lens distortion, then determine the marker positions in the corrected images (same as 2. above, no need to re-do that) and estimate Hm12 from these corresponding positions
Compute the 3x1 vector v describing the markers' plane pm by solving this linear equation: Z * Hm12 = K2 * ( R2 - t2 * vT ) * K1-1 (see HZ00 chapter 13, result 13.5 and equation 13.2 for a reference on that), where Z is a scaling factor. Infer the distance to origin dm = ||v|| and the normal n = v / ||v||, which describe the markers' plane pm in 3D.
Since the object plane po is parallel to pm, they have the same normal n. Hence, you can infer the distance to origin do for po from the distance to origin dm for pm and from the measured plane offset dm-o, as follows: do = dm ± dm-o (the sign depends of the relative position of the planes: positive if pm is closer to the camera for I1 than po, negative otherwise).
From n and do describing the object plane in 3D, infer the homography Ho12 = K2 * ( R2 - t2 * nT / do ) * K1-1 (see HZ00 chapter 13, equation 13.2)
The homography Ho12 maps points on the measured object in I1 to the corresponding points in I2, where both I1 and I2 are assumed to be corrected for lens distortion. If you need to map points from and to the original distorted image, don't forget to use the distortion coefficients D1 and D2 to transform the input and output points of Ho12.
The reference I used:
[HZ00] "Multiple view geometry for computer vision", by R.Hartley and A.Zisserman, 2000.