【发布时间】:2015-10-16 08:31:43
【问题描述】:
当我运行我的 python 代码时
import numpy as np
import cv2
import matplotlib.pyplot as plt
img1 = cv2.imread('/home/shar/home.jpg',0) # queryImage
img2 = cv2.imread('/home/shar/home2.jpg',0) # trainImage
# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
# 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()
从这一行
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)
我收到此错误
TypeError: Required argument 'outImg' (pos 6) not found
我正在使用 python3 和 opencv3
【问题讨论】:
-
我想 outImg 应该是一个 numpy 数组
-
它的签名是
cv2.drawMatches(img1, keypoints1, img2, keypoints2, matches1to2[, outImg[, matchColor[, singlePointColor[, matchesMask[, flags]]]]])所以我想如果你指定flags你也需要指定所有前面的参数 -
我认为文档是错误的/具有误导性。我根据 OP 发现的问题创建了一个issue on opencv github。
-
附注 - 工厂方法
cv2.BFMatcher_create()已替换默认的cv2.BFMatcher()、according to the official documentation。