from PIL import Image im1, im2 = Image.open("1.jpg"), Image.open("2.jpg") width, height = im1.size diff = [(x, y) for x in xrange(width) for y in xrange(height) if im1.getpixel((x, y)) != im2.getpixel((x, y))] print len(diff)
### import numpy as np import cv2 global n n = 0 img1 = cv2.imread('testimg.jpg', 0) img2 = cv2.imread('testimg_diff.jpg', 0) 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 ###
-> 299
奇怪得出的值和你的不太一样,继续研究研究
doomgiant
2015-05-29 16:12:31 +08:00
重新排版
### import numpy as np import cv2 global n n = 0 img1 = cv2.imread('testimg.jpg', 0) img2 = cv2.imread('testimg_diff.jpg', 0) 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 ###