Giter VIP home page Giter VIP logo

py-phash's Introduction

py-pHash

Python bindings for libpHash (http://phash.org/)

A perceptual hash is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions which rely on the avalanche effect of small changes in input leading to drastic changes in the output, perceptual hashes are "close" to one another if the features are similar.

Installation

python setup.py install

(for python 3 checkout python3 branch)

You may wish to install imagemagick or graphicsmagick for additional file format support.

Usage

DCT hash

int phash_imagehash( str file ) int phash_distance( int hash1, int hash2 )

Radial hash

pHash.Digest phash_image_digest( str file, float sigma, float gamma, int angles=180 ) int phash_crosscorr( phash.Digest digest1, phash.Digest digest2 )

Mexican hat wavelet

list pHash.mh_imagehash( str file ) float pHash.hamming_distance2( list byteList1, list byteList2 )

Peak of Cross Correlation

float pHash.compare_images( str file1, str file2 )

import pHash
hash1 = pHash.imagehash( 'file.1.jpg' )
hash2 = pHash.imagehash( 'file.2.jpg' )
print 'Hamming distance: %d (%08x / %08x)' % ( pHash.hamming_distance( hash1, hash2 ), hash1, hash2 )

digest1 = pHash.image_digest( 'file.1.jpg', 1.0, 1.0, 180 )
digest2 = pHash.image_digest( 'file.2.jpg', 1.0, 1.0, 180 )
print 'Cross-correelation: %d' % ( pHash.crosscorr( digest1, digest2 ) )

Todo

  • Return peak cross-correlation for radial hashing
  • Add audio and video support
  • Beautify the code, add comments
  • Unify with python 3 branch

py-phash's People

Contributors

bradjasper avatar fakechris avatar lifthrasiir avatar polachok avatar romulooliveira avatar soulseekah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py-phash's Issues

Build error on OS X Lion

Hello, I'm getting the following build error on OS X Lion 10.7.4, Python 2.7.1. Any ideas?

$ python setup.py install
running install
running build
running build_ext
building 'pHash' extension
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict
-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototyp
es -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -ar
ch i386 -arch x86_64 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/inclu
de/python2.7 -c phashmodule.C -o build/temp.macosx-10.7-intel-2.7/phashmodule.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not
for C++
phashmodule.C:40: warning: deprecated conversion from string constant to 'char_'
phashmodule.C:40: warning: deprecated conversion from string constant to 'char_'
phashmodule.C:40: warning: deprecated conversion from string constant to 'char_'
phashmodule.C:40: warning: deprecated conversion from string constant to 'char_'
phashmodule.C:40: warning: deprecated conversion from string constant to 'char_'
phashmodule.C:40: warning: deprecated conversion from string constant to 'char_'
phashmodule.C: In function 'void initpHash()':
phashmodule.C:51: warning: deprecated conversion from string constant to 'char_'
phashmodule.C:58: error: expected primary-expression before '{' token
phashmodule.C:58: error: expected ;' before '{' token phashmodule.C:45: warning: unused variable 'coeffs' phashmodule.C: In function 'PyObject_ phash_image_digest(PyObject_, PyObject_)': phashmodule.C:86: warning: unused variable 'coeff' /usr/local/include/pHash.h: At global scope: /usr/local/include/pHash.h:326: warning: 'cimg_library::CImg<float>\* ph_dct_matrix(int)' de clared 'static' but never defined /usr/local/include/pHash.h:341: warning: 'cimg_library::CImgList<unsigned char>\* ph_getKeyF ramesFromVideo(const char_)' declared 'static' but never defined /usr/local/include/pHash.h:452: warning: 'MVPRetCode _ph_query_mvptree(MVPFile_, DP_, int, float, float, DP__, int&, int)' declared 'static' but never defined /usr/local/include/pHash.h:473: warning: 'MVPRetCode _ph_save_mvptree(MVPFile_, DP**, int, int, int, FileIndex_)' declared 'static' but never defined /usr/local/include/pHash.h:490: warning: 'MVPRetCode _ph_add_mvptree(MVPFile_, DP_, int)' d eclared 'static' but never defined cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ phashmodule.C:40: warning: deprecated conversion from string constant to 'char_' phashmodule.C:40: warning: deprecated conversion from string constant to 'char_' phashmodule.C:40: warning: deprecated conversion from string constant to 'char_' phashmodule.C:40: warning: deprecated conversion from string constant to 'char_' phashmodule.C:40: warning: deprecated conversion from string constant to 'char_' phashmodule.C:40: warning: deprecated conversion from string constant to 'char_' phashmodule.C: In function 'void initpHash()': phashmodule.C:51: warning: deprecated conversion from string constant to 'char_' phashmodule.C:58: error: expected primary-expression before '{' token phashmodule.C:58: error: expected ;' before '{' token
phashmodule.C:45: warning: unused variable 'coeffs'
phashmodule.C: In function 'PyObject* phash_image_digest(PyObject_, PyObject_)':
phashmodule.C:86: warning: unused variable 'coeff'
/usr/local/include/pHash.h: At global scope:
/usr/local/include/pHash.h:326: warning: 'cimg_library::CImg* ph_dct_matrix(int)' de
clared 'static' but never defined
/usr/local/include/pHash.h:341: warning: 'cimg_library::CImgList* ph_getKeyF
ramesFromVideo(const char_)' declared 'static' but never defined
/usr/local/include/pHash.h:452: warning: 'MVPRetCode ph_query_mvptree(MVPFile, DP*, int,
float, float, DP**, int&, int)' declared 'static' but never defined
/usr/local/include/pHash.h:473: warning: 'MVPRetCode ph_save_mvptree(MVPFile, DP__, int,
int, int, FileIndex_)' declared 'static' but never defined
/usr/local/include/pHash.h:490: warning: 'MVPRetCode ph_add_mvptree(MVPFile, DP_, int)' d
eclared 'static' but never defined
lipo: can't open input file: /var/folders/gx/2c9g2zn92v5_vqxkqf0np7fr0000gn/T//ccgL1lfm.out
(No such file or directory)
error: command 'llvm-gcc-4.2' failed with exit status 1

ImageMagick / GraphicsMagick dependency

I was happy to find Python bindings for phash and wanted to give it a try. I managed to install pHash on MacOS X Snow Leopard using Homebrew and then installed the Python module successfully.

It seems as if the hashing functions work with 8bit RGB JPEGs, but not with 16bit RGB TIFFs.

sh: convert: command not found
sh: gm: command not found
sh: convert: command not found
sh: gm: command not found
sh: convert: command not found
sh: gm: command not found

[CImg] *** CImgIOException *** [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'example1.tif'.
Traceback (most recent call last):
  File "phash_test.py", line 7, in <module>
    print pHash.imagehash(path)
pHash.error: The DCT robust image hash has failed.

This seems to tell that pHash tries to convert my image using either convert (from ImageMagick) or gm from Graphicsmagick.

It would be cool if you could mention this in the README.

For OS X users, this is easy to fix doing e.g.

sudo brew install graphicsmagick

phashmodule.C:3:19: fatal error: pHash.h: No such file or directory

Trying to run setup.py I get:

~/phash ❯❯❯ python setup.py install                                                  ⏎ python3
running install
running build
running build_ext
building 'pHash' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-    protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -        I/usr/include/python3.4m -I/home/david/.virtualenvs/stocksearch/include/python3.4m -c phashmodule.C -    o build/temp.linux-x86_64-3.4/phashmodule.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
phashmodule.C:3:19: fatal error: pHash.h: No such file or directory
 #include <pHash.h>
                   ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

any idea whats going on?

ImportError: libpHash.so.0

Running python setup.py install runs fine, but when I open up python and try import pHash I get the following error:

Traceback (most recent call last):
File "", line 1, in
ImportError: libpHash.so.0: cannot open shared object file: No such file or directory

When I look in /usr/local/lib I can see the particular file. Any ideas what I'm doing wrong?

I can't install

I can't install it,please
➜ py-phash git:(master) ✗ python setup.py install
running install
running build
running build_ext
building 'pHash' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c phashmodule.C -o build/temp.linux-x86_64-2.7/phashmodule.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
phashmodule.C:8:19: fatal error: pHash.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

➜ py-phash git:(master) python -V
Python 2.7.4

➜ py-phash git:(master) uname -a
Linux user 3.8.0-29-generic #42-Ubuntu SMP Tue Aug 13 19:40:39 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.