一对多图像比较SURF python

2022-01-19 00:36:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做一个项目,我必须把一个图像和一个完整的数据集进行匹配,然后得出一个相似性分数……一对一的图像比较很好,但是一对多的比较……呃……这不会发生吗?你知道吗

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()