Git Product home page Git Product logo

pypuzzle's Introduction

PyPuzzle Build Status

PyPuzzle provides python bindings for libpuzzle. Libpuzzle is designed to quickly find visually similar images (gif, png, jpg), even if they have been resized, recompressed, recolored or slightly modified. Since libpuzzle is a C library, PyPuzzle connects it to python.

For more information about libpuzzle, consult its home page.

Installation

At present, PyPuzzle has only been tested under Linux and OS X 10.9.

Before compiling, make sure you have header files of libpuzzle and libgd2 installed. See 'COMPILATION' section in the doc of libpuzzle.

For Ubuntu users, you can just install them from source:

apt-get install libgd-dev libpuzzle-dev

Note: In case of missing some image formats support, make sure you have corresponding image libraries installed. For example, libjpeg/libpng, etc.

Then you can install PyPuzzle with pip:

$ pip install pypuzzle

or easy_install:

$ esay_install pypuzzle

In addition, you can compile it from source:

$ python setup.py install

Usage

import pypuzzle

puzzle = pypuzzle.Puzzle()

# Get distance between two image files
distance = puzzle.get_distance_from_file("file_1.jpg", "file_2.jpg")

# Get vector from image file
vec_1 = puzzle.get_cvec_from_file("file_1.jpg")
vec_2 = puzzle.get_cvec_from_file("file_2.jpg")

# Get distance between two vectors
distance = puzzle.get_distance_from_cvec(vec_1, vec_2)

# Compress vector
cmp_vec_1 = puzzle.compress_cvec(vec_1)

# Uncompress vector
uncmp_vec_1 = puzzle.uncompress_cvec(cmp_vec_1)

PyPuzzle allows you to change related parameters of the algorithm with set_*() methods:

Puzzle.set_max_width(max_width)
Puzzle.set_max_height(max_height)
Puzzle.set_lambdas(lambdas)
Puzzle.set_p_ratio(p_ratio)
Puzzle.set_noise_cutoff(noise_cutoff)
Puzzle.set_contrast_barrier_for_cropping(barrier)
Puzzle.set_max_cropping_ratio(ratio)
Puzzle.set_autocrop(enable)

Consult original page of libpuzzle for more details.

Changes

v1.3

  • Add Python 3 support

v1.2

  • Raise IOError in get_cvec_from_file and get_distance_from_file if error occurred when reading from file.

pypuzzle's People

Contributors

archangelsdy 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pypuzzle's Issues

Can't install

src/pypuzzle.c:2:10: fatal error: 'puzzle.h' file not found
#include <puzzle.h>
^
1 error generated.
error: command 'clang' failed with exit status 1

what should i do?

*BUG* File: [vector_ops.c] Line: [18]

While trying to compare two vectors I get the following error

on Ubuntu 14.04

*BUG* File: [vector_ops.c] Line: [18]
Aborted (core dumped)

I am comparing to a value in mongoDB and I have verified both vec and doc['vector'] are not null.

My program breaks here

                                distance = puzzle.get_distance_from_cvec(vec,doc['vector'])

I am comparing to a value in mongoDB and I have verified both vec and doc['vector'] are not null.

error when setting non-default lambda and doing a compress uncompress

Hi!

If I set the lambda value to anything other than the default of 9 when doing a vec compress/uncompress, I get the following error:

BUG File: [compress.c] Line: [59]
Aborted

I have observed this in all other bindings I have tried including cytyping in python I've done on my own. I have filed an issue with libpuzzle, but if you know what is happening, it would be great to fix :)

REPRODUCE:

import pypuzzle

puzzle = pypuzzle.Puzzle()

puzzle.set_lambdas(11) #****************#

cvec_1 = puzzle.get_cvec_from_file('1.jpg')
cvec_2 = puzzle.get_cvec_from_file('2.jpg')

Compress vector

cmp_vec_1 = puzzle.compress_cvec(cvec_1)
cmp_vec_2 = puzzle.compress_cvec(cvec_2)

Uncompress vector

uncmp_vec_1 = puzzle.uncompress_cvec(cmp_vec_1)
uncmp_vec_2 = puzzle.uncompress_cvec(cmp_vec_2)

distance = puzzle.get_distance_from_cvec(uncmp_vec_1, uncmp_vec_2)
print distance

for ubuntu 18.04 you also need libgd-dev

pip install pypuzzle
Collecting pypuzzle
Using cached https://files.pythonhosted.org/packages/fc/f7/59c2f47b48393be5fdc99c5f9587cbe177250a07b8faea04c8b7754f7d48/pypuzzle-1.3.tar.gz
Building wheels for collected packages: pypuzzle
Running setup.py bdist_wheel for pypuzzle ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-dBVjJi/pypuzzle/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmp645aLrpip-wheel- --python-tag cp27:
running bdist_wheel
running build
running build_ext
building 'pypuzzle' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/pypuzzle.c -o build/temp.linux-x86_64-2.7/src/pypuzzle.o
creating build/lib.linux-x86_64-2.7
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC build/temp.linux-x86_64-2.7/src/pypuzzle.o -lpuzzle -lgd -o build/lib.linux-x86_64-2.7/pypuzzle.so
/usr/bin/ld: cannot find -lgd
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1


