php错误!没有找到命令“”,

j1dl9f46  于 2023-02-07  发布在  PHP
关注(0)|答案(3)|浏览(218)

我正在尝试使用tesseract php,但失败了。我得到这个错误:

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

我使用的是Windows 10,xampp安装在C:\xampp.php版本7.4中,我从https://github.com/UB-Mannheim/tesseract/wiki安装了tesseract.exe,x32和x64,我使用composer安装了https://github.com/thiagoalessio/tesseract-ocr-for-php,它没有出现错误。

<?php
require_once 'C:\Users\Peppe\vendor\autoload.php';  

use thiagoalessio\TesseractOCR\TesseractOCR;
$ocr = new TesseractOCR("caption.jpg");
$content = $ocr->run();
echo $content;

?>

最后,caption.jpg位于htdocs文件夹,主文件夹和index.php所在的文件夹中,上面提到的代码出现在该文件夹中。
有什么解决办法吗?

b91juud3

b91juud31#

我找到了答案:$PATH变量取自Windows。要正确设置它,请搜索"系统环境变量",单击"环境变量",编辑PATH并添加tesseract软件文件夹,例如C:\Program Files\Tesseract-OCR

qco9c6ql

qco9c6ql2#

在我的例子中,我必须添加新变量tesseract,其完整路径为C:\Program Files\Tesseract-OCR\tesseract.exe,如下图所示

yacmzcpb

yacmzcpb3#

安装TESSERACT OCR并在PHP中使用它
您必须执行以下步骤:(在我的解释中,我假设您使用的是Windows)url src = https://tesseract-ocr.github.io/tessdoc/Installation.html
1-从以下URL下载TESSERACT软件:https://github.com/UB-Mannheim/tesseract/wiki
2-在编写器中,必须安装:url:https://packagist.org/packages/thiagoalessio/tesseract_ocr composer 需要thiagoalessio/镶嵌_ocr
3-然后,按以下顺序执行操作很重要:您的TESSERACT软件(步骤1)安装在一个目录中,该目录肯定是(由您检查您的系统)folder = C:\Program Files\Tesseract-OCR

    • 绝对有必要将此文件夹添加到PATH级别(用户和系统)的Windows环境变量中**

4-然后重新启动Web环境(WAMP、LARAGON ...)
5-验证TESSERACT是否可操作。转到CMD并写入:立方体版本

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-PHP脚本中的操作测试使用白色背景上的图像和文本

<?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);
?>

相关问题