OCR-Naive
view release on metacpan or search on metacpan
bin/makedict view on Meta::CPAN
#!/usr/bin/perl
# $Id: makedict,v 1.3 2007/08/29 12:03:23 dk Exp $
use strict;
use subs qw(log);
BEGIN { local @ARGV; require Prima; }
use Prima qw(Application ImageViewer Label InputLine Buttons MsgBox);
use Getopt::Long;
use IPA;
use IPA::Geometry qw(rotate90);
use OCR::Naive qw(:all);
my (
%options, $rename_db,
$i, $display,
$db, @sorted_glyphs,
@curr_ext, @curr_pos, $curr_glyph, $curr_index, $curr_entry,
);
%options = (
verbose => 0,
dict => 'dict',
help => 0,
);
GetOptions( \%options,
'verbose',
'help',
'dict=s',
) or usage();
usage() if $options{help};
1 == @ARGV or usage();
sub usage
{
print <<USAGE;
$0 - create a font dictionary for later OCR::Simple recognition from an image.
The image bust be one or more lines of text, where lines must be divided with
al least one pixel of horizontal space, and glyphs must not be overlapped.
options:
--verbose - be verbose
--help - show this text
--dict=FILE - load from dictionary FILE, save changes there
USAGE
exit 1;
}
sub log { warn join('',@_), "\n" if $options{verbose} }
log "loading $ARGV[0]";
$i = Prima::Image-> load( $ARGV[0]);
die "Cannot load $ARGV[0]:$@\n" unless $i;
log "loaded ", ( $i-> type & im::BPP), " bpp image ", $i-> width, "x", $i-> height;
# load db
if ( -f $options{dict}) {
$db = load_dictionary( $options{dict} );
( run in 1.688 second using v1.01-cache-2.11-cpan-800906f7e73 )