4

我在我的 Windows 上使用 Xampp。我想在 PHP 中使用 Tesseract OCR

我的 tesseract 安装在

C:/Program Files/Tesseract OCR/

和 Xampp 安装在

C:/xampp/

M 使用此代码执行我的 php 中的 teseract

exec("tesseract test.png test.txt");

但它不起作用...

请给我工作代码。

4

6 回答 6

3

你的exec功能应该是

exec("tesseract.exe test.png test.txt");

您缺少 tesseract 上的 .exe 扩展名。我刚刚犯了同样的错误!

此外,您的 tesseract 也应该安装在您的 xampp 服务器上。

于 2013-10-24T01:19:48.653 回答
0

答复为时已晚。但希望能帮助其他人。代码是:

shell_exec('"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract" "F:\\WebApp5\\htdocs\\imgtotext\\images\\'.$file_name.'" out');

这里 shell_exec('"你的 tesseract 文件位置" "你的图像位置" file_name'). 谢谢。

于 2021-09-02T03:31:31.190 回答
0
#Debes tener eng.traineddata y el tesseract.exe en la carpeta prueba#
//este codigo funciona en el servidor local
<?php 
$imagen = file_get_contents('http://e-consultaruc.sunat.gob.pe/cl-ti-
itmrconsruc/captcha?accion=image');
file_put_contents('C:\AppServ\www\Sitio AAA\Prueba\foto.jpg', $imagen);
exec("tesseract.exe foto.jpg mitexto2.txt");
?>
<form action="obtener_imagen_captcha.php" method="post">
<input type="submit" value="Aceptar">
</form>
于 2017-06-06T04:53:05.227 回答
0

这是一个很好的教程。
https://chillyfacts.com/convert-image-to-text-optical-character-recognition-ocr-using-php/

这里的代码对我有用:

    <?php
    shell_exec('"C:\\Program Files\\Tesseract-OCR\\tesseract" "example_image.PNG" out');
    ?>

(第 1 部分)这里是对这段代码的第一部分的解释,它定义了 Tesseract 的安装目录。因此,根据您的计算机文件更改目录。

(Part 1)
"C:\\Program Files\\Tesseract-OCR\\tesseract"

(第 2 部分)代码的第二部分定义了图像文件的目录。shell_exec()因此,在我的情况下,具有该函数的 php 文件与我拥有图像文件的目录相同example_image.PNG。如果您的图像有不同的目录,则可以这样定义C:\\xampp\\htdocs\\images\\example_image.PNG

(Part 2)
"example_image.PNG"

(第 3 部分)第三部分定义输出文本文件的文件名。

(Part 3)
out
于 2019-03-30T22:30:44.887 回答
0

一个比放到命令执行器更好的解决方案是这个包装器-> https://github.com/thiagoalessio/tesseract-ocr-for-php

如果您不想使用作曲家,我在这里发布了一些代码来规避这个问题,只需搜索没有作曲家的 php tesseract。

在撰写本文时,我可以验证包装器至少可以工作到 PHP 8.0.13。

于 2022-02-10T08:01:40.197 回答
-1

检查前请

运行cmd管理员

tesseract

如果显示信息

将您的 test.png 复制到桌面并运行此代码

cd %userprofile%\desktop
tesseract test.png test
于 2014-10-01T17:42:48.800 回答