1 package Image
::OpenALPR
;
7 use Image
::OpenALPR
::PlateResult
;
8 use JSON
::MaybeXS qw
/decode_json/;
12 our $VERSION = '0.001';
13 XSLoader
::load
('Image::OpenALPR', $VERSION);
14 *initialise
= \
&initialize
;
15 *is_loaded
= \
&isLoaded
;
16 *get_version
= \
&getVersion
;
17 *set_country
= \
&setCountry
;
18 *set_prewarp
= \
&setPrewarp
;
19 *set_default_region
= \
&setDefaultRegion
;
20 *set_top_n
= \
&setTopN
;
24 my $alpr = initialise
(@_[1..$#_]);
25 die "Failed to load OpenALPR\n" unless $alpr->is_loaded;
30 my ($alpr, $data) = @_;
31 my $json = ref $data eq 'SCALAR' ?
$alpr->recognizeArray($$data) : $alpr->recognizeFile($data);
32 $json = decode_json
$json;
33 my @plates = map { Image
::OpenALPR
::PlateResult
->new($_) } @
{$json->{results
}};
34 wantarray ?
@plates : shift @plates
37 sub DESTROY
{ shift->dispose }
40 our @ISA = qw
/Image::OpenALPR/;
49 Image::OpenALPR - Perl binding for Automatic License Plate Recognition library
54 my $alpr = Image::OpenALPR->new('eu');
55 $alpr->get_version; # 2.2.4
56 my (@plates) = $alpr->recognise('many_plates.jpg');
57 say 'Plates found: ', join ' ', map { $_->plate } @plates;
60 my $data = read_file 'one_plate.gif';
61 my $a_plate = $alpr->recognise(\$data);
62 my @cnd = @{$a_plate->candidates};
63 say $cnd[0]->plate, ' ', $cnd[0]->confidence;
64 say $cnd[1]->plate, ' ', $cnd[1]->confidence;
68 OpenALPR is an automatic license plate recognition library that
69 extracts license plate numbers from images.
71 The following methods are available:
75 =item Image::OpenALPR->B<new>(I<$country>, I<$config>, I<$runtime_data>)
77 Takes one mandatory argument (the country rules to use, such as C<eu>
78 or C<us>) and two optional arguments: a path to the configuration
79 file, and a path to the runtime_data directory.
81 Returns a new Image::OpenALPR instance. If initialization fails (for
82 example, if the chosen country is not available) an exception is
85 =item $alpr->B<recognise>(I<$file>)
86 =item $alpr->B<recognise>(I<\$data>)
88 Takes a path to an image file or a reference to the contents of an
89 image file and tries to find license plates in the image. In list
90 context, it returns a list of L<Image::OpenALPR::PlateResult> objects,
91 one for each plate found. In scalar context it returns only one such
92 object (the first plate found), or undef if no plates were found.
94 =item $alpr->B<get_version>
95 =item $alpr->B<getVersion>
97 Returns the version of the OpenALPR library.
99 =item $alpr->B<set_country>(I<$country>)
100 =item $alpr->B<setCountry>(I<$country>)
102 Changes the country rules in use.
104 =item $alpr->B<set_prewarp>(I<$prewarp>)
105 =item $alpr->B<setPrewarp>(I<$prewarp>)
107 Sets the camera calibration values, as obtained from the
108 openalpr-utils-calibrate utility. Can also be set in the configuration
111 =item $alpr->B<set_default_region>(I<$region>)
112 =item $alpr->B<setDefaultRegion>(I<$region>)
114 Sets the expected region for pattern matching. This improves accuracy.
115 The B<matches_template> flag is set on plates that match this pattern.
117 =item $alpr->B<set_top_n>(I<$n>)
118 =item $alpr->B<setTopN>(I<$n>)
120 Sets the maximum number of candidates to return for one plate. Default
127 L<http://www.openalpr.com>, L<https://github.com/openalpr/openalpr>
131 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
133 =head1 COPYRIGHT AND LICENSE
135 Copyright (C) 2016 by Marius Gavrilescu
137 This file is part of Image-OpenALPR.
139 Image-OpenALPR is free software: you can redistribute it and/or modify
140 it under the terms of the GNU Affero General Public License as published by
141 the Free Software Foundation, either version 3 of the License, or
142 (at your option) any later version.
144 Image-OpenALPR is distributed in the hope that it will be useful,
145 but WITHOUT ANY WARRANTY; without even the implied warranty of
146 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147 GNU Affero General Public License for more details.
149 You should have received a copy of the GNU Affero General Public License
150 along with Image-OpenALPR. If not, see <http://www.gnu.org/licenses/>
This page took 0.027994 seconds and 5 git commands to generate.