【问题标题】:Image stitching Python图像拼接 Python
【发布时间】:2022-04-29 15:04:50
【问题描述】:

我必须使用 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

# 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)

【问题讨论】:

标签: python image opencv image-stitching opencv-stitching


【解决方案1】:

你的问题不是很清楚,但我假设你的意思是你有一堆图像,你想让 opencv 找到相应的地标,然后扭曲/缩放每张图片,以便它们可以形成一个大图像。

this github code中记录了一种不使用stitcher 类的方法,基本上是循环遍历图片并确定每次迭代中最合适的一个。

【讨论】:

    【解决方案2】:

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

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

    到目前为止,这大致就是您的代码所做的。

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

    快速的 google 搜索提供了许多实现这一点的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-10
      • 2011-12-26
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      • 2020-10-30
      • 2015-05-03
      • 1970-01-01
      相关资源
      最近更新 更多