所谓感知哈希算法 它不是很严格的哈希算法
而是相对的hash
本篇介绍的感知哈希算法为:dhash
dHash:差异值哈希,基于渐变的hash算法,精确度较高,且速度也比较快(本文没有转换,见代码注释)
注:用到了PIL库
以及汉明距离(传送门)
正文来了
先贴代码
# -*- coding:utf-8 -*-
"""
用dhash判断是否相同照片
基于渐变比较的hash
hash可以省略(本文省略)
By Guanpx
"""
from PIL import Image
from os import listdir
def picPostfix(): # 相册后缀的集合
postFix = set()
postFix.update(['bmp', 'jpg', 'png', 'tiff', 'gif', 'pcx', 'tga', 'exif',
'fpx', 'svg', 'psd', 'cdr', 'pcd', 'dxf', 'ufo', 'eps',