The following is the output of the perl test script:
Distance = 4 <- from pHash
Distance = 20 <- from PP
[ ][ ][ ][ ][ ][ ][ ][ ] Hash in Hex Filename
0110011001111110011010101100001000000110001100101001111010111100 667e6ac206329ebc 24299403.jpg
1001001101000111000110101000101100010110011101101001111000111100 93471a8b16769e3c 26468566.jpg
^^^^ ^ ^ ^^^ ^ ^^^ ^ ^ ^ ^ ^ ^ ^
The following is the output of the C++ test program
Distance = 20 <- from pHash
[ ][ ][ ][ ][ ][ ][ ][ ] Hash in Hex File Name
0110011001111110011010101100001000000110001100101001111010111100 667e6ac206329ebc 24299403.jpg
1001001101000111000110101000101100010110011101101001111000111100 93471a8b16769e3c 26468566.jpg
^^^^ ^ ^ ^^^ ^ ^^^ ^ ^ ^ ^ ^ ^ ^
Please note that the hamming distance using Phash::FFI::ph_hamming_distance is 4 when it should be 20. The actual hashes returned from Phash::FFI::dct_imagehash match exactly that from the C++ program. The perl program also has a perl perl subroutine to calculate the hamming distance (Thanks to Ken -
http://www.perlmonks.org/?node_id=1048973)
I also modified the return type to uint64 on the attach call in Phase::FFI.pm to attempt to coerce a different treatmet by perl; however, I received exactly the same results.
I really wonder if the problem is actually in FFI::Platypus upon which Phash::FFI depends. I will open a ticket there and link to this ticket.
Thanks
lbe
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use File::Basename;
use Phash::FFI;
main: {
my ( $fn1, $fn2 ) = @ARGV;
$" = "\n";
my $hash1 = calc_hash($fn1);
my $hash2 = calc_hash($fn2);
my $hd = hd( $hash1, $hash2 );
printf "Distance = %d <- from pHash\n", $hd;
printf "Distance = %d <- from PP\n", hdpp( $hash1, $hash2, 64 );
my $s;
for ( 1 .. 8 ) {
$s .= "[ ]";
}
printf "%s %-16s %s\n", $s, "Hash in Hex", "Filename";
my $a = sprintf "%064b", $hash1;
my $b = sprintf "%064b", $hash2;
printf "%s %x %s\n", $a, $hash1, basename($fn1);
printf "%s %x %s\n", $b, $hash2, basename($fn2);
my $d = 0;
$s = undef;
for ( 0 .. 63 ) {
my $na = substr( $a, $_, 1 );
my $nb = substr( $b, $_, 1 );
my $diff = $na eq $nb ? 0 : 1;
$d += $diff;
$s .= $diff ? "^" : ' ';
}
print "$s\n";
} ## ---------- end main:
sub calc_hash {
my ($fn) = @_;
my $hash = Phash::FFI::dct_imagehash($fn);
return ($hash);
} ## ---------- end sub calc_hash
sub hd {
my ( $hash1, $hash2 ) = @_;
my $hd = Phash::FFI::ph_hamming_distance( $hash1, $hash2 );
return ($hd);
} ## ---------- end sub hd
sub hdpp {
my ( $diff, $bits, $count, $mask ) = ( $_[0] ^ $_[1], $_[2] || 8, 0 );
$mask = 1 << $_, $diff & $mask && ++$count for 0 .. $bits - 1;
$count;
} ## ---------- end sub hdpp
Message body not shown because it is not plain text.