Python Forum
Score of similarity using SIFT (python)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Score of similarity using SIFT (python)
#1
Hello,
I need to get the score of comparison of two images using SIFT. I found an example online and I wanted to adapt it with my needs, you'll find below the code.

import cv2
import os
import numpy as np

img1 = cv2.imread("C:/Users/Akhou/Desktop/ALTRAN Tech.jpg")
gray1= cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
img2 = cv2.imread("C:/Users/Akhou/Desktop/ALTRAN Tech.jpg")
gray2= cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)



sift1 = cv2.xfeatures2d.SIFT_create()
kp1, des1 = sift1.detectAndCompute(gray1,None)
sift2 = cv2.xfeatures2d.SIFT_create()
kp2, des2 = sift2.detectAndCompute(gray2,None)

def extractFeatures_SIFT(): 

    featurlist += [kp2, des2]
    bf = cv2.BFMatcher()
    matches1 = bf.knnMatch(des1,des2, 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)/kp2
            print("{} % similarity".format(percent))
            if percent >= 75.00:
                print('Match Found')
                break;
    return featurlist
print(featurlist)
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,None,flags=2)
if __name__ == '__main__':
    extractFeatures_SIFT()
Thank you
Reply


Messages In This Thread
Score of similarity using SIFT (python) - by Akhou - May-07-2018, 01:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Make unique id in vectorized way based on text data column with similarity scoring ill8 0 918 Dec-12-2022, 03:22 AM
Last Post: ill8
  Difference between R^2 and .score donnertrud 1 6,972 Jan-08-2020, 05:14 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020