python调用opencv,使用OpenCV(Python)拼接多个图像

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?

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

But in stead of showing the lines between feature points at the end I have used this http://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.

EDIT:

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. Here is my code http://pastebin.com/dQjhE5VD

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.

解决方案

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;

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...

Select one anchor image e.g. I1 which position will remain fixed i.e H_1=Identity

Find image that better align with I1 based on maximum number of

consistent matches e.g. I3

Update H_3= H_1 * inv(H_13) = inv(H_13) = H_31

Find image that better matches I1 or I3 e.g I2 matching I3

Update H_2= H_3 * H_23

Same as above for image I0

Do bundle adjustment to globally optimize alignment

See section 4 of this seminal paper https://www.cs.bath.ac.uk/brown/papers/ijcv2007.pdf for an in depth explanation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值