python relatively simple picture

# by movie on 2019/12/18
from PIL import Image
from PIL import ImageChops

path1 = 'images/trumpA689.jpg'
path2 = 'images/trumpA748.jpg'
diff_path = 'images/diff.bmp'

imageA = Image.open('images/ImageA.bmp')
imageB = Image.open('images/ImageB.bmp')

dif = ImageChops.difference(imageB, imageA).getbbox()
print(dif)


# draw = ImageDraw.Draw(imageA)
#
# draw.rectangle(dif)
# imageA.show()

def compare(path1, path2, diffpath):
    path1 = Image.open(path1)
    path2 = Image.open(path2)
    difference = ImageChops.difference(path1, path2)
    if difference.getbbox():
        difference.save(diffpath)


compare(path1, path2, diff_path)

Note: To compare the two images to the same size

Reference:  https://www.blog.pythonlibrary.org/2016/10/11/how-to-create-a-diff-of-an-image-in-python/

Guess you like

Origin www.cnblogs.com/lijiale/p/12066948.html