如何在 PHP 中使用 Tesseract OCR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18965275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:35:42  来源:igfitidea点击:

How To Use Tesseract OCR In PHP

phptesseract

提问by user2424807

I Am Using Xampp On My Windows. I Wanted To Usen Tesseract OCR In PHP

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

my tesseract installed in

我的tesseract安装在

C:/Program Files/Tesseract OCR/

And Xampp Installed In

和 Xampp 安装在

C:/xampp/

M Using This Codes To exec The teseract in my php

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

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

But its not working...

但它不工作...

Please Give Me Working Codes.

请给我工作代码。

回答by Nicolas Raoul

There is a library for this: TesseractOCR for PHP

有一个库: TesseractOCR for PHP

https://github.com/thiagoalessio/tesseract-ocr-for-php

https://github.com/thiagoalessio/tesseract-ocr-for-php

It is open source.

它是开源的。

回答by Bpainter

Your execfunction should be

你的exec功能应该是

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

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

You're missing the .exe extension on tesseract. I just made the same mistake!

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

Also, your tesseract should be installed on your xampp server as well.

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

回答by user8117530

#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>

回答by Bhaskar Paneri

This is a nice tutorial here.
https://chillyfacts.com/convert-image-to-text-optical-character-recognition-ocr-using-php/

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

This code here works for me:

这里的代码对我有用:

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

(Part 1) Here is the explanation to The first part of this code defines the directory where Tesseract is installed. So change the directory based on your computer file.

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

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

(Part 2) The second part of the code defines the directory for the image file. So in my case the php file with the shell_exec()function is the same directory where I have the image file example_image.PNG. If you have a different directory for your image it can be defined like this C:\\xampp\\htdocs\\images\\example_image.PNG

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

(Part 2)
"example_image.PNG"

(Part 3) The third part defines the filename for the output text file.

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

(Part 3)
out

回答by zertel

Before check please

检查前请

run cmd administrator

运行cmd管理员

tesseract

If the information is displayed

如果显示信息

copy your test.png to desktop and run this code

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

cd %userprofile%\desktop
tesseract test.png test