skip to Main Content

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


  1. Chosen as BEST ANSWER

    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


  2. In my case I have to add new variable tesseract with full path C:Program FilesTesseract-OCRtesseract.exe as showing in below screenshot

    enter image description here

    Login or Signup to reply.
  3. To 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

    Reply somethink like that :
    tesseract v5.3.0.20221222
    leptonica-1.78.0
    libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.0
    Found AVX2
    Found AVX
    Found FMA
    Found SSE4.1
    Found libarchive 3.5.0 zlib/1.2.11 liblzma/5.2.3 bz2lib/1.0.6 liblz4/1.7.5 libzstd/1.4.5
    Found libcurl/7.77.0-DEV Schannel zlib/1.2.11 zstd/1.4.5 libidn2/2.0.4 nghttp2/1.31.0
    

    6- Operation test from a PHP script
    uses an image on a white background with text

    <?php
    
        $app_class = 'thiagoalessioTesseractOCRTesseractOCR';
        $file = 'C:/Users/admin/Desktop/im2.jpg';
        
        $class = new ReflectionClass($app_class);
        $infoImg = $class->newInstanceArgs();
        $infoImg->lang('eng','jpn','spa','fr');
        $infoImg->image($file);
        $infoImg->withoutTempFiles();
        $resultat = $infoImg->run();
        var_dump($resultat);
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search