import cv2.cv as cv
import cv2
import numpy as np
def compareHist( stdimg, ocimg):
stdimg = cv2.imread(str(stdimg), 0)
ocimg = cv2.imread(str(ocimg), 0)
stdimg = np.float32(stdimg)
ocimg = np.float32(ocimg)
stdimg = np.ndarray.flatten(stdimg)
ocimg = np.ndarray.flatten(ocimg)
imgocr = np.corrcoef(stdimg, ocimg)
print imgocr[0, 1]
return imgocr[0, 1] > 0.96
if __name__ =='__main__':
stding = 'C:/Users/503061752/Desktop/OCImg.png'
ocimg ='C:/Users/503061752/Desktop/BJAutoT520/images/Attention.png'
compareHist(stding,ocimg)
以上代码实现的功能是先读取两张图片,然后比较两张图片的相似程度,当两张图片相似度为0 时,运行到imgocr行时 imgocr 为nan 会报错
numpy\lib\function_base.py:3183: RuntimeWarning: invalid value encountered in true_divide