python 简单的图片比较
Posted java渣渣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 简单的图片比较相关的知识,希望对你有一定的参考价值。
# 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)
注意:要比较的两张图片大小要一样
参考: https://www.blog.pythonlibrary.org/2016/10/11/how-to-create-a-diff-of-an-image-in-python/
以上是关于python 简单的图片比较的主要内容,如果未能解决你的问题,请参考以下文章
python 用于在终端中运行的sublime text 3的简单代码片段制作工具