source: main/trunk/greenstone2/perllib/cgiactions/ocraction.pm@ 23769

Last change on this file since 23769 was 23769, checked in by davidb, 13 years ago

Support for using a command-line OCR program. Experimental. Currently only written for Windows

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1package ocraction;
2
3use strict;
4
5use cgiactions::baseaction;
6
7use dbutil;
8use ghtml;
9
10
11BEGIN {
12# unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
13 require XML::Rules;
14}
15
16
17@ocraction::ISA = ('baseaction');
18
19my $action_table =
20{
21 "preformOcr" => { 'compulsory-args' => [ "d", "imagename" ],
22 'optional-args' => [] },
23 "setText" => { 'compulsory-args' => [ "d", "newtext" ],
24 'optional-args' => [] }
25};
26
27sub 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
37sub 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
78sub 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
871;
Note: See TracBrowser for help on using the repository browser.