Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differences using ImageHash Class and MySQL DB comparision #55

Open
Ahnungsloser opened this issue Apr 21, 2020 · 3 comments
Open

Differences using ImageHash Class and MySQL DB comparision #55

Ahnungsloser opened this issue Apr 21, 2020 · 3 comments

Comments

@Ahnungsloser
Copy link

Ahnungsloser commented Apr 21, 2020

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?

@gorkijatt
Copy link

gorkijatt commented Apr 28, 2020

your issue solved ? i am having same issue

@gorkijatt
Copy link

okae i fixed this issue :)

  1. create a new column in your database name it hexdec or anything you want.. set type as bigint and attributes unsigned.
  2. now convert your hash column values to hexdec using this function
<?php 
 $hash_format = "1d1f094b99d97933";
 $hexdec_format = hexdec($hash_format);
?>
  1. 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

image

@xiahe-debug
Copy link

laravel Eloquent seems to be unavailable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants