Python calculates image hash and caches images as key

Python, sometimes I want to cache images as keys, what should I do? Caching the entire breakthrough takes up too much memory, so you might as well cache the hash value:

Fast way to Hash Numpy objects for Caching

import hashlib
import numpy
a = numpy.random.rand(10, 100)
b = a.view(numpy.uint8)
hashlib.sha1(b).hexdigest()
'15c61fba5c969e5ed12cee619551881be908f11b'

Hash does not add too much program burden. The author used a picture with a pixel size of about 500*500 for testing. The calculation of the hash value took 0.01 seconds.

Guess you like

Origin blog.csdn.net/duoyasong5907/article/details/132105198