| 1 | package PDF::OCR2::Base::Image; # this should be Image::OCR::Tesseract:OO | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use LEOCHARRE::Class2; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | __PACKAGE__->make_accessor_get(qw/abs_path/); | ||
| 5 | 1 | ▶ | use Image::OCR::Tesseract; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | use Carp; | ||
| 7 | sub new { | ||
| 8 | my ($class,$arg) =@_; | ||
| 9 | |||
| 10 | my $self = {}; | ||
| 11 | require Cwd; | ||
| 12 | my $abs = Cwd::abs_path($arg) | ||
| 13 | or Carp::cluck("Can't get abs path to '$arg'") | ||
| 14 | and return; | ||
| 15 | |||
| 16 | -f $abs | ||
| 17 | or Carp::cluck("Not on disk: '$abs'") | ||
| 18 | and return; | ||
| 19 | |||
| 20 | $self->{abs_path} = $abs; | ||
| 21 | |||
| 22 | bless $self, $class; | ||
| 23 | return $self; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub text { | ||
| 27 | my $self = shift; | ||
| 28 | |||
| 29 | unless( defined $self->{text}){ | ||
| 30 | my $abs = $self->abs_path; | ||
| 31 | $self->{text} ||= Image::OCR::Tesseract::get_ocr($abs); | ||
| 32 | $self->{text} | ||
| 33 | or warn("No text in '$abs'?"); | ||
| 34 | } | ||
| 35 | $self->{text}; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub text_length { length( $_[0]->text ) || 0 } | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | 1; | ||
| 44 | |||
| 45 | |||
| 46 | |||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | |||
| 52 | 1; | ||
| 53 | |||
| 54 | __END__ | ||
| 55 | |||
| 56 | =pod | ||
| 57 | |||
| 58 | =head1 NAME | ||
| 59 | |||
| 60 | =head1 SYNOPSIS | ||
| 61 | |||
| 62 | =head1 DESCRIPTION | ||
| 63 | |||
| 64 | Do not use this api. | ||
| 65 | |||
| 66 | =head1 AUTHOR | ||
| 67 | |||
| 68 | Leo Charre leocharre at cpan dot org | ||
| 69 | |||
| 70 | =head1 LICENSE | ||
| 71 | |||
| 72 | This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License". | ||
| 73 | |||
| 74 | =head1 DISCLAIMER | ||
| 75 | |||
| 76 | This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 77 | |||
| 78 | See the "GNU General Public License" for more details. | ||
| 79 | |||
| 80 | =cut | ||
| 81 | |||
| 82 | |||