aboutsummaryrefslogtreecommitdiff
path: root/deduper/libpuzzle/README-PHP
blob: 6b14fb99a2c61da34b1561973811a90496ef1709 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
                       .:. LIBPUZZLE - PHP EXTENSION .:.
                               
                         http://libpuzzle.pureftpd.org


        ------------------------ PHP EXTENSION ------------------------
        
        
The Puzzle library can also be used through PHP, using a native extension.

Prerequisites are the PHP headers, libtool, autoconf and automake.

Here are the basic steps in order to install the extension:

(on OpenBSD: export AUTOMAKE_VERSION=1.9 ; export AUTOCONF_VERSION=2.61)

cd php/libpuzzle
phpize
./configure --with-libpuzzle
make clean
make
make install

If libpuzzle is installed in a non-standard location, use:
./configure --with-libpuzzle=/base/directory/for/libpuzzle

Then edit your php.ini file and add:

extension=libpuzzle.so


            ------------------------ USAGE ------------------------
            
            
The PHP extension provides bindings for the following tuning functions:
- puzzle_set_max_width()
- puzzle_set_max_height()
- puzzle_set_lambdas()
- puzzle_set_noise_cutoff()
- puzzle_set_p_ratio()
- puzzle_set_contrast_barrier_for_cropping()
- puzzle_set_max_cropping_ratio()
- puzzle_set_autocrop()

Have a look at the puzzle_set man page for more info about those.

Getting the signature of a picture is as simple as:

$signature = puzzle_fill_cvec_from_file($filename);

In order to compute the similarity between two pictures using their
signatures, use:

$d = puzzle_vector_normalized_distance($signature1, $signature2);

The result is between 0.0 and 1.0, with 0.6 being a good threshold to detect
visually similar pictures.

The PUZZLE_CVEC_SIMILARITY_THRESHOLD, PUZZLE_CVEC_SIMILARITY_HIGH_THRESHOLD,
PUZZLE_CVEC_SIMILARITY_LOW_THRESHOLD and PUZZLE_CVEC_SIMILARITY_LOWER_THRESHOLD
constants can also be used to get common thresholds :

if ($d < PUZZLE_CVEC_SIMILARITY_THRESHOLD) {
  echo "Pictures look similar\n";
}

Before storing a signature into a database, you can compress it in order to
save some storage space:

$compressed_signature = puzzle_compress_cvec($signature);

Before use, those compressed signatures must be uncompressed with:

$signature = puzzle_uncompress_cvec($compressed_signature);