一对多的图像比较SURF python

时间:2018-05-01 15:04:36

标签: python opencv surf

我正在开展一个项目,我必须将图像与整个数据集进行匹配,并得出相似度得分.....一对一的图像比较工作正常,但是一对多......呃......那没发生?

def extractFeatures_SIFT():      

    a1='F:\\HandDataset\\'
    a1=[os.path.join(a1, p) for p in sorted(os.listdir(a1))]
    k = len(a1)
    print(l)
    sift1 = cv2.xfeatures2d.SIFT_create()
    kp, desc = sift1.detectAndCompute(img2, None)
    featurlist=[]
    for img_path in a1:
        img = img_path
        img = cv2.imread(img_path)
        sift = cv2.xfeatures2d.SURF_create()
        kps,descriptor = sift.detectAndCompute(img, None)
        featurlist += [kps, descriptor]
        bf = cv2.BFMatcher()
        matches1 = bf.knnMatch(desc,descriptor, k=2) 
        good = []
        for m,n in matches1:
                if m.distance < 0.7*n.distance:
                        good.append([m])
                        a=len(good)
                        print(a)
                        percent=(a*100)/kps
                        print("{} % similarity".format(percent))
                        if percent >= 75.00:
                            print('Match Found')
                            break;





    return featurlist

img3 = cv2.drawMatchesKnn(img1,kps,img2,kp,good,None,flags=2)

extractFeatures_SIFT()

0 个答案:

没有答案