|
Revision 133, 1.9 kB
(checked in by decoder, 1 year ago)
|
Added License tags too all code files
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
package FuzzyOcr::Preprocessor; |
|---|
| 19 |
|
|---|
| 20 |
sub new { |
|---|
| 21 |
my ($class, $label, $command, $args) = @_; |
|---|
| 22 |
|
|---|
| 23 |
bless { |
|---|
| 24 |
"label" => $label, |
|---|
| 25 |
"command" => $command, |
|---|
| 26 |
"args" => $args |
|---|
| 27 |
}, $class; |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
sub run { |
|---|
| 31 |
my ($self, $input) = @_; |
|---|
| 32 |
my $tmpdir = FuzzyOcr::Config::get_tmpdir(); |
|---|
| 33 |
my $label = $self->{label}; |
|---|
| 34 |
my $output = "$tmpdir/prep.$label.out"; |
|---|
| 35 |
my $stderr = ">$tmpdir/prep.$label.err"; |
|---|
| 36 |
|
|---|
| 37 |
my $stdin = undef; |
|---|
| 38 |
my $stdout = undef; |
|---|
| 39 |
my $args = $self->{args}; |
|---|
| 40 |
my $rcmd = $self->{command}; |
|---|
| 41 |
|
|---|
| 42 |
if (defined $args) { |
|---|
| 43 |
$rcmd .= ' ' . $args; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
if(defined $args and $args =~ /\$input/) { |
|---|
| 48 |
$rcmd =~ s/\$input/$input/; |
|---|
| 49 |
} else { |
|---|
| 50 |
$stdin = "<$input"; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
if(defined $args and $args =~ /\$output/) { |
|---|
| 55 |
$rcmd =~ s/\$output/$output/; |
|---|
| 56 |
} else { |
|---|
| 57 |
$stdout = ">$output"; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
my $retcode = FuzzyOcr::Misc::save_execute($rcmd, $stdin, $stdout, $stderr); |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
return $retcode; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
1; |
|---|