JohannesBuchner / imagehash

A Python Perceptual Image Hashing Module
BSD 2-Clause "Simplified" License
3.28k stars 331 forks source link

AttributeError: 'str' object has no attribute 'size' #162

Closed fayyazraja closed 2 years ago

fayyazraja commented 2 years ago

I am comparing the hash of the source image with the hashes stored in the DB (as strings). I have converted them to "ImageHash" type but am still getting the error "AttributeError: 'str' object has no attribute 'size'".

image ='img1.jpg'
img = Image.open(img)
src_whash = imagehash.whash(img)

def get_similarity_whash(hash1):
      hash1=imagehash.ImageHash(hash1)`
      return hash1-src_whash

whash_sim=list(map(get_similarity_whash, whashes)) # getting the error here

The type of src_whash variable is "imagehash.ImageHash" when checked with type(src_whash) and the type of "hash1" used in the function is also "imagehash.ImageHash". Can anyone please tell me what I am doing wrong when comparing a string-based hash with the freshly computed one? Thanks!

JohannesBuchner commented 2 years ago

This is now documented here: https://github.com/JohannesBuchner/imagehash#storing-hashes