tesseract-php wrapper having a path error while running on localhost - php

So I am using the tesseract-php wrapper given here https://github.com/thiagoalessio/tesseract-ocr-for-php.
Here's what my php code looks like:
<?php
require_once "vendor/autoload.php";
use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('image1.jpeg'))->run();
?>
On running via cmd, it works just fine. However, while trying to run on xampp server, I'm getting this error
Fatal error: Uncaught thiagoalessio\TesseractOCR\TesseractNotFoundException:
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:\ProgramData\Oracle\Java\javapath;C:\Program Files
(x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program
Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Java\jdk1.8.0_151\bin;C:\Program Files\Git\
in C:\xampp\htdocs\tesseract_project\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php on line 42
I read a few answers here, and turns out adding this would help
$path = getenv('PATH');
putenv("PATH=$path:C:\Program Files (x86)\Tesseract-OCR");
However, there's no change, and I'm still getting the same error. Is there anything I'm doing wrong?

INSTALL TESSERACT IN YOUR SYSTEM THEN Define a custom location of the tesseract executable, if by any reason it is not present in the $PATH.
->executable('/path/to/tesseract')
->run();

Related

php Tesseract Error! The command "tesseract" was not found

I'm trying and failing to use tesseract php. I get this error:
Fatal error: Uncaught thiagoalessio\TesseractOCR\TesseractNotFoundException: 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:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Users\Peppe\AppData\Local\Microsoft\WindowsApps;C:\Users\Peppe\AppData\Roaming\Composer\vendor\bin in C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php:48 Stack trace: #0
C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\TesseractOCR.php(26): thiagoalessio\TesseractOCR\FriendlyErrors::checkTesseractPresence('tesseract') #1 C:\xampp\htdocs\index.php(7): thiagoalessio\TesseractOCR\TesseractOCR->run() #2 {main} thrown in C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.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:\Users\Peppe\vendor\autoload.php';
use thiagoalessio\TesseractOCR\TesseractOCR;
$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?
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 Files\Tesseract-OCR
In my case I have to add new variable tesseract with full path C:\Program Files\Tesseract-OCR\tesseract.exe as showing in below screenshot
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 Files\Tesseract-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 = 'thiagoalessio\TesseractOCR\TesseractOCR';
$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);
?>

How to use tesseract_ocr in PHP?

