3fcca2dd446cff530241c7b5354e80a55aaa01f6
[image-openalpr.git] / lib / Image / OpenALPR / PlateResult.pm
1 package Image::OpenALPR::PlateResult;
2
3 use 5.014000;
4 use strict;
5 use warnings;
6
7 use parent qw/Class::Accessor::Fast/;
8
9 our $VERSION = '0.001';
10
11 __PACKAGE__->mk_ro_accessors(qw/plate confidence matches_template/);
12
13 sub coordinates {
14 my $coords = shift->{coordinates};
15 return unless $coords;
16 my @result = map { [$_->{x}, $_->{y}] } @$coords;
17 wantarray ? @result : \@result
18 }
19
20 sub candidates {
21 my $cands = shift->{candidates};
22 return unless $cands;
23 my @result = map { __PACKAGE__->new($_) } @$cands;
24 wantarray ? @result : \@result
25 }
26
27 1;
28 __END__
29
30 =encoding utf-8
31
32 =head1 NAME
33
34 Image::OpenALPR::PlateResult - a license plate, as identified by OpenALPR
35
36 =head1 SYNOPSIS
37
38 my $plate = $alpr->recognise('t/example.jpg');
39 say $plate->plate; # ZP36709
40 say $plate->confidence; # 92.373634
41 my @coords = $plate->coordinates; # [306, 351], [476, 351], [476, 384], [306, 384]
42 my @candidates = $plate->candidates;
43 say $candidates[1]->plate; # ZP367O9
44 say $candidates[1]->confidence; # 89.812302
45
46 =head1 DESCRIPTION
47
48 Image::OpenALPR::PlateResult is a class representing a plate
49 identified by OpenALPR. It offers the following methods:
50
51 =over
52
53 =item $plate->B<plate>
54
55 The plate number that has the highest confidence value (likelihood of
56 being correct).
57
58 =item $plate->B<confidence>
59
60 The confidence value of the plate number returned by B<plate>.
61
62 =item $plate->B<matches_template>
63
64 True if the plate matches the plate pattern chosen via the
65 B<set_default_region> in L<Image::OpenALPR>, false otherwise (or if no
66 region was chosen).
67
68 =item $plate->B<coordinates>
69
70 In list context, returns a four element list representing the vertices
71 of the license plate, numbered clock-wise from top-left. Each element
72 is an arrayref with two elements: the X coordinate followed by the Y
73 coordinate.
74
75 In scalar context, returns an arrayref to an array containing the list
76 described above.
77
78 =item $plate->B<candidates>
79
80 In list context, returns a list of candidate license numbers, in
81 decreasing order of confidence. The first element coincides with the
82 plate/confidence pair returned by the B<plate> and B<confidence>
83 methods. Each element is a partial Image::OpenALPR::PlateResult object
84 -- only the B<plate>, B<confidence> and B<matches_template> methods
85 will return a meaningful value.
86
87 =back
88
89 =head1 AUTHOR
90
91 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
92
93 =head1 COPYRIGHT AND LICENSE
94
95 Copyright (C) 2016 by Marius Gavrilescu
96
97 This file is part of Image-OpenALPR.
98
99 Image-OpenALPR is free software: you can redistribute it and/or modify
100 it under the terms of the GNU Affero General Public License as published by
101 the Free Software Foundation, either version 3 of the License, or
102 (at your option) any later version.
103
104 Image-OpenALPR is distributed in the hope that it will be useful,
105 but WITHOUT ANY WARRANTY; without even the implied warranty of
106 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
107 GNU Affero General Public License for more details.
108
109 You should have received a copy of the GNU Affero General Public License
110 along with Image-OpenALPR. If not, see <http://www.gnu.org/licenses/>
111
112
113 =cut
This page took 0.026315 seconds and 3 git commands to generate.