我想使用gms匹配器(match.html)在帧上找到相应的点。所以我写:
import copy
import cv2
from cv2.xfeatures2d import matchGMS
def match(img1, img2):
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)
matcher = cv2.BFMatcher(cv2.NORM_HAMMING)
matches_all = matcher.match(des1, des2)
matches_gms = matchGMS(img1.shape, img2.shape, kp1, kp2, matches_all)
return matches_gms
cap = cv2.VideoCapture(path_to_video)
frame1 = None
frame2 = None
while(cap.isOpened()):
state, frame2 = cap.read()
frame2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
matches_gms = []
if frame1 is not None:
matches_gms = match(frame1, frame2)
frame1 = copy.copy(frame2)
cap.release()但是当我第二次调用match(frame1, frame2)时,我会得到一个错误'cv2.DMatch' object is not callable。我该怎么办?
发布于 2018-09-17 22:13:48
我找到了解决方案:只需重命名match函数。使用match名称,第一次迭代工作正常,但在第二次迭代中,match不是我的函数(smth重写了我的对象),match方法的调用失败了。
https://stackoverflow.com/questions/52367041
复制相似问题