def check_hash_stored(self, func, image, binbits=range(2, 5)): for bit in binbits: image_hash = func(image, bit) other_hash = imagehash.hex_to_flathash(str(image_hash), bit * (2 + 6 * 2)) emsg = 'stringified hash {} != original hash {}'.format( other_hash, image_hash) self.assertEqual(image_hash, other_hash, emsg) distance = image_hash - other_hash emsg = ('unexpected hamming distance {}: original hash {} ' '- stringified hash {}'.format(distance, image_hash, other_hash)) self.assertEqual(distance, 0, emsg)
def detect_default_profile_pic(flathash): if flathash - imagehash.hex_to_flathash("000018183c3c0000", 8) < 10 : return True return False
def from_hex(hash_function, hex, card_id): return HashResult(hash_function, imagehash.hex_to_flathash(hex, hash_function.hash_size), card_id)