[23769] | 1 | package ocraction;
|
---|
| 2 |
|
---|
| 3 | use strict;
|
---|
| 4 |
|
---|
| 5 | use cgiactions::baseaction;
|
---|
| 6 |
|
---|
| 7 | use dbutil;
|
---|
| 8 | use ghtml;
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | BEGIN {
|
---|
| 12 | # unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
|
---|
| 13 | require XML::Rules;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | @ocraction::ISA = ('baseaction');
|
---|
| 18 |
|
---|
| 19 | my $action_table =
|
---|
| 20 | {
|
---|
| 21 | "preformOcr" => { 'compulsory-args' => [ "d", "imagename" ],
|
---|
| 22 | 'optional-args' => [] },
|
---|
| 23 | "setText" => { 'compulsory-args' => [ "d", "newtext" ],
|
---|
| 24 | 'optional-args' => [] }
|
---|
| 25 | };
|
---|
| 26 |
|
---|
| 27 | sub new
|
---|
| 28 | {
|
---|
| 29 | my $class = shift (@_);
|
---|
| 30 | my ($gsdl_cgi,$iis6_mode) = @_;
|
---|
| 31 |
|
---|
| 32 | my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
|
---|
| 33 |
|
---|
| 34 | return bless $self, $class;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | sub preformOcr
|
---|
| 38 | {
|
---|
| 39 | my $self = shift @_;
|
---|
| 40 |
|
---|
| 41 | my $collection = $self->{'collect'};
|
---|
| 42 | my $site = $self->{'site'};
|
---|
| 43 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 44 |
|
---|
| 45 | my $docId = $self->{'d'};
|
---|
| 46 | my $imagename = $self->{'imagename'};
|
---|
| 47 |
|
---|
| 48 | # Change URL style '/' to Windows style
|
---|
| 49 | $imagename =~ s/\//\\/g;
|
---|
| 50 |
|
---|
| 51 | my $indexDir = "C:\\Users\\Bryce\\Desktop\\Research\\greenstone3-svn-bryce64\\web\\sites\\localsite\\collect\\jonesmin\\";
|
---|
| 52 | ##my $hashDir = $archivesDir . substr($docId,0,8) . ".dir\\";
|
---|
| 53 |
|
---|
| 54 | my $imageFile = $indexDir . $imagename;
|
---|
| 55 |
|
---|
| 56 | my $outputFile = $ENV{'TEMP'} . "\\out";
|
---|
| 57 | my $cmd = "tesseract $imageFile $outputFile";
|
---|
| 58 | ## print STDERR "\n\n CMD=\n$cmd \n\n";
|
---|
| 59 |
|
---|
| 60 | my $status = system($cmd);
|
---|
| 61 | if($status != 0) { print STDERR "\n\n Fail to run \n $cmd \n $! \n\n"; }
|
---|
| 62 | if (open (FILE, "<$outputFile" . ".txt")==0) {
|
---|
| 63 | $gsdl_cgi->generate_error("Unable to open file containing OCR'd text:<br> $!");
|
---|
| 64 | return;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | my $result = "";
|
---|
| 68 | my $line;
|
---|
| 69 | while(defined ($line=<FILE>)) {
|
---|
| 70 | $result .= $line;
|
---|
| 71 | }
|
---|
| 72 | close FILE;
|
---|
| 73 | unlink($outputFile . ".txt");
|
---|
| 74 |
|
---|
| 75 | $gsdl_cgi->generate_ok_message($result);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | sub setText
|
---|
| 79 | {
|
---|
| 80 | my $self = shift @_;
|
---|
| 81 | my $collection = $self->{'collect'};
|
---|
| 82 | my $site = $self->{'site'};
|
---|
| 83 | my $docId = $self->{'d'};
|
---|
| 84 | my $newtext = $self->{'newtext'};
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | 1; |
---|