File Coverage

ocr.pm
Criterion Covered Total %
statement 6 25 24.0
total 6 25 24.0


line stmt code
1   # Copyright 2009-2013 Bernhard M. Wiedemann
2   # Copyright 2012-2020 SUSE LLC
3   # SPDX-License-Identifier: GPL-2.0-or-later
4    
5   use Mojo::Base -strict, -signatures;
6 30 require IPC::System::Simple;
  30  
  30  
7   use autodie ':all';
8 30  
  30  
  30  
9   my $imgfn = 'ocr.png';
10 0 my $txtfn = 'ocr'; # tesseract appends .txt automatically o_O
  0  
  0  
  0  
11 0 my $txt;
12 0  
13 0 if ($area) {
14   $img = $img->copyrect($area->{xpos}, $area->{ypos}, $area->{width}, $area->{height});
15 0 }
16 0  
17   $img->write($imgfn);
18   system('tesseract', $imgfn, $txtfn);
19 0 $txtfn .= '.txt';
20 0 open(my $fh, '<:encoding(UTF-8)', $txtfn);
21 0 local $/;
22 0 $txt = <$fh>;
23 0 close $fh;
24 0 unlink $imgfn;
25 0 unlink $txtfn;
26 0 return $txt;
27 0 }
28 0  
29   1;