【问题标题】:Tesseract OCR for PHP blank page用于 PHP 空白页的 Tesseract OCR
【发布时间】:2018-08-09 08:51:14
【问题描述】:

它返回一个空白页。使用 PHP 的 thiagoalessio Tesseract OCR。

Tesseract 安装在我的 Homestead 虚拟机上:

vagrant@xxx-yyy-zzz:/usr/bin$ ./tesseract -v
tesseract 3.04.01

空白页:

use thiagoalessio\TesseractOCR\TesseractOCR;
    class OCRController extends Controller
    {
        public function analyze() {
            echo (new TesseractOCR(asset('storage/text.png')))
                ->executable('/usr/bin/tesseract')->run();
        }
    }

调试 PHP 代码:

use thiagoalessio\TesseractOCR\TesseractOCR;
class OCRController extends Controller
{
    public function analyze() {
        $tesseract = new TesseractOCR(asset('storage/text.png'));
        $tesseract->executable('/usr/bin/tesseract');
        var_dump($tesseract);
    }
}

输出:

/home/vagrant/code/project-io/app/Http/Controllers/OCRController.php:13:
object(thiagoalessio\TesseractOCR\TesseractOCR)[444]
  private 'image' => string 'http://project.test/storage/text.png' (length=38)
  private 'command' => null
  private 'executable' => string '/usr/bin/tesseract' (length=18)
  private 'options' => 
    array (size=0)
      empty

知道http://project.test/storage/text.png实际上是在返回图片。

Tesseract 正在使用命令行:

vagrant@xxx-yyy-zzz:~/code/project-io/public/storage$ tesseract text.png stdout
The quick brown fox
jumps over
the lazy dog.

【问题讨论】:

  • 没有足够的代码 imo。虽然应该分析重新调整一些东西?
  • 当我 var_dump (new TesseractOCR(asset('storage/text.png')))->executable('/usr/bin/tesseract')->run(); 它返回 "Call to a member function executable() on null" 我不明白,因为当我 var_dump() 在可执行方法之前它返回 TesseractOCR 对象

标签: php laravel ocr tesseract


【解决方案1】:

在 PHP 中使用 laravel 和 Tesseract OCR,接收图像路径的TesseractOCR 的构造函数似乎不接受 URL 作为参数。由于asset() 返回图像的 URL,这将不起作用。这应该是一条严格的路径。

$tesseract = new TesseractOCR(asset('storage/app/public/text.png')); // Incorrect

应该是:

$tesseract = new TesseractOCR(storage_path('app/public/text.png')); // Correct

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多