python - 如何在 MySQL 8 中保存 phash 并计算汉明距离?
问题描述
与给定的 phash 相比,我试图在 MySQL 8.0 表中找到类似的图像。
阶段是通过 python 生成的,当前存储在 varchar(255) 字段中。通常它们看起来像这样:ae95916ec1354a9d
我的查询应该以字节为单位返回差异:
SELECT m.*,
BIT_COUNT( 0xae95916ec1354a9d ^ m.HASH) as hd,
BIT_COUNT( 0xae95916ec1354a9d ^ concat('0x', m.HASH)) as hd,
concat('0x', m.HASH)
from
media m
where m.HASH is not null
ORDER BY hd ASC;
不幸的是,这不起作用,我怀疑这是因为哈希前面缺少 0x。
哈希在 Python 中是这样生成的:
response2 = requests.get(url, stream=True)
if response2:
response2.raw.decode_content = True
image2 = Image.open(response2.raw)
hash2 = str(imagehash.phash(image2))
我是否将哈希保存在错误的数据类型字段中,或者这种方法有什么问题?
解决方案
推荐阅读
- html - 当您将鼠标悬停在列表本身上时,有没有办法让我显示这个下拉列表?
- c# - C# 扩展失败
- node.js - ENOENT:没有这样的文件或目录,stat '/app/client/build'"
- google-apps-script - 为什么我通过应用程序脚本创建的 PDF 文件全部损坏?
- flutter - 如何在加载值之前显示循环进度指示器?
- c++ - 为什么标准不提供通过内容检查散列 c 字符串的专业化
- aem - 服务用户重复的 AEM 工作流注释
- r - R:让 dplyr 和摘要显示超过 3 位数字
- sql-server - 如果一个查询具有较低的逻辑读取但另一个查询具有较低的相对查询成本,则哪个查询执行得更好?
- php - 当我使用 For 循环时,键通过下一步。而foreach数据没有改变data.PHP