如何从任何位置使用 php 的 tesseract ocr

How to use tesseract ocr with php from any location

我已经在 C:\Program Files (x86)\Tesseract-OCR 中安装了 tesseract。在命令提示符下,如果我使用 tesseract 123.png sample 执行,那么它就可以工作。但是我不能将 tesseractphp 一起使用。我已经尝试了很多库和代码。

有人可以帮我解决这个问题吗?

如果您需要在 php 代码中使用 Tesseract,方法是使用 http://php.net/manual/en/function.exec.php or http://php.net/manual/en/function.shell-exec.php 函数,两者都允许您执行 bash 中的代码,如 [=21] =],但您需要更加注意使用它,这会带来几个安全问题,因为客户端输入的数据有时是恶意的。希望对您有所帮助!

一个工作示例:

exec("tesseract C:/your/path/file.png C:/output/file");    

另一件事,在 C:/output/file 部分,您不需要将 .txt 放在输出路径中,tesseract 始终将输出作为 .txt 文件扩展名。

如果 "Environment Variables" 上不存在 Tesseract,解决方案是传递完整的可执行文件路径:

shell_exec('"C:/Program Files (x86)/Tesseract-OCR/tesseract.exe" C:/path/to/image C:/output/path/')