使用 OpenCV (Python) 拼接多个图像 [英] Stitch multiple images using OpenCV (Python)

查看:41
本文介绍了使用 OpenCV (Python) 拼接多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,看过很多教程,如何使用两张照片进行简单的图像拼接,没问题.
但是当我想从 4-6 张或更多图片中制作全景图时该怎么办?

Hi have seen a lot of tutorials how to do simple image stitching using two photos and that is no problem.
But what to do when I want to make a panorama from 4-6 images or more?

我有接收图像文件列表的代码(图像按顺序从序列中的第一个图像到最后一个图像).然后对于每个图像,我计算 SIFT 特征描述符.但是后来我被卡住了,对于两个图像,我会使用 FLANN kd-tree 设置一个匹配器并找到图像之间的匹配并计算 Homography.类似于本教程 http://docs.opencv.org/trunk/doc/py_tutorials/py_feature2d/py_feature_homography/py_feature_homography.html#py-feature-homography

I have code that takes in list of image files(the images are in order from the first image in the sequence to the last). Then for each image I compute the SIFT feature descriptors . But then I am stuck, for two images I would set up a matcher using FLANN kd-tree and find matches between the images and calculate the Homography. Similar to this tutorial http://docs.opencv.org/trunk/doc/py_tutorials/py_feature2d/py_feature_homography/py_feature_homography.html#py-feature-homography

但我没有在最后显示特征点之间的线,而是使用了这个 https://stackoverflow.com/a/20355545/622194 功能可从 2 张图像制作全景图.但是当我想将第三张和第四张图像添加到全景图时,我不确定该怎么做.

But in stead of showing the lines between feature points at the end I have used this https://stackoverflow.com/a/20355545/622194 function to make a panorama from 2 images. But I am not sure what to do when I want to add the third and the fourth image to the panorama.

从答案中,我尝试实现我的图像拼接脚本来计算图像序列中彼此相邻的图像之间的单应矩阵.所以如果我有 I1 I2 I3 和 I4 我现在有 H_12、H_23 和 H_34.然后我开始使用 H_12 缝合 I1 和 I2.然后我想找到累积单应性将 I3 拼接到当前全景图.我 fing H_13 = H_12*H_23 并将图像 3 拼接到当前全景图,但是在这里我的全景图像中有非常明显的间隙,当缝合下一张图像时,间隙更大并且图像非常拉伸.

From the answers I have tried to implement my image stitching script to calculate a homography matrix between images that are next to each other in the image sequence. So if I have I1 I2 I3 and I4 I now have H_12, H_23 and H_34. Then I start by stitching I1 and I2 using H_12. Then I want to find cumulative homography to stitch I3 to the current panorama. I fing H_13 = H_12*H_23 and stitch the image 3 to the current panorama but here I get very apparent gap in my panorama image and when next image is stitched it is even bigger gap and the images is very stretched.

谁能告诉我我是否为此使用了正确的方法,或者有人可以发现错误或查看我做错了什么.

Can anyone tell me if I am using right approach for this or can someone spot the error or see what I am doing wrong.

推荐答案

一步一步,假设你要拼接四张图片I0,I1,I2, I3, 你的目标是计算单应性 H_0, H_1, H_2, H_3;

Step by step, assuming you want to stitch four images I0, I1, I2, I3, your goal is to compute homographies H_0, H_1, H_2, H_3;

  1. 计算所有成对单应性 H_01, H_02, H_03, H_12, H_13, H_23 其中单应性 H_01 将图像 I0 扭曲成 I1 等...
  2. 选择一个锚图像,例如I1 哪个位置将保持固定,即 H_1 = Identity
  3. 根据最大数量找到与 I1 更好对齐的图像一致的匹配,例如I3
  4. 更新 H_3 = H_1 * inv(H_13) = inv(H_13) = H_31
  5. 查找与 I1I3 更好匹配的图像,例如 I2 匹配 I3
  6. 更新 H_2 = H_3 * H_23
  7. 同上图I0
  8. 进行捆绑调整以全局优化对齐
  1. Compute all pairwise homographies H_01, H_02, H_03, H_12, H_13, H_23 where homography H_01 warps image I0 into I1, etc...
  2. Select one anchor image e.g. I1 which position will remain fixed i.e H_1 = Identity
  3. Find image that better align with I1 based on maximum number of consistent matches e.g. I3
  4. Update H_3 = H_1 * inv(H_13) = inv(H_13) = H_31
  5. Find image that better matches I1 or I3 e.g I2 matching I3
  6. Update H_2 = H_3 * H_23
  7. Same as above for image I0
  8. Do bundle adjustment to globally optimize alignment

请参阅这篇开创性论文的第 4 部分 使用不变特征的自动全景图像拼接 进行深入解释.

See section 4 of this seminal paper Automatic Panoramic Image Stitching using Invariant Features for an in depth explanation.

这篇关于使用 OpenCV (Python) 拼接多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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