Last active
May 12, 2019 13:48
-
-
Save ficapy/e7012d193c5ea85110a404c006ed7273 to your computer and use it in GitHub Desktop.
将phash得到的64位数据转换成bigint方便存储到数据库
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import imagehash | |
def get_phash(file_path): | |
img = Image.open(file_path) | |
phash = imagehash.phash(img).hash.flatten() | |
phash_list = list(map(bool, phash)) | |
if phash_list[0] is True: | |
# 取反 | |
for k, v in enumerate(phash_list): | |
if k == 0: | |
continue | |
phash_list[k] = not v | |
ret = [] | |
add = 1 | |
for i in phash_list[1:][::-1]: | |
if i + add > 1: | |
ret.append(0) | |
add = 1 | |
else: | |
ret.append(i + add) | |
add = 0 | |
return sum((2 ** k) * v for k, v in enumerate(ret)) * -1 | |
return sum((2 ** k) * v for k, v in enumerate(phash_list[::-1])) |
你好, 看到了你的bk树索引汉明距离的文章, 有些问题想问下, 方便给下联系方式么
有什么问题可以直接说, 主要就是安装一个PG索引扩展插件就可以了
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你好, 看到了你的bk树索引汉明距离的文章, 有些问题想问下, 方便给下联系方式么