你如何在python的Open CV中使用Akaze

时间:2016-04-22 14:07:23

标签: python opencv

我在c ++中找到了例子: http://docs.opencv.org/3.0-beta/doc/tutorials/features2d/akaze_matching/akaze_matching.html

但是在python中没有任何示例显示如何使用此功能检测器(也无法在有关AKAZE的文档中找到更多信息,有ORB SIFT,SURF等,但不是我和#39;我正在寻找) http://docs.opencv.org/3.1.0/db/d27/tutorial_py_table_of_contents_feature2d.html#gsc.tab=0

有人可以分享或告诉我在哪里可以找到如何将python中的图像与akaze匹配的信息吗?

2 个答案:

答案 0 :(得分:14)

我不知道在哪里可以找到它,我的工作方式是通过这个使用Brute Force匹配器的功能:

def kaze_match(im1_path, im2_path):
    # load the image and convert it to grayscale
    im1 = cv2.imread(im1_path)
    im2 = cv2.imread(im2_path)
    gray1 = cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY)
    gray2 = cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY)    

    # initialize the AKAZE descriptor, then detect keypoints and extract
    # local invariant descriptors from the image
    detector = cv2.AKAZE_create()
    (kps1, descs1) = detector.detectAndCompute(gray1, None)
    (kps2, descs2) = detector.detectAndCompute(gray2, None)

    print("keypoints: {}, descriptors: {}".format(len(kps1), descs1.shape))
    print("keypoints: {}, descriptors: {}".format(len(kps2), descs2.shape))    

    # Match the features
    bf = cv2.BFMatcher(cv2.NORM_HAMMING)
    matches = bf.knnMatch(descs1,descs2, k=2)    # typo fixed

    # Apply ratio test
    good = []
    for m,n in matches:
        if m.distance < 0.9*n.distance:
            good.append([m])

    # cv2.drawMatchesKnn expects list of lists as matches.
    im3 = cv2.drawMatchesKnn(im1, kps1, im2, kps2, good[1:20], None, flags=2)
    cv2.imshow("AKAZE matching", im3)
    cv2.waitKey(0) 

请记住,特征向量是二元向量。因此,相似性是基于汉明距离,而不是常用的L2范数或欧几里德距离。

答案 1 :(得分:1)

我搜索了同一教程,发现该教程以3种替代语言C ++,Python和Java给出。在代码区域开始之前,有3个超链接。

试试这个[https://docs.opencv.org/3.4/db/d70/tutorial_akaze_matching.html]