我需要计算两个图像之间相似性的百分比,我发现在线进行计算的部分,我想在我的情况下调整它,但在测试代码时我遇到了一个问题,我不知道如何修复。 你会在我的代码下面找到:
import cv2
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)
featurlist=[]
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;
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,None,flags=2)
这是我遇到的错误:
percent=(a*100)/kp2
TypeError: unsupported operand type(s) for /: 'int' and 'list'
感谢您的时间和帮助。