imagehash
imagehash copied to clipboard
Differences using ImageHash Class and MySQL DB comparision
I've got three test images .. ImageHash gives following hashes ..
Image 1: 0405794952704d4a Image 2: 0405714972704d48 Image 3: 0445714972704d4a
Distances in ImageHash are always 3 using example:
use Jenssegers\ImageHash\ImageHash; use Jenssegers\ImageHash\Implementations\DifferenceHash ;
$hasher = new ImageHash(new DifferenceHash()); $distance = $hasher->distance($hash1, $hash2); // = 3 $distance = $hasher->distance($hash1, $hash3); // = 3
If the hashes are inserted into MySQL DB in column "hash" ( data type varchar() ) ...
SELECT images.*, BIT_COUNT('0405794952704d4a' ^ hash) as hamming_distance FROM images HAVING hamming_distance < 50
Distances are as followed ..
Image 1: 0405794952704d4a -> 0 Image 2: 0405714972704d48 -> 12 Image 3: 0445714972704d4a -> 21
I am expecting hamming distance of 3 like using the ImageHash DifferenceHash() Class. Where is my fault?
your issue solved ? i am having same issue
okae i fixed this issue :)
- create a new column in your database name it
hexdec
or anything you want.. set type as bigint and attributes unsigned. - now convert your hash column values to
hexdec
using this function
<?php
$hash_format = "1d1f094b99d97933";
$hexdec_format = hexdec($hash_format);
?>
- after updating hexdec column you can run this query
SELECT images.*, BIT_COUNT(2098406171686304051^ hexdec) as hamming_distance FROM images HAVING hamming_distance < 30 ORDER BY hamming_distance ASC LIMIT 10
laravel Eloquent seems to be unavailable