赞
踩
from skimage.measure import compare_ssim import cv2
class CompareImage(): def compare_image(self, path_image1, path_image2): print() TT = cv2.imread(path_image2, 0) (W, H) = TT.shape imageA = cv2.imread(path_image1) imageB = cv2.imread(path_image2) # 重置图片大小,下面的compare_ssim 是指接受大小相同的图表对比 imageA1 = cv2.resize(imageA, (W, H)) # 图片灰度处理 grayA = cv2.cvtColor(imageA1, cv2.COLOR_BGR2GRAY) grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY) (score, diff) = compare_ssim(grayA, grayB, full=True) print("SSIM: {} {}".format(score, type(diff))) return score
compare_image = CompareImage() # 图表路径为英文绝对路径 compare_image.compare_image(r"D:/1.png", r"D:/1_2.png")
result:
SSIM: 0.9612563765412815 <class 'numpy.ndarray'>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。