【发布时间】:2018-09-22 21:20:37
【问题描述】:
我想在 Python 中使用 opencv 执行蛮力 SIFT 特征匹配。
我在 opencv 文档中找到了以下代码。
import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('box.png',0) # queryImage
img2 = cv2.imread('box_in_scene.png',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)
# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)
# Apply ratio test
good = []
for m,n in matches:
if m.distance < 0.75*n.distance:
good.append([m])
# cv2.drawMatchesKnn expects list of lists as matches.
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)
plt.imshow(img3),plt.show()
但是,此代码仅适用于两个图像。我尝试提供描述符列表,但它似乎不起作用。如何一次匹配多个数据库图像?
【问题讨论】:
标签: python opencv image-processing