python - How do you compare two images in python to return a numerical difference and time elapsed?
问题描述
- numerical difference is expected as positive or negative with decimal places
- compare the visual appearance of each image, not their binary contents
for example:
file1.png & file2.gif
diff 0.23
time elapsed 0.843
I have tried
from PIL import Image
from PIL import ImageChops
...
one = Image.open("file1.png")
two = Image.open("file2.gif")
diff = ImageChops.difference(one, two)
print(diff)
But ImageChops
does not work for comparing .gif and .png files. Error is
python3.8/site-packages/PIL/ImageChops.py", line 102, in difference
return image1._new(image1.im.chop_difference(image2.im))
ValueError: images do not match
Will imagemagick
or numpy
work? has to support .png, .gif (.jpg, .bmp are optional)
解决方案
尝试打印图像的模式。
print(one.mode)
print(two.mode)
如果这两种模式 != 不相等,那么它可能会像您所看到的那样爆炸。
推荐阅读
- c# - ONSException 异常 - 未配置节点
- mysql - 使用 Express.js api 和 mysql 包将数组发布到 MySQL Workbench
- android - 尽管我将 api 密钥限制为 android 特定应用程序,但仍收到暴露的 GCP API 密钥警告
- php - 是否可以在不创建相册的情况下获取谷歌相册共享网址?
- javascript - 自适应卡在提交时清除输入
- linux - Docker容器内存上限
- ios - Swift Time 总是比实际时间晚 3 小时
- android - 无法从 RxJava2 链触发 Android Activity [Android][RxJava]
- angular - 具有拖放功能的角垫树
- python - Django过滤通用表单通过用户名从基于通用类的视图中选择属性或预填充并隐藏表单选择属性