赞
踩
简单介绍两种方法
一、
import numpy as np
import cv2
global n
zong=0
n = 0
img1 = cv2.imread('1.png', cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread('22.png', cv2.IMREAD_GRAYSCALE)
height, width = img1.shape
for line in range(height):
for pixel in range(width):
if img1[line][pixel] != img2[line][pixel]:
n = n + 1
print (n)
二、
import cv2
import numpy as np
image1 = cv2.imread("1.png")
image2 = cv2.imread("22.png")
difference = cv2.subtract(image1, image2)
result = not np.any(difference) #if difference is all zeros it will return False
if result is True:
print("两张图片一样")
else:
cv2.imwrite("result.jpg", difference)
print ("两张图片不一样")
注意:两种方法皆为python3写法。而且所比较的两张图片必须大小相同,不然会报错
最后,生活那么苦,来看看沙雕视频欢乐下吧!
自家亲视频号,卑微在线求关注
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。