我正在使用这作为ocr。这是Tesseract ocr的包装器(我已经安装了Tesseract本身)。
一开始,我通过composer下载了它,并遵循了repo中的例子,以及关于它本身的几个帖子。所有能显示的都是在网络标签failed to load response data
中。
我的另一种方法是尝试下载repo本身,然后尝试从我的index.php
调用它,为了测试目的,它位于TesseractOCR
类所在的文件夹中。我试过在回购中使用图像,也尝试在白色背景图像上使用黑色字母,使用简单的文本。
这是如此帖子看上去很有希望,但我不确定OP的示例代码文件在哪里.
use thiagoalessio\TesseractOCR\TesseractOCR;
//or//require "TesseractOCR.php";//if it's in the same dir as test.php
$content = new TesseractOCR('text.png');
$text = $content->run();
echo $text;
我错过什么明显的东西了吗?任何帮助都是非常感谢的。
EDIT1:我尝试在win powershell cli中使用。通过将text.png
放在安装了tesseract的目录中,然后使用管理员权限调用shell,然后输入tesseract text.png output
,这将在同一个目录中创建带有该映像中可识别文本的output.txt
。所以tesseract起作用了,我用php包装器实现的不是。
EDIT2:忘记添加,页面本身显示:
This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
不知道为什么会这样。
Edit3:
我的代码:
try{
//use thiagoalessio\TesseractOCR\TesseractOCR;
require "./vendor/thiagoalessio/tesseract_ocr/src/TesseractOCR.php";
echo $temp;//It's value is set in TesseractOCR.php
$content = new TesseractOCR('text1.png');
$text = $content->run();
echo $text;
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
$temp
变量中的值集通过状态文件路径可见,那么为什么TesseractOCR
类本身是不可见的呢?
Edit4:,即使我将绝对路径放置到包含类的TesseractOCR.php
,在语句中,它也不起作用。它抛出此错误:
Fatal error: Uncaught Error: Class 'TesseractOCR' not found in C:\xampp\htdocs\myocr\index.php:10 Stack trace: #0 {main} thrown in C:\xampp\htdocs\myocr\index.php on line 10
This is TesseractOCR.//echoed text from file that holds TesseractOCR class.
包容路径:
include ("C:/xampp/htdocs/myocr/vendor/thiagoalessio/tesseract_ocr/src/TesseractOCR.php");
如果我使用(在readme,use thiagoalessio\TesseractOCR\TesseractOCR;
中建议使用),那么它会抛出:
Fatal error: Uncaught Error: Class 'thiagoalessio\TesseractOCR\TesseractOCR' not found in C:\xampp\htdocs\myocr\index.php:10 Stack trace: #0 {main} thrown in C:\xampp\htdocs\myocr\index.php on line 10
我的问题是:它如何命中测试消息,但不会进入TesseractOCR
类?
EDIT5:,如果我是require_once "./vendor/autoload.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:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Users\Eddie\AppData\Local\Microsoft\WindowsApps;;C:\Users\Eddie\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Eddie\AppData\Roaming\npm;C:\Users\Eddie\AppData\Roaming\Composer\vendor\bin;C:\Program Files\heroku\bin in C:\xampp\htdocs\myocr\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php:48 Stack trace: #0 C:\xampp\htdocs\myocr\vendor\thiagoalessio\tesseract_ocr\src\TesseractOCR.php(26): thiagoalessio\TesseractOCR\FriendlyErrors::checkTesseractPresence('tesseract') #1 C:\xampp\ht in C:\xampp\htdocs\myocr\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php on line 48
顺便说一下,我在env变量中添加了它的修补程序:
发布于 2020-11-12 14:01:25
我把它解决了!我的问题是,我不知道php中的自动加载程序。帮助我的链接是这。
我的项目结构是:
然后
然后
然后
我认为这是不言而喻的图像提供。
composer require thiagoalessio/tesseract_ocr
require_once('./vendor/autoload.php');//<-This!
use thiagoalessio\TesseractOCR\TesseractOCR;
$content = new TesseractOCR('text1.png');
$text = $content->run();
echo $text;
这对我有用。需要注意的关键是目录结构。localhost > myocr > index.php
及其代码,在使用composer之后,您将得到供应商dir。而且很满足。新TesseractOCR('text1.png');
中的图像路径是index.php
和图像都位于的目录。
https://stackoverflow.com/questions/64792178
复制相似问题