4

I had clone git library of OCR using this link .

git clone git://github.com/thiagoalessio/tesseract-ocr-for-php.git

then simply i include the required file by following this example

here is the example code which i m trying to run

require_once './src/TesseractOCR.php';
$tesseract = new TesseractOCR('text.png');
$text = $tesseract->recognize();
echo "The recognized text is:", $text;

But always it fires a fatal Error

Fatal error: Uncaught Error: Call to undefined method TesseractOCR::recognize()

Edit I tried to use run() instead of recognize()

require_once './src/TesseractOCR.php';
$tesseract = new TesseractOCR('text.png');
$text = $tesseract->run();
var_dump($text);
echo PHP_EOL, "The recognized text is:", $text, PHP_EOL;

Then result is : string(0) "" The recognized text is:

I had tried my best to find some appropriate solution but failed to find some authentic solution

Sami
  • 8,168
  • 9
  • 66
  • 99
Hassan ALi
  • 1,313
  • 1
  • 23
  • 51
  • There does not seem to be a `recognize()` function in that class. What happens when you add `var_dump($tesseract)` after this line: `$tesseract = new TesseractOCR('text.png');` – Maximus2012 Aug 24 '16 at 15:50
  • Try `run()` in place of `recognize()` and see if that works. There is a documentation here: https://github.com/thiagoalessio/tesseract-ocr-for-php – Maximus2012 Aug 24 '16 at 15:51
  • $tesseract i had var_dump this instance of class is available . And run is also is function . But run did give me any result as per exception. – Hassan ALi Aug 24 '16 at 15:58
  • In that case, maybe the library is not able to recognize the text in the png file. You might wanna try the updated code with some other png files and see if that works. – Maximus2012 Aug 24 '16 at 16:00
  • sure give me a mint thanks @Maximus2012 – Hassan ALi Aug 24 '16 at 16:01
  • @Maximus2012 still the same result .its giving a empty string in return. – Hassan ALi Aug 24 '16 at 16:02
  • Instead of using `new TesseractOCR('text.png');` try `new TesseractOCR('http://www.ghulmil.com/wp-content/uploads/2009/08/beautiful-black-text-wallpaper-for-computer.jpg');` it will confirm if the fault is in file path – Sami Aug 24 '16 at 16:12
  • still empty result . @Sami – Hassan ALi Aug 24 '16 at 16:17
  • What's your TesseractOCR version? – Jakub Matczak Aug 24 '16 at 16:22
  • "version": "1.0.0-RC" with "license": "Apache-2.0", . – Hassan ALi Aug 24 '16 at 16:24
  • You're talking about `tesseract-ocr-for-php` package, that is just a PHP wrapper, I ask about TesseractOCR itself (a program written in c++ that you installed in your OS). – Jakub Matczak Aug 24 '16 at 16:26
  • sorry i couldn't find it – Hassan ALi Aug 24 '16 at 16:29
  • execute `tesseract -v` in command line/terminal/bash/shell/whatever :) – Jakub Matczak Aug 24 '16 at 16:33
  • do i need to install its binary too ? if yes then please provide me the binary link . Thanks – Hassan ALi Aug 24 '16 at 16:35
  • First line in installation instructions on package's page: `First of all, make sure you have Tesseract OCR installed. (v3.03 or greater)` ;-) Go here: https://github.com/tesseract-ocr/tesseract/wiki – Jakub Matczak Aug 24 '16 at 16:58
  • your second edit works fine.It prints text result output in a file called "stdout.txt" in same directory as php file in my case instead of returning in var $text. – Dashrath May 04 '18 at 11:31

1 Answers1

2

This sample code probably comes from this article or some similar. But I can see that it's over 1,5 year old and apparently it's outdated.

Take a look at their github's page. It looks like it's run() instead of recognize() right now:

<?php
echo (new TesseractOCR('german.png'))
    ->run();
Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64