#!/usr/bin/perl -w
###########################################
# Mike Schilli, 2007 (m@perlmeister.com)
###########################################
use strict;
use Log::Log4perl qw(:easy);
use LCDOCR;
use Getopt::Std;

getopts("vd", \my %opts);
Log::Log4perl->easy_init($opts{v} ? 
                         $DEBUG : $ERROR);
my($file, $x1, $y1, $x2, $y2) = @ARGV;
die "usage: $0 file x1 y1 x2 y2\n" unless
   defined $y2;

my $i = Imager->new();
$i->read(file => $file, type => "jpeg") or 
    die "Can't read $file";

my $gr = Imager::Color->new(0, 255,0);
$i->circle(color=>$gr,r=>1,x=>$x1, y=>$y1);
$i->circle(color=>$gr,r=>1,x=>$x2, y=>$y2);

my $ocr = LCDOCR->new(
  name   => 'RSA1',
  x1_ref => $x1, y1_ref => $y1,
  x2_ref => $x2, y2_ref => $y2,
  image  => $i,
  debug  => ($opts{v}||0));

my $digits = $ocr->reco();

if($opts{v}) {
  my $font = Imager::Font->new(file =>
  "/usr/X11R6/lib/X11/fonts/TTF/Vera.ttf");

  $i->string(x => 50, y => 50,
    string => "Reco: @$digits",
    font   => $font, color => "white",
    size => 30);
  $i->write(file => "out1.jpg", 
            type => "jpeg");
  system("xv out1.jpg") if $opts{d};
}
print join('', @$digits), "\n";