Failed building wheel for pypuzzle
Running setup.py clean for pypuzzle
Failed to build pypuzzle
Installing collected packages: pypuzzle
Running setup.py install for pypuzzle ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-dBVjJi/pypuzzle/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-DiqEjY-record/install-record.txt --single-version-externally-managed --compile --user --prefix=:
running install
running build
running build_ext
building 'pypuzzle' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/pypuzzle.c -o build/temp.linux-x86_64-2.7/src/pypuzzle.o
creating build/lib.linux-x86_64-2.7
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC build/temp.linux-x86_64-2.7/src/pypuzzle.o -lpuzzle -lgd -o build/lib.linux-x86_64-2.7/pypuzzle.so
/usr/bin/ld: cannot find -lgd
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-dBVjJi/pypuzzle/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-DiqEjY-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-dBVjJi/pypuzzle/
~/PyPuzzle (master)$ sudo synaptic
~/PyPuzzle (master)$ python setup.py install
running install
running build
running build_ext
building 'pypuzzle' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/pypuzzle.c -o build/temp.linux-x86_64-2.7/src/pypuzzle.o
creating build/lib.linux-x86_64-2.7
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-kjnyAR/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC build/temp.linux-x86_64-2.7/src/pypuzzle.o -lpuzzle -lgd -o build/lib.linux-x86_64-2.7/pypuzzle.so
/usr/bin/ld: cannot find -lgd
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

=========================

installing libgd-dev fixing issue. Update readme plz, because pull requests are closed

missing setup.py

when I do a pip install pypuzzle I get
IOError: [Errno 2] No such file or directory: '[omitted]/virenv/deysite/build/pypuzzle/setup.py'

Fix:
pip install pypuzzle==1.2

install error

PyPuzzle git:(master) python2 setup.py install
running install
running build
running build_ext
building 'pypuzzle' extension
creating build
creating build/temp.macosx-10.6-intel-2.7
creating build/temp.macosx-10.6-intel-2.7/src
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/pypuzzle.c -o build/temp.macosx-10.6-intel-2.7/src/pypuzzle.o
src/pypuzzle.c:2:10: fatal error: 'puzzle.h' file not found
#include <puzzle.h>
         ^~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1

Error installing

I get this error, either with pip og setup.py. Using brewed Python 2.7.9 or 3.4.2 on OS X 10.10.


ImportError Traceback (most recent call last)
in ()
----> 1 import pypuzzle

ImportError: dlopen(/usr/local/lib/python3.4/site-packages/pypuzzle.so, 2): Symbol not found: _PyInt_AsLong
Referenced from: /usr/local/lib/python3.4/site-packages/pypuzzle.so
Expected in: flat namespace
in /usr/local/lib/python3.4/site-packages/pypuzzle.so

Error when getting distance between files.

Hi,

On Ubuntu 14.04 server when I get the distance between two filles, either with puzzle.get_distance_from_file() or puzzle.get_distance_from_cvec(), I get the following error:

*BUG* File: [vector_ops.c] Line: [18]
Aborted (core dumped)

I installed libpuzzle-dev and libgd2-xpm-dev through apt-get. The files I have tried work when I try them using puzzle-diff from the shell.

Thanks.

update to README

Hi! Great, great library-- thank you!

I didn't want to fork and issue a patch or pull request because it's already got everything I need, but just wanted to let you know that brand new linux installs also require libjpeg62 (or at least from my experience in automating builds using your lib on Docker.)

python3 / undefined symbol: PyInt_AsLong

Hi.

I have installed pypuzzle with pip.
Installation has correctly finished. but I cannot run example code on python3 due to an error.

 Traceback (most recent call last):
   File "puzzletest.py", line 1, in <module>
     import pypuzzle
  ImportError: /usr/lib64/python3.4/site-packages/pypuzzle.cpython-34m.s : undefined symbol: PyInt_AsLong

The error does not occur with using python 2 .

Perhaps it is necessary to wrap some function .

#if PY_MAJOR_VERSION >= 3
#  define PyInt_AsLong(x) (PyLong_AsLong((x)))
// ....
#endif

Add proper type verification

I added, by mistake, the length of the vectors.
When calling get_distance_from_cvec() with the two integers: core dump.

In [15]: vectors = []

In [16]: for fname in glob.glob('path/to/dir/*'):
    vectors.append(len(puzzle.get_cvec_from_file(fname)))
   ....:     

In [17]: distances = []

In [18]: puzzle.get_distance_from_cvec(vectors[0], vectors[1])
Segmentation fault (core dumped)
$ 

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.