快速有效的方法来检测两个图像在Python中在视觉上是否相同 [英] Fast and efficient way to detect if two images are visually identical in Python

查看:51
本文介绍了快速有效的方法来检测两个图像在Python中在视觉上是否相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出两个图像:

image1.jpg
image2.jpg

检测它们在Python上视觉上是否相同的快速方法是什么?例如,它们可能具有不同的EXIF数据,即使图像数据相同,它们也会产生不同的校验和.

What's a fast way to detect if they are visually identical in Python? For example, they may have different EXIF data which would yield different checksums, even though the image data is the same).

Imagemagick具有出色的识别"工具,可以生成图像的视觉哈希值,但是它非常占用处理器资源.

Imagemagick has an excellent tool, "identify," that produces a visual hash of an image, but it's very processor intensive.

推荐答案

使用PIL/枕头:

from PIL import Image

im1 = Image.open('image1.jpg')
im2 = Image.open('image2.jpg')

if list(im1.getdata()) == list(im2.getdata()):
    print "Identical"
else:
    print "Different"

这篇关于快速有效的方法来检测两个图像在Python中在视觉上是否相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