One of the cheapest KYC fraud patterns is reusing one ID document across many accounts : the same photo, resized, recompressed or brightened a little so the file is different each time. A file hash such as SHA-256 misses all of these, because one changed byte changes the whole hash. A perceptual hash describes what the image looks like, so near-identical images get near-identical hashes. dHash is one of the simplest: shrink the image to 9×8 greyscale and record, for each pixel, whether it's brighter than its right neighbour, giving 64 bits. Two images are near-duplicates when their hashes differ in only a few bits. The catch for ID documents: every card of the same type shares a layout, so hash the portrait, not the whole card . Tested Python below.
How does dHash work?
dHash records gradients , not brightness. Shrinking to 9×8 throws away detail, compression noise and size; comparing neighbours makes it insensitive to overall brightness.…