图像拼接Python [英] Image stitching Python

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

问题描述

我必须使用python和openCV将两个或多个图像拼接在一起。
我发现这个代码用于查找关键点和匹配,但我不知道如何继续。
请帮帮我!

  import numpy as np 
import cv2

MIN_MATCH_COUNT = 10

img1 = cv2.imread('a.jpg',0)#queryImage
img2 = cv2.imread('b.jpg',0)#trainImage

#启动SIFT检测器
sift = cv2.SIFT()

#用SIFT找到关键点和描述符
kp1,des1 = sift.detectAndCompute(img1,无)
kp2,des2 = sift.detectAndCompute(img2,无)

FLANN_INDEX_KDTREE = 0
index_params = dict(算法= FLANN_INDEX_KDTREE,树= 5)
search_params = dict(checks = 50)

flan = cv2.FlannBasedMatcher(index_params,search_params)

matches = flann.knnMatch(des1,des2,k = 2)

#按照Lowe的比率测试存储所有好的比赛。
good = []
表示m,n表示匹配:
如果m.distance< 0.7 * n.distance:
good.append(m)


解决方案

图像拼接的一种方法包括以下步骤:



首先,正如您已经想到的那样,您需要一个特征点检测器和一些找到两个图像上的特征点之间的对应关系的方法。消除大量的对应关系通常是一个好主意,因为它们可能包含很多噪音。消除大量噪音的一种非常简单的方法是在匹配中寻找对称性。



这大致是你的代码到目前为止所做的。



接下来,要将图像拼接在一起,您需要扭曲其中一个图像以匹配另一个图像的透视图。这是通过使用对应关系估计单应性来完成的。由于您的通信仍然可能包含大量噪音,我们通常会使用RANSAC来有力地估计单应性。



快速谷歌搜索提供了许多实施此示例的示例。 / p>

I have to stitch two or more images together using python and openCV. I found this code for finding keypoints and matches, but I don't know how to continue. Help me please!

import numpy as np
import cv2

MIN_MATCH_COUNT = 10

img1 = cv2.imread('a.jpg',0)          # queryImage
img2 = cv2.imread('b.jpg',0) # trainImage

# Initiate SIFT detector
sift = cv2.SIFT()

# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)

FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks = 50)

flann = cv2.FlannBasedMatcher(index_params, search_params)

matches = flann.knnMatch(des1,des2,k=2)

# store all the good matches as per Lowe's ratio test.
good = []
for m,n in matches:
    if m.distance < 0.7*n.distance:
        good.append(m)

解决方案

One approach to image stitching consists of the following steps.

Firstly, as you've already figured out, you need a feature point detector and the some way to find correspondences between feature points on both images. It's typically a good idea to eliminate a lot of correspondences because they will likely contain a lot of noise. A super simple way to eliminate a lot of noise is to look for symmetry in the matches.

This is roughly what your code does up to this point.

Next, to stitch images together, you need to warp one of the images to match the perspective of the other image. This is done by estimating the homography using the correspondences. Because your correspondences will still likely contain a lot of noise, we typically use RANSAC to robustly estimate the homography.

A quick google search provides many examples of this being implemented.

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

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