| 1 |
|
| 2 |
.:. LIBPUZZLE - PHP EXTENSION .:. |
| 3 |
|
| 4 |
http://libpuzzle.pureftpd.org |
| 5 |
|
| 6 |
|
| 7 |
------------------------ PHP EXTENSION ------------------------ |
| 8 |
|
| 9 |
|
| 10 |
The Puzzle library can also be used through PHP, using a native extension. |
| 11 |
|
| 12 |
Prerequisites are the PHP headers, libtool, autoconf and automake. |
| 13 |
|
| 14 |
Here are the basic steps in order to install the extension: |
| 15 |
|
| 16 |
(on OpenBSD: export AUTOMAKE_VERSION=1.9 ; export AUTOCONF_VERSION=2.61) |
| 17 |
|
| 18 |
cd php/libpuzzle |
| 19 |
phpize |
| 20 |
./configure --with-libpuzzle |
| 21 |
make clean |
| 22 |
make |
| 23 |
make install |
| 24 |
|
| 25 |
If libpuzzle is installed in a non-standard location, use: |
| 26 |
./configure --with-libpuzzle=/base/directory/for/libpuzzle |
| 27 |
|
| 28 |
Then edit your php.ini file and add: |
| 29 |
|
| 30 |
extension=libpuzzle.so |
| 31 |
|
| 32 |
|
| 33 |
------------------------ USAGE ------------------------ |
| 34 |
|
| 35 |
|
| 36 |
The PHP extension provides bindings for the following tuning functions: |
| 37 |
- puzzle_set_max_width() |
| 38 |
- puzzle_set_max_height() |
| 39 |
- puzzle_set_lambdas() |
| 40 |
- puzzle_set_noise_cutoff() |
| 41 |
- puzzle_set_p_ratio() |
| 42 |
- puzzle_set_contrast_barrier_for_cropping() |
| 43 |
- puzzle_set_max_cropping_ratio() |
| 44 |
- puzzle_set_autocrop() |
| 45 |
|
| 46 |
Have a look at the puzzle_set man page for more info about those. |
| 47 |
|
| 48 |
Getting the signature of a picture is as simple as: |
| 49 |
|
| 50 |
$signature = puzzle_fill_cvec_from_file($filename); |
| 51 |
|
| 52 |
In order to compute the similarity between two pictures using their |
| 53 |
signatures, use: |
| 54 |
|
| 55 |
$d = puzzle_vector_normalized_distance($signature1, $signature2); |
| 56 |
|
| 57 |
The result is between 0.0 and 1.0, with 0.6 being a good threshold to detect |
| 58 |
visually similar pictures. |
| 59 |
|
| 60 |
The PUZZLE_CVEC_SIMILARITY_THRESHOLD, PUZZLE_CVEC_SIMILARITY_HIGH_THRESHOLD, |
| 61 |
PUZZLE_CVEC_SIMILARITY_LOW_THRESHOLD and PUZZLE_CVEC_SIMILARITY_LOWER_THRESHOLD |
| 62 |
constants can also be used to get common thresholds : |
| 63 |
|
| 64 |
if ($d < PUZZLE_CVEC_SIMILARITY_THRESHOLD) { |
| 65 |
echo "Pictures look similar\n"; |
| 66 |
} |
| 67 |
|
| 68 |
Before storing a signature into a database, you can compress it in order to |
| 69 |
save some storage space: |
| 70 |
|
| 71 |
$compressed_signature = puzzle_compress_cvec($signature); |
| 72 |
|
| 73 |
Before use, those compressed signatures must be uncompressed with: |
| 74 |
|
| 75 |
$signature = puzzle_uncompress_cvec($compressed_signature); |
| 76 |
|