简体   繁体   English

在 python/openCV 中的图像拼接上下文中应用捆绑调整以全局校正图像

[英]Apply bundle adjustment to rectify images globally in the context of image stitching in python/openCV

I am trying to perform image registration on potentially hundreds of aerial images taken from a camera mounted on a UAV.我正在尝试对安装在无人机上的相机拍摄的数百张航拍图像进行图像配准。 I think it is safe to assume that I know the ordering of the images, and hopefully, sequential images will overlap.我认为可以安全地假设我知道图像的顺序,并且希望顺序图像会重叠。

I have read some papers that suggest using a CNN to find the homography matrix can vastly outperform the old school feature descriptor matching with RANSAC song and dance.我读过一些论文,建议使用 CNN 查找单应矩阵可以大大优于与 RANSAC 歌曲和舞蹈匹配的老式特征描述符。 My issue is that I don't quite understand how to stitch more than 2 images together.我的问题是我不太明白如何将超过 2 张图像拼接在一起。 It seems to me that to register image 100 in the same coordinate frame as image 1 using the cv2.warpPerspective function, I would do I100 H1 H2*H3...H99.在我看来,要使用 cv2.warpPerspective function 在与图像 1 相同的坐标系中注册图像 100,我会做 I100 H1 H2*H3...H99。 Even if the error in each transform is small after 100 applications it seems like it would be huge.即使每次转换的误差在 100 次应用后很小,但它似乎会很大。 My understanding is that the solution to this problem is bundle adjustment.我的理解是,解决这个问题的方法是捆绑调整。

I have looked into bundle adjustment a little bit but Im struggling to see how exactly I can use it.我对捆绑调整进行了一些研究,但我正在努力了解如何准确地使用它。 I have read the paper that many related stack overflow posts suggest "Automatic Panoramic Image Stitching using Invariant Features".我已经阅读了许多相关堆栈溢出帖子建议“使用不变特征的自动全景图像拼接”的论文。 In the section on bundle adjustment IF I understand the authors suggest that after building the initial panorama it is likely that image A will eventually overlap with multiple other images.在关于捆绑调整的部分中,如果我理解,作者建议在构建初始全景图后,图像 A 最终可能会与多个其他图像重叠。 Using the matched feature points in any images that overlap with A they basically calculate some adjustment...?在与 A 重叠的任何图像中使用匹配的特征点,他们基本上会计算一些调整......? I think to image A?我想图像A?

My question is using openCV how do I apply this adjustment?我的问题是使用 openCV 如何应用此调整? Let's say I have 3 images I1, I2, I3 all overlapping for a minimal example.假设我有 3 个图像 I1、I2、I3 全部重叠,作为一个最小示例。

#assuimg CNN model predicts transform 
#I think the first step is find the homography between all images
H12 = cnnMod.predict(I1,I2)
H13 = cnnMod.predict(I1,I3)
H23 = cnnMod.predict(I2,I3)

outI2 = cv2.warpPerspective(I2,H12,(maxWidth, maxHeight),flags=cv2.INTER_LINEAR)
outI3 = cv2.warpPerspective(I2,H23,(maxWidth, maxHeight),flags=cv2.INTER_LINEAR)

#now would I do some bundle voodoo?
#what would it look like?
#which of the bundler classes should I use?

#would it look like this?

#or maybe the input is features?
voodoo = cv2.bundleVoodoo([H12,H13,H23])

golaballyRectifiedI2 = cv2.warpPerspective(outI2,voodoo[2],(maxWidth, maxHeight),flags=cv2.INTER_LINEAR)

The code is my best guess at what a solution might look like but clearly I have no idea what I am doing.该代码是我对解决方案可能是什么样子的最佳猜测,但显然我不知道我在做什么。 I've not been able to find anything that actually shows how the bundle adjustment is done.我无法找到任何实际显示捆绑调整是如何完成的东西。

The basic idea underlying image alignment through bundle adjustment is that, rather than matching pairs of 2D points (x, x') across pairs of images, you posit the existence of 3d points X that, ideally, project onto matched tuples of 2D points (x, x', x'', ...) matched among corresponding tuples of images.通过捆绑调整作为图像 alignment 的基本思想是,您假设存在 3d 点 X,理想情况下,投影到匹配的 2D 点元组( x, x', x'', ...) 在相应的图像元组之间匹配。 You then solve for the location of the X's and the camera parameters (extrinsics, and intrinsics if the camera is uncalibrated) that minimize the (robustified, usually) RMS reprojection error over all 2d points and images.然后,您求解 X 的位置和相机参数(如果相机未校准,则为外部参数和内部参数),以最小化所有 2d 点和图像上的(通常是鲁棒的)RMS 重投影误差。

Depending on your particular setup and scene, you may make some simplifying assumptions, eg:根据您的特定设置和场景,您可能会做出一些简化假设,例如:

  • That the X's all belong to the same plane (which you can arbitrarily choose as the world's Z=0 plane). X 都属于同一个平面(可以任意选择作为世界的 Z=0 平面)。 This is useful, for example, when stitching images of a painting, or aerial images on relatively flat ground with relatively small extent so one can ignore the earth's curvature.这很有用,例如,在拼接一幅画的图像时,或者在相对平坦、范围相对较小的地面上拼接航拍图像时,可以忽略地球的曲率。
  • Or that the X's are all on the WGS84 ellipsoid.或者 X 都在 WGS84 椭球上。 Both the above assumptions remove one free coordinate from X, effectively reducing the problem's dimensionality.上述两个假设都从 X 中删除了一个自由坐标,有效地降低了问题的维数。

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

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