I’m trying and failing to use tesseract php. I get this error:
Fatal error: Uncaught thiagoalessioTesseractOCRTesseractNotFoundException: Error! The command "tesseract" was not found. Make sure you have Tesseract OCR installed on your system: https://github.com/tesseract-ocr/tesseract
The current $PATH is C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:WindowsSystem32OpenSSH;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program FilesNVIDIA CorporationNVIDIA NvDLISR;C:xamppphp;C:ProgramDataComposerSetupbin;C:UsersPeppeAppDataLocalMicrosoftWindowsApps;C:UsersPeppeAppDataRoamingComposervendorbin in C:UsersPeppevendorthiagoalessiotesseract_ocrsrcFriendlyErrors.php:48 Stack trace: #0
C:UsersPeppevendorthiagoalessiotesseract_ocrsrcTesseractOCR.php(26): thiagoalessioTesseractOCRFriendlyErrors::checkTesseractPresence('tesseract') #1 C:xampphtdocsindex.php(7): thiagoalessioTesseractOCRTesseractOCR->run() #2 {main} thrown in C:UsersPeppevendorthiagoalessiotesseract_ocrsrcFriendlyErrors.php on line 48
I’m using windows 10 with xampp installed in C:xampp. php version 7.4
I installed tesseract.exe from https://github.com/UB-Mannheim/tesseract/wiki both x32 and x64
I used composer to install the https://github.com/thiagoalessio/tesseract-ocr-for-php and it gave no error.
<?php
require_once 'C:UsersPeppevendorautoload.php';
use thiagoalessioTesseractOCRTesseractOCR;
$ocr = new TesseractOCR("caption.jpg");
$content = $ocr->run();
echo $content;
?>
finally, the caption.jpg is in the htdocs folder, the main folder and same folder as index.php where the aforementioned code appears.
any solutions?
3
Answers
I found the answer: the $PATH variable is taken from Windows. To set it right search for "system environment variables", click "environment variables", edit PATH and add the tesseract software folder, for example C:Program FilesTesseract-OCR
In my case I have to add new variable
tesseract
with full pathC:Program FilesTesseract-OCRtesseract.exe
as showing in below screenshotTo install TESSERACT OCR and use it in PHP
You must perform the following steps:
(in my explanation, I assume you are on windows)
url src = https://tesseract-ocr.github.io/tessdoc/Installation.html
1- Download the TESSERACT software from URL:
https://github.com/UB-Mannheim/tesseract/wiki
2- From your composer, you must install:
url: https://packagist.org/packages/thiagoalessio/tesseract_ocr
composer require thiagoalessio/tesseract_ocr
3- Then, it is important to do things in the following order:
Your TESSERACT software (step 1) is installed in a directory
which will certainly be (it’s up to you to check in your system)
folder = C:Program FilesTesseract-OCR
It is absolutely necessary to add this folder in the windows environment variables at the PATH level (user and system)
4- Then you restart your web environment (WAMP, LARAGON …)
5- Verification that TESSERACT is operational.
Go to your CMD and write:
tesseract –version
6- Operation test from a PHP script
uses an image on a white background with text