我正在尝试计算图像的哈希值。 我在相同尺寸的图像上使用dhash,但得到的哈希长度不同(即使使用填充)
为什么呢
def dhash(image, hash_size=16):
image = image.convert("L").resize((hash_size + 1, hash_size),
Image.ANTIALIAS)
pixels = np.asarray(image)
diff = pixels[:, 1:] > pixels[:, :-1]
bit_string = ''.join(str(b) for b in 1 * diff.flatten())
return int(bit_string, 2)
image1.size (1280, 800) image2.size (1280, 800) hash1 = dhash(image1) hash2 = dhash(image2) bin(hash1 ).zfill(64) '0b1001101000000000100110100000000000010000000000000010101100000000001011111000000011011011100000001001111110000000100101111000000111011011100000011001101110000000100110111000000010011011100000001101100110000000100110111100100010011011010' bin(hash2 ).zfill(64) '0b101101000000000010110100000000001011011100000000101101000111000110110100101100001011011001110001101101000111000110110100101100011011011111001000001101001011010110110100101101001011011101001000101101000111000010110100000000001011010000000000101101000000000'
目前没有回答
相关问题 更多 >
编程相关推荐