Skip to content

Instantly share code, notes, and snippets.

@ficapy ficapy/phash.py
Last active May 12, 2019

Embed
What would you like to do?
将phash得到的64位数据转换成bigint方便存储到数据库
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]))
@ZZZWY

This comment has been minimized.

Copy link

ZZZWY commented Apr 11, 2019

你好, 看到了你的bk树索引汉明距离的文章, 有些问题想问下, 方便给下联系方式么

@ficapy

This comment has been minimized.

Copy link
Owner Author

ficapy commented May 12, 2019

你好, 看到了你的bk树索引汉明距离的文章, 有些问题想问下, 方便给下联系方式么

有什么问题可以直接说, 主要就是安装一个PG索引扩展插件就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.