May-07-2018, 01:24 PM
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.
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