我们有一个图像数据库,我使用David Oftedal实施的Neal Krawetz 博士的方法计算了 PHASH 。
部分示例代码计算了这些 long 之间的差异:
ulong hash1 = AverageHash(theImage);
ulong hash2 = AverageHash(theOtherImage);
uint BitCount(ulong theNumber)
{
uint count = 0;
for (; theNumber > 0; theNumber >>= 8) {
count += bitCounts[(theNumber & 0xFF)];
}
return count;
}
Console.WriteLine("Similarity: " + ((64 - BitCount(hash1 ^ hash2)) * 100.0) / 64.0 + "%");
挑战在于我只知道其中一个哈希值,并且我想查询 SOLR 以按相似度顺序查找其他哈希值。
几点注意事项:
- 在这里使用 SOLR(我唯一的选择是 HBASE)
- 想要避免将任何自定义 java 安装到 solr 中(很高兴安装现有插件)
- 很高兴在 C# 中进行大量预处理
- 乐于使用多个字段将数据存储为位字符串、长等
- 使用 SOLRNet 作为客户端
编辑,一些额外的信息(抱歉我陷入了这个问题并开始假设它是一个广为人知的领域)。这里是 C# 控制台/示例应用程序的直接下载:http: //01101001.net/Imghash.zip
此控制台应用程序的示例输出为:
004143737f7f7f7f phash-test-001.jpg
0041417f7f7f7f7f phash-test-002.jpg
相似度:95.3125%