如何在python中比较两个图像以返回数值差和所用时间? 数字差应为带小数点的正或负 比较每个图像的视觉外观,而不是它们的二进制内容

如何在python中比较两个图像以返回数值差和所用时间? 数字差应为带小数点的正或负 比较每个图像的视觉外观,而不是它们的二进制内容,python,opencv,image-processing,imagemagick,image-comparison,Python,Opencv,Image Processing,Imagemagick,Image Comparison,例如: file1.png和file2.gif 差值0.23 时间流逝0.843 我试过了 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) 但是,Imag

例如:
file1.png和file2.gif
差值0.23
时间流逝0.843

我试过了


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)  

但是,
ImageChops
不适用于比较.gif和.png文件。错误是


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  


imagemagick
numpy
有效吗?必须支持.png、.gif(.jpg、.bmp是可选的)

尝试打印图像的模式

print(one.mode)
print(two.mode)

如果这两种模式如果它们彼此不相等,则可能会像您看到的那样爆炸。

您确定错误是由于不同的文件格式造成的吗?或者可能是图像大小不同或使用不同的颜色格式,或者是许多其他可能的问题之一?请尝试运行
print(one.format,one.size,one.mode)
并对第二个图像执行相同操作。尝试cv2.matchTemplate()