如何在 wamp 服务器上使用 Tesseract PHP 包装器

How to use Tesseract PHP wrapper on wamp server

我使用 composer 安装了这个 Tesseract PHP 包装器:https://github.com/thiagoalessio/tesseract-ocr-for-php 通过直接从位于 C:/wamp/www/project_folder 的 php 项目文件夹中键入以下命令行:

$ composer require thiagoalessio/tesseract_ocr

我在尝试使用 tesseract 的同一文件夹中创建了一个名为 php 的文件 'new':

use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('text.png'))
->run();

我收到以下错误:

Fatal error: Class 'thiagoalessio\TesseractOCR\TesseractOCR' not found in C:\wamp\www\project_folder\new.php on line 4

这是我的项目文件夹的内容:

   vendor(a folder)
   composer.json 
   composer.lock
   new.php 
   test.png 

我有 wampserver 2.5 版 我已经在 C:program 个文件中安装了 tesseract(版本 4) 我将以下代码包含到我的 php 文件中以设置路径但仍然遇到错误。

$path = getenv('PATH');
putenv("PATH=$path:C:\Program Files\Tesseract_OCR");

new.php 是否包含 autoload.php 的包含?您很可能必须在该文件的顶部添加 require_once __DIR__ . '/vendor/autoload.php';

我解决了这个问题,首先按照 Nico Haase 的建议使用更新版本的 PHP,然后将我的 php 文件放在与 tesseract 可执行文件相同的路径上。