FlannBasedMatcher opencv的克隆方法在python中不起作用

时间:2018-12-23 15:44:23

标签: python opencv matcher

我的FlannBasedMather代码在python中无法正常工作。 它会为每次运行返回不同的匹配关键点。

我的代码:(比较两个图像的匹配点)

def count_flann_match(img_1, img_2):
    # count matched point between img1 and img2
    kp1, des1 = ALG.detectAndCompute(read(img_1), None)
    kp2, des2 = ALG.detectAndCompute(read(img_2), None)

    cv2.FlannBasedMatcher().clear()
    flann = cv2.FlannBasedMatcher()
    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)

    good = list(set(good))

    return len(good)


img_list = ["50.png", "52.png", "55.png"] #list of my img
query = "1.png" #my query image

for image in img_list:
    print (count_flann_match(query, image))
# result 
# ([['50.png', 78], ['52.png', 2], ['55.png', 2]])

for image in img_list:
    print (count_flann_match(query, image))
# result 
# ([['50.png', 78], ['55.png', 1], ['52.png', 0]])    

我猜想,当我从opencv调用对象时,可能会出错。

我尝试clear()从课堂讲解,但这是行不通的。 而且我尝试使用的Python不支持clone()方法。

flann = cv2.FlannBasedMatcher().clone(emptyTrainData=False) cv2.error: OpenCV(3.4.2) /io/opencv/modules/features2d/src/matchers.cpp:1362: error: (-213:The function/feature is not implemented) deep clone functionality is not implemented, because Flann::Index has not copy constructor or clone method in function 'clone'

所以,任何人都已经看到了这个问题以及如何在python中解决这个问题

0 个答案:

没有答案