def dhash(img):
"""Compute a perceptual has of an image.
Algo explained here :
https://blog.bearstech.com/2014/07/numpy-par-lexemple-une-implementation-de-dhash.html
:param img: an image
:type img: numpy.ndarray
:return: a perceptual hash of img coded on 64 bits
:rtype: int
"""
TWOS = np.array([2 ** n for n in range(7, -1, -1)])
BIGS = np.array([256 ** n for n in range(7, -1, -1)], dtype=np.uint64)
img = rgb2grey(resize(img, (9, 8)))
h = np.array([0] * 8, dtype=np.uint8)
for i in range(8):
h[i] = TWOS[img[i] > img[i + 1]].sum()
return (BIGS * h).sum()
评论列表
文章目录