Initial commit
[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 {
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;
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
81Returns a new Image::OpenALPR instance. If initialization fails (for
82example, if the chosen country is not available) an exception is
83thrown.
84
85=item $alpr->B<recognise>(I<$file>)
86=item $alpr->B<recognise>(I<\$data>)
87
88Takes a path to an image file or a reference to the contents of an
89image file and tries to find license plates in the image. In list
90context, it returns a list of L<Image::OpenALPR::PlateResult> objects,
91one for each plate found. In scalar context it returns only one such
92object (the first plate found), or undef if no plates were found.
93
94=item $alpr->B<get_version>
95=item $alpr->B<getVersion>
96
97Returns the version of the OpenALPR library.
98
99=item $alpr->B<set_country>(I<$country>)
100=item $alpr->B<setCountry>(I<$country>)
101
102Changes the country rules in use.
103
104=item $alpr->B<set_prewarp>(I<$prewarp>)
105=item $alpr->B<setPrewarp>(I<$prewarp>)
106
107Sets the camera calibration values, as obtained from the
108openalpr-utils-calibrate utility. Can also be set in the configuration
109file.
110
111=item $alpr->B<set_default_region>(I<$region>)
112=item $alpr->B<setDefaultRegion>(I<$region>)
113
114Sets the expected region for pattern matching. This improves accuracy.
115The B<matches_template> flag is set on plates that match this pattern.
116
117=item $alpr->B<set_top_n>(I<$n>)
118=item $alpr->B<setTopN>(I<$n>)
119
120Sets the maximum number of candidates to return for one plate. Default
121is 10.
122
123=back
124
125=head1 SEE ALSO
126
127L<http://www.openalpr.com>, L<https://github.com/openalpr/openalpr>
128
129=head1 AUTHOR
130
131Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
132
133=head1 COPYRIGHT AND LICENSE
134
135Copyright (C) 2016 by Marius Gavrilescu
136
137This file is part of Image-OpenALPR.
138
139Image-OpenALPR is free software: you can redistribute it and/or modify
140it under the terms of the GNU Affero General Public License as published by
141the Free Software Foundation, either version 3 of the License, or
142(at your option) any later version.
143
144Image-OpenALPR is distributed in the hope that it will be useful,
145but WITHOUT ANY WARRANTY; without even the implied warranty of
146MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147GNU Affero General Public License for more details.
148
149You should have received a copy of the GNU Affero General Public License
150along with Image-OpenALPR. If not, see <http://www.gnu.org/licenses/>
151
152
153=cut
This page took 0.017389 seconds and 4 git commands to generate.