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