defsimilarity(im1,im2):img1=cv2.imread(im1,0)img2=cv2.imread(im2,0)# Initiate SIFT detectororb=cv2.ORB()# find the keypoints and descriptors with SIFTkp1,des1=orb.detectAndCompute(img1,None)kp2,des2=orb.detectAndCompute(img2,None)bf=cv2.BFMatcher(cv2.NORM_HAMMING,crossCheck=True)matches=bf.match(des1,des2)ifuse_mean:iflen(matches)is0:return100lis=[m.distanceforminmatches]returnnp.mean(lis)else:iflen(matches)is0:return0matches=sorted(matches,key=lambdax:x.distance)good_matches=[mforminmatchesifm.distance<0.75]similarity_score=len(good_matches)/len(matches)returnsimilarity_score