I find a problem to use tesseract_ocr in php, I follow this tutorial https://github.com/thiagoalessio/tesseract-ocr-for-php.
I install tesseract_ocr use composer :
$ composer require thiagoalessio/tesseract_ocr
this is my folder structure in localhost :
this is mycode :
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
require __DIR__ . "/vendor/autoload.php";
use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('images/8055.PNG'))
->whitelist(range('A', 'Z'))
->run();
?>
</body>
</html>
this is my php version :
and in the browser I get this error :
Fatal error: Uncaught thiagoalessio\TesseractOCR\TesseractNotFoundException: 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:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk1.8.0_73\bin;C:\Users\frank\AppD in C:\xampp\htdocs\ocr\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php on line 48
please anyone help me to solve this problem.
Thanks.
You need to install Tesseract OCR on your pc from here:
https://github.com/tesseract-ocr/tesseract
Then your code should be(just in case you are on windows, C:\Program Files\Tesseract-OCR\tesseract.exe is the path of Tesseract engine):
echo (new TesseractOCR($img_url))
->executable('C:\Program Files\Tesseract-OCR\tesseract.exe')
->whitelist(range('A', 'Z'))
->lang('eng')
->run();
Make sure the tesseract folder is in your path.
If you're unsure what I'm saying, click on the start button and type "edit the system environment variables". Click Environment Variables, under "System variables" click on the line that has "Path" on the far left, and click edit. Click "New" and put in the path to your executable, depending on if you're using the 64 bit or 32 bit version. In my case it was "C:\Program Files\Tesseract-OCR".
You can test this now by opening a new command prompt (if you had an old one open, it won't have the new path variable), and type tesseract and hit enter. You should see:
Usage:
tesseract --help | --help-extra | --version
tesseract --list-langs
tesseract imagename outputbase [options...] [configfile...]
OCR options:
-l LANG[+LANG] Specify language(s) used for OCR.
NOTE: These options must occur before any configfile.
Single options:
--help Show this help message.
--help-extra Show extra help for advanced users.
--version Show version information.
--list-langs List available languages for tesseract engine.
If you do, then it's installed and globally working on your machine now and should work with PHP. If you want to get it working without composer, look up my other answer about that on here.

PHP/Composer include and path-handling

i have got a local installation of xampp with wordpress.
xampp -> htdocs -> mywordpress -> composerproject
content of composerproject
I am using a wordpressplugin to include php in articles of wordpress like this
include('../composerproject/recanalyst/test.php');
Everything works fine on a local maschine with xampp an the same wordpress both are working with php 7.1.
But when i deploy the same on my webspace with following settings:
paths of webspace
define('ROOTPATH', __DIR__);
echo ROOTPATH;
require ROOTPATH . '/vendor/autoload.php';
use RecAnalyst\RecordedGame;
$filename = ROOTPATH . '/test.mgz';
$rec = new RecordedGame($filename);// This line 12 doesnt work
Error line 12
Uncaught Error: Class 'RecAnalyst\RecordedGame' not found in /var/www/vhosts/myhoster.net/httpdocs/recanalyst/test.php:12 Stack trace: #0
Composerproject on github:
enter link description here
Can be closed. My webhoster is running with php 7.1 but their cli was running with 5.3.3. So i had installed with putty an old version of composer without recognizing it. Changing the CLI to 7.1 was the solution.

Failed loading php_xdebug message

When I run php from the command line (on Windows), I receive the following message
Failed loading C:\Users\Nickey K\Documents\AMD APP\bin\x86_64;C:\Users\Nickey K\
Documents\AMD APP\bin\x86;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program F
iles (x86)\AMD APP\bin\x86;C:\Program Files\Common Files\Microsoft Shared\Window
s Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Prog
ram Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C
:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program F
iles (x86)\Calibre2\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files
(x86)\Windows Live\Shared;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-
Static;C:\Program Files (x86)\EasyPHP-12.0\php\php544x120715104042;\php\php544x1
20715104042\php_xdebug-2.2.0-5.4-vc9.dll
x_debug seems to be installed properly based on phpinfo, and I have the following line in php.ini
zend_extension = "C:\Program Files (x86)\EasyPHP-12.0\php\php544x120715104042\php_xdebug-2.2.0-5.4-vc9.dll"
I've put the dll file in both the above the the ...\ext directory and tried a few variants of the above line, but I'm unable to get rid of this error message.
Any ideas?
The regular command line PHP from EasyPHP did not work as is. The problem is EasyPHP replaces the PATH variable with its own. That is just dumb that it doesn't use a different variable.
But, the following worked for me after some experimentations. I created a batch file php5.bat and placed it in C:\Windows\Sytem32 for easier access, with the following code (where C:\Program Files (x86)\EasyPHP-12.1\php\php548x121030011600 is the location my easyPHP php.exe was).
#echo off
REM Set the path for easy PHP and then start PHP.
set OLD_PATH=%PATH%
set PATH=C:\Program Files (x86)\EasyPHP-12.1
set PHP_DIR=C:\Program Files (x86)\EasyPHP-12.1\php\php548x121030011600
call "%PHP_DIR%\php.exe" -c "%PHP_DIR%\php.ini" %*
set PATH=%OLD_PATH%
#echo on
And then calling the batch file php5 -v will give you the php version. You might need to copy some DLLs from the Apache folder into the PHP folder as it will complain the DLLs are not found.
lets try to use zend_extension_tc instead of zend_extension if you're using window.

youtube API - strange issue with ZendGdata

I have installed the ZendGdata PHP library into /var/www/html on my
local fedora machine. I am trying to learn to use the youtube API by
following the instructions at this link
http://code.google.com/apis/gdata/articles/php_client_lib.html
Without any changes to the "include_path", i tried opening
InstallationChecker.php in my browser and i get an exception.
PHP Extension Errors Tested
No errors found
Zend Framework Installation Errors Tested
0 Exception thrown trying to access Zend/Loader.php using
'use_include_path' = true. Make sure you include Zend Framework in
your include_path which currently contains: .:/usr/share/pear:/usr/
share/php
SSL Capabilities Errors Not tested
YouTube API Connectivity Errors Not tested
Ok. Now thats pretty normal. Next, I append the ZendGdata library path
to "include_path" using the below code at the top of InstallationChecker.php
$clientLibraryPath = '/var/www/html/phplibs/ZendGdata/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR .$clientLibraryPath);
Now i get an Servor 500 error when trying to open
InstallationChecker.php in the browser:) thats strange to me. If this is a
permission issue, the page should not have opened before. Right? I
disabled the above 2 lines of code and i get the error previously displayed.
(already shown above)
Any of you faced this issue? thanks in advance guys for your help...
My PHP version is 5.3 if that would help.
For php --ini, i get
[myname#localhost ~]$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed: /etc/php.d/curl.ini,
/etc/php.d/dom.ini,
/etc/php.d/fileinfo.ini,
/etc/php.d/gd.ini,
/etc/php.d/json.ini,
/etc/php.d/mbstring.ini,
/etc/php.d/mcrypt.ini,
/etc/php.d/mysql.ini,
/etc/php.d/mysqli.ini,
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini,
/etc/php.d/sqlite3.ini,
/etc/php.d/wddx.ini,
/etc/php.d/xmlreader.ini,
/etc/php.d/xmlwriter.ini,
/etc/php.d/xsl.ini,
/etc/php.d/zip.ini

Categories