Bump version and update Changes
[image-openalpr.git] / lib / Image / OpenALPR.pm
CommitLineData
470f6420
MG
1package Image::OpenALPR;
2
3use 5.014000;
4use strict;
5use warnings;
6
7use Image::OpenALPR::PlateResult;
8use JSON::MaybeXS qw/decode_json/;
9use XSLoader;
10
11BEGIN {
4d4051da 12 our $VERSION = '0.001001';
470f6420
MG
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;
21}
22
23sub new {
24 my $alpr = initialise (@_[1..$#_]);
25 die "Failed to load OpenALPR\n" unless $alpr->is_loaded;
26 $alpr
27}
28
29sub recognise {
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
35}
36
37sub DESTROY { shift->dispose }
38
39package AlprPtr;
40our @ISA = qw/Image::OpenALPR/;
41
421;
43__END__
44
45=encoding utf-8
46
47=head1 NAME
48
49Image::OpenALPR - Perl binding for Automatic License Plate Recognition library
50
51=head1 SYNOPSIS
52
53 use Image::OpenALPR;
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;
58
59 $alpr->set_top_n(2);
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;
65
66=head1 DESCRIPTION
67
68OpenALPR is an automatic license plate recognition library that
69extracts license plate numbers from images.
70
71The following methods are available:
72
73=over
74
75=item Image::OpenALPR->B<new>(I<$country>, I<$config>, I<$runtime_data>)
76
77Takes one mandatory argument (the country rules to use, such as C<eu>
78or C<us>) and two optional arguments: a path to the configuration
79file, and a path to the runtime_data directory.
80
6765bc35 81Returns a new Image::OpenALPR instance. If initialisation fails (for
470f6420
MG
82example, if the chosen country is not available) an exception is
83thrown.
84
85=item $alpr->B<recognise>(I<$file>)
a6894b64 86
470f6420
MG
87=item $alpr->B<recognise>(I<\$data>)
88
89Takes a path to an image file or a reference to the contents of an
90image file and tries to find license plates in the image. In list
91context, it returns a list of L<Image::OpenALPR::PlateResult> objects,
92one for each plate found. In scalar context it returns only one such
93object (the first plate found), or undef if no plates were found.
94
95=item $alpr->B<get_version>
a6894b64 96
470f6420
MG
97=item $alpr->B<getVersion>
98
99Returns the version of the OpenALPR library.
100
101=item $alpr->B<set_country>(I<$country>)
a6894b64 102
470f6420
MG
103=item $alpr->B<setCountry>(I<$country>)
104
105Changes the country rules in use.
106
107=item $alpr->B<set_prewarp>(I<$prewarp>)
a6894b64 108
470f6420
MG
109=item $alpr->B<setPrewarp>(I<$prewarp>)
110
111Sets the camera calibration values, as obtained from the
6765bc35
MG
112C<openalpr-utils-calibrate> utility. Can also be set in the
113configuration file.
470f6420
MG
114
115=item $alpr->B<set_default_region>(I<$region>)
a6894b64 116
470f6420
MG
117=item $alpr->B<setDefaultRegion>(I<$region>)
118
119Sets the expected region for pattern matching. This improves accuracy.
120The B<matches_template> flag is set on plates that match this pattern.
121
122=item $alpr->B<set_top_n>(I<$n>)
a6894b64 123
470f6420
MG
124=item $alpr->B<setTopN>(I<$n>)
125
126Sets the maximum number of candidates to return for one plate. Default
127is 10.
128
129=back
130
131=head1 SEE ALSO
132
133L<http://www.openalpr.com>, L<https://github.com/openalpr/openalpr>
134
135=head1 AUTHOR
136
137Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
138
139=head1 COPYRIGHT AND LICENSE
140
141Copyright (C) 2016 by Marius Gavrilescu
142
143This file is part of Image-OpenALPR.
144
145Image-OpenALPR is free software: you can redistribute it and/or modify
146it under the terms of the GNU Affero General Public License as published by
147the Free Software Foundation, either version 3 of the License, or
148(at your option) any later version.
149
150Image-OpenALPR is distributed in the hope that it will be useful,
151but WITHOUT ANY WARRANTY; without even the implied warranty of
152MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153GNU Affero General Public License for more details.
154
155You should have received a copy of the GNU Affero General Public License
156along with Image-OpenALPR. If not, see <http://www.gnu.org/licenses/>
157
158
159=cut
This page took 0.020334 seconds and 4 git commands to generate.