forked from os-autoinst/os-autoinst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocr.pm
31 lines (26 loc) · 798 Bytes
/
ocr.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright 2009-2013 Bernhard M. Wiedemann
# Copyright 2012-2020 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later
package ocr;
use Mojo::Base -strict, -signatures;
require IPC::System::Simple;
sub tesseract ($img, $area) {
my $imgfn = 'ocr.png';
my $txtfn = 'ocr'; # tesseract appends .txt automatically o_O
my $txt;
if ($area) {
$img = $img->copyrect($area->{xpos}, $area->{ypos}, $area->{width}, $area->{height});
}
$img->write($imgfn);
# disable debug output, because new versions by default only reports errors and warnings
system("tesseract $imgfn $txtfn quiet");
$txtfn .= '.txt';
open(my $fh, '<:encoding(UTF-8)', $txtfn);
local $/;
$txt = <$fh>;
close $fh;
unlink $imgfn;
unlink $txtfn;
return $txt;
}
1;