Finance-MICR-GOCR-Check
view release on metacpan or search on metacpan
bin/checkscan view on Meta::CPAN
my $check = new Finance::MICR::GOCR::Check({
abs_check => $abs_check,
abs_path_gocrdb => ($o->{b} or undef),
d => ( $o->{D} or undef ),
s => ( $o->{S} or undef ),
});
if ($custom_increment or $custom_steps ){
$check->crop_increment($custom_increment) if $custom_increment;
$check->crop_iterations($custom_steps) if $custom_steps;
print STDERR "custom steps [$custom_steps] custom increment [$custom_increment]\n" if DEBUG;
}
$check->crop_sides($o->{o}) if $o->{o};
if ($o->{q}){
if ($check->found_valid){
print STDERR " found valid micr line\n" if DEBUG;
}
bin/checkscan view on Meta::CPAN
checkscan - work with a scanned check image
=head1 USAGE
checkscan -q /path/to/check.png
=head1 PARAMETERS
-i increment pixels per iteration, default is 5
-x how many iterations, default is 12 if you set the pixel increment yourself
-o crop sides when iterating, value is percent in the form 0.15 where 1 is 100%
-b path to micr database, dafaults to /usr/share/micrdb/
-D dust size, default is 20
-S spacing, default is 80
=head1 OPTIONS
-p prep
-v version
-h help
-d debug messages, default is off
=head1 USAGE EXAMPLES
checkscan -q ./t/checks_hard/hard1.png
For a hard to read check you may want to try changing iterations:
checkscan -q -x 15 -i 2 ./t/checks_hard/hard1.png
=head1 CHANGING THE ITERATIONS
The program crops from the bottom up to look for a valid micr line in the image
by default the steps are something like:
lib/Finance/MICR/GOCR/Check.pm view on Meta::CPAN
sub crop_sides {
my($self,$set) = @_;
if (defined $set){
$self->{crop_sides} = $set;
}
$self->{crop_sides} ||= 0.15;
return $self->{crop_sides};
}
sub crop_iterations {
my($self,$set) = @_;
if (defined $set){
$self->{crop_iterations} = $set;
$self->{custom_iteration_is_set} =1;
}
$self->{crop_iterations} ||= 12;
return $self->{crop_iterations};
}
sub crop_increment {
my($self,$set) = @_;
if (defined $set){
$self->{crop_increment} = $set;
$self->{custom_iteration_is_set} =1;
}
$self->{crop_increment} ||= 5;
return $self->{crop_increment};
}
sub scan_iterations_reset {
my $self = shift;
$self->{crop_iterations} = undef;
$self->{custom_iteration_is_set} = undef;
$self->{crop_increment} = undef;
return;
}
# build the increment values and elements
# these are the iterations steps we will try
# stops when we find one that produces valid micr
sub scan_iterations {
my $self = shift;
my @iterations;
if( $self->_custom_iteration_is_set ){
my $i =0;
my $now = 70;
while ( $i != $self->crop_iterations ){
push @iterations, $now;
$now =($now + $self->crop_increment);
$i++;
}
print STDERR "custom iteration is set, steps are [@iterations]\n" if DEBUG;
printf STDERR "step increment is : %s, number of steps: %s\n", $self->crop_increment, $self->crop_iterations if DEBUG;
}
else {
@iterations = qw(70 75 80 85 90 95 100 105 110 115 120 130 140 150 160 170 180 190 200 210 220 230 240 250 300); # aggressive
print STDERR "iterations are default, set to [@iterations]\n" if DEBUG;
}
return \@iterations;
}
sub rescan {
my $self = shift;
$self->{_data}->{_micrdata} = undef;
return $self->found_valid;
}
sub found_valid {
my $self = shift;
lib/Finance/MICR/GOCR/Check.pm view on Meta::CPAN
}
=head2 crop_sides()
Percentage to crop sides by when iterating, scanning up for MICR line
default is fifteen percent
number should be 0.15 for 15%
=head2 crop_iterations()
argument is number of iterations to do before giving up on searching for micrline scans.. starts from bottom.. does 5 pix increments.
if no argumetn, returns number of iterations set.
If you give 0, it switches to default, which is 12- max is 25
=head2 crop_increment()
argument is pixel increment per iteration
if no argumetn, returns increment value
If you give 0, it switches to default, which is 5
suggested is min 2, max 8
You must set these values BEFORE you ask for the micr from ocr
=head2 scan_iterations()
returns array ref of what the iterations are set at
dafault are approximately:
70 75 80 85 90 95 100 105 110 115 120 130 140 150 160 170 180 190 200 210 220 230 240 250 300
That means the first image extract is the micr height from 70 pixels from the bottom, then 75, etc.. Until a valid
micr line is found.
=head2 scan_iterations_reset()
will reset crop_sides, crop_increment, crop_iterations to default values.
=head2 found_valid()
will trigger a scan if none was already ran.
returns boolean if at the last scan parser() returns true for parser->valid()
=head2 rescan()
If you want to change your parameters and rescan.
returns boolean just like found_valid()
Example usage:
unless( $c->found_valid ){
$c->s(70); # change the spacing for gocr
$c->d(15); # change the dust size from default of 20 to 15
$c->crop_increment(2); # set more precise iterations, default is 5 or so
$c->crop_iterations(10); # set less iterations to happen
$c->rescan;
if ($c->found_valid){
printf STDERR "worked! found: %s\n", $c->parser->micr_pretty;
}
}
lib/Finance/MICR/GOCR/Check.pm view on Meta::CPAN
sub _micr {
my $self = shift;
unless( defined $self->{_data}->{_micrdata} ){
if (DEBUG){
printf STDERR __PACKAGE__ ." _micr defining\n
custom iteration %s
crop iterations %s
crop increment %s
",
$self->_custom_iteration_is_set,
$self->crop_iterations,
$self->crop_increment;
}
my $data = {
parser => undef,
height => undef,
abs_micr => undef,
raw => undef,
};
# get string from where micr line should be
# it should NOT STOP at first valid.. it should run one more!!! when it gets chopped up it still tries matching!
my $id = time ;# for development purpose.. disregard, names the micrfiles
my $last_one_was_valid =0;
my $stop = 0;
my $iterations = $self->scan_iterations;
for (@$iterations){
if ($last_one_was_valid){ # then do one more just 2px or 4px up
$data->{height} = ($data->{height} + 5);
$stop =1; #force stop
}
else { # go on as usual
$data->{height} = $_;
}
printf STDERR "iterating size [%s]\n",$data->{height} if DEBUG;
lib/Finance/MICR/GOCR/Check.pm view on Meta::CPAN
}
$self->{_data}->{_micrdata} = $data;
# if it's not valid try something nuts??
# $last_one_was_valid =0;
# $stop = 0;
my $data2=$data; # copies or .. what?
unless ($data2->{parser}->micr_pretty){
print STDERR "iterations will not match, trying something different\n" if DEBUG;
for (qw(90 95 100 105 110 115)){
# if ($last_one_was_valid){ # then do one more just 2px or 4px up
# $data2->{height} = ($data2->{height} + 5);
# $stop =1; #force stop
# }
# else { # go on as usual
$data2->{height} = $_;
# }
lib/Finance/MICR/GOCR/Check.pm view on Meta::CPAN
return $self->_micr->{abs_micr};
}
sub gocr_raw {
my $self = shift;
return $self->_micr->{raw};
}
=head2 abs_micr()
absolute path to micr file what was created.
after the iterations, the one that closest matched is this file.
This is useful to know if you want to build or increment the gocr database.
=head2 gocr_raw()
the raw ocr output for the micrfile that was last made,
returns 'none' if none returned.
=head2 micr_height()
the height of the micr file, we try to make 70 80 90 100 110 120 130 and the first to match
( run in 2.510 seconds using v1.01-cache-2.11-cpan-71847e10f99 )