Skip Menu |

This queue is for tickets about the Phash-FFI CPAN distribution.

Report information
The Basics
Id: 120345
Status: open
Priority: 0/
Queue: Phash-FFI

People
Owner: Nobody in particular
Requestors: LBE [...] cpan.org
Cc: PLICEASE [...] cpan.org
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: ph_hamming_distance returns truncated result
The result returned from the pHas ph_hamming_distance function is 64 bits in size. It appears, that what is being returned only a 32 bit result which are the two low order bytes on my Mac (little endian). I have written a test script in perl as well as modified one of the pHash example programs to provide the same output. I have tested this both on Debian Jessie and on my Mac. <code> Test </code>
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
Subject: phash-ffi-hd-test.pl
#!/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
Subject: phash-hd-test.cpp
Download phash-hd-test.cpp
application/octet-stream 3.8k

Message body not shown because it is not plain text.

On Sat Feb 25 00:15:56 2017, PLICEASE wrote: Show quoted text
Following the advice of PLICEASE, the following modification fixes the problem: diff FFI.pm FFI.pm.orig 13c13 < $ffi->attach([ ph_hamming_distance => 'ph_hamming_distance' ] => [ 'uint64', 'uint64' ] => 'int'); --- Show quoted text
> $ffi->attach([ ph_hamming_distance => 'ph_hamming_distance' ] => [ 'int', 'int' ] => 'int');
This was tested successfully on 64-bit Debian Jessie - pHash was built from source (http://phash.org/downloads - version 0.9.6) - cimg-dev 1.5.9+dfsg-1 installed via apt This failed on MacOS Sierra where - pHash was built from source (http://phash.org/downloads - version 0.9.6) - cimg 1.6.9 was installed using Homebrew The error message received there was: [CImg] *** CImgIOException *** [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to open file 'test1.jpg'. I will conduct further tests on MacOS. I believe the error is due the way the Cimg package is built in Homebrew.
On Sun Feb 26 13:19:09 2017, LBE wrote: Show quoted text
> On Sat Feb 25 00:15:56 2017, PLICEASE wrote: > > Following the advice of PLICEASE, the following modification fixes the > problem: > > diff FFI.pm FFI.pm.orig > 13c13 > < $ffi->attach([ ph_hamming_distance => 'ph_hamming_distance' ] => [ > 'uint64', 'uint64' ] => 'int'); > ---
> > $ffi->attach([ ph_hamming_distance => 'ph_hamming_distance' ] => [ > > 'int', 'int' ] => 'int');
> > This was tested successfully on 64-bit Debian Jessie > - pHash was built from source (http://phash.org/downloads - version > 0.9.6) > - cimg-dev 1.5.9+dfsg-1 installed via apt > > This failed on MacOS Sierra where > - pHash was built from source (http://phash.org/downloads - version > 0.9.6) > - cimg 1.6.9 was installed using Homebrew > The error message received there was: [CImg] *** CImgIOException *** > [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed > to open file 'test1.jpg'. > > I will conduct further tests on MacOS. I believe the error is due the > way the Cimg package is built in Homebrew.
This is actually working on MacOS now. My previous test failure was user error.