0

I have been trying to work this out for a couple days now and can't crack it.

I'm trying to use php to echo the result of tesseract.

After everything I've researched and tried, I feel like the below code should work.

<?php

echo '<pre>';
echo exec('/usr/local/bin/tesseract /home/username/www/ocr/images/hello.png result');
echo '</pre>';

?>

The command runs fine via SSH and if I change the above to suit ifconfig it works fine.

Any ideas to get this working?

McDan Garrett
  • 183
  • 1
  • 3
  • 15
  • What does the reference to ifconfig do in there? – arkascha Jan 12 '15 at 06:34
  • You checked file permissions to the executable and the subject file and to all levels above@ Note that php typical is executed under a different account than when connect via ssh. – arkascha Jan 12 '15 at 06:36
  • If I run the above code, but with ifconfig replacing tesseract, then it gives me a nice array with all the usual ifconfig information. So I know exec is working. But, that second comment you made is interesting, maybe tesseract needs to have it's permissions changed. – McDan Garrett Jan 12 '15 at 06:36
  • 1
    You should add error handling to know what is going on. Especially take care to consider the error output of the command. Use the famous 2>&1 for that! – arkascha Jan 12 '15 at 06:38
  • I've added `2>&1` and now I get `Tesseract Open Source OCR Engine v3.02.02 with Leptonica` so that's awesome. Now I just have to get the result not be saved in a text file, instead to be echo'd. – McDan Garrett Jan 12 '15 at 06:41
  • Hm? I understood from your initial question that things work as required when you are executing directly via ssh. Now you say things do not work but you have to redirect the output? – arkascha Jan 12 '15 at 10:42
  • http://stackoverflow.com/questions/24347819/can-tesseract-ocr-put-the-result-to-stdout – arkascha Jan 12 '15 at 10:44

3 Answers3

0

You could try cat-ing the result as a 2nd command once tesseract is done. shell_exec appears to be better at returning the full output vs. exec.

<?php

$res = shell_exec('/opt/local/bin/tesseract /Users/stressederic/Sites/Sandbox/OCR/CC/gold.jpg result && cat result.txt');
var_dump($res);
PorridgeBear
  • 1,183
  • 1
  • 12
  • 19
0

I ended up getting this working by just breaking everything down.

file_put_contents("$tmpFile",file_get_contents($img));
$cmd = "/usr/local/bin/tesseract $tmpFile stdout";
exec($cmd, $msg);
$arraymsg = $msg;
$msg = implode(' ', $msg);
echo $msg;
McDan Garrett
  • 183
  • 1
  • 3
  • 15
0

its work

var_dump(exec('/usr/bin/tesseract 6.png out1 -l eng+ara'));

or

var_dump(shell_exec('/usr/bin/tesseract 6.png out1 -l eng+ara'));

tip:

in laravel => 6.png Into the folder public

lang=> eng or ara are language
Netwons
  • 1,170
  • 11
  • 14