我目前正试图从python中的图像中获取哈希值,我已经成功地做到了这一点,并且它在某种程度上起作用
但是,我有一个问题: Image1和image2最终拥有相同的散列,即使它们不同。我需要一种更精确的散列格式
图像1=Image1
图像2=Image2
图像的哈希为:faf076149381
我目前正在使用from PIL import Image
import imagehash
和imagehash.average_hash
代码在这里
import os
from PIL import Image
import imagehash
def checkImage():
for filename in os.listdir('images//'):
hashedImage = imagehash.average_hash(Image.open('images//' + filename))
print(filename, hashedImage)
for filename in os.listdir('checkimage//'):
check_image = imagehash.average_hash(Image.open('checkimage//' + filename))
print(filename, check_image)
if check_image == hashedImage:
print("Same image")
else:
print("Not the same image")
print(hashedImage, check_image)
checkImage()
默认情况下,^{} 检查图像文件是否几乎相同。您正在比较的文件比未比较的文件更相似。如果您想要对文件进行或多或少独特的指纹识别,可以使用不同的方法,例如采用加密哈希算法:
尝试使用hashlib。只需打开文件并执行哈希
相关问题 更多 >
编程相关推荐