匹配器GMS opencv

时间:2018-09-17 11:47:45

标签: python-3.x opencv

我想使用gms匹配器(https://docs.opencv.org/3.4.2/db/dd9/group__xfeatures2d__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。我该怎么办?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:只需重命名match函数。 使用match的名称时,第一次迭代可以正常工作,但是在第二次迭代时,match不是我的函数(可能重写了我的对象),并且match方法的调用失败。