2016-04-22 182 views
3

我發現在C++例子中使用Akaze開放CV: http://docs.opencv.org/3.0-beta/doc/tutorials/features2d/akaze_matching/akaze_matching.html你如何蟒蛇

但沒有在Python展示瞭如何使用此功能檢測任何實例(也無法找到任何更約aKAZE文檔有ORB SIFT,SURF等,但不是我要找的) http://docs.opencv.org/3.1.0/db/d27/tutorial_py_table_of_contents_feature2d.html#gsc.tab=0

能有人可以共享或告訴我在哪裏可以找到信息如何與akaze匹配蟒蛇圖片?

回答

7

我不知道在哪裏可以找到它,我把它工作的方式是通過這個功能,使用蠻力匹配:

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範數或歐幾里得距離。

+0

它的工作原理感謝 – JeremyK

+0

比率測試是否正確?它給我關鍵點數字而不是比例。 – JeremyK