一、背景
在做安卓端的自动化测试,使用opencv图片对比。
上网找资源
https://www.cnblogs.com/webRobot/p/6216994.html
明明一样的图片还能不一样?我很懵。。。
import cv2
import numpy as np
file1 = 'update_before.png'
file2 = 'update_after.png'
im1 = cv2.imread(file1)
im2 = cv2.imread(file2)
# print(im1)
# print('这里是分割')
# print(im2)
if im1.shape == im2.shape:
print('shape一样')
else:
print('shape not equal')
difference = cv2.subtract(im1,im2)
print(difference)
result = not np.any(difference)
if result is False:
print('一样')
else:
cv2.imwrite('reslult.jpg',difference)
print('不一样')
为了验证,把图片数组打印出来,一模一样。
后来发现是参考的博文错了。
后面自己找了英文的解释来看: