PHP / Laravel-Tesseract OCR-文件的完整路径

时间:2018-12-14 14:42:10

标签: php laravel tesseract

我已经在我的Forge服务器上成功安装了tesseract OCR和Imagick。但是,当我尝试读取图像时,出现以下错误:

这是错误:

Error! The image "/home/forge/domain.com/storage/app/temp_files/ocrtotext_ijP1II9th2.jpeg" was not found.

The current __DIR__ is /home/forge/domain.com/vendor/thiagoalessio/tesseract_ocr/src

这是我的代码:

 $text = (new TesseractOCR(storage_path() . '/app/temp_files/'.$imageName.'.jpeg'))
        ->lang('eng')
        ->psm($psm)
        ->run();


        return $text;

我在做什么错?为什么tesseract在/vendor/文件夹中而不在我的storage/..文件夹中查找?

1 个答案:

答案 0 :(得分:1)

如果您检查https://github.com/thiagoalessio/tesseract-ocr-for-php/blob/ea31d13143683c1b76e622f2b76be4c3e2e6c1af/src/FriendlyErrors.php上的代码

您会看到:

public static function checkImagePath($image)
{
    if (file_exists($image)) return;
    $currentDir = __DIR__;
    $msg = array();
    $msg[] = "Error! The image \"$image\" was not found.";
    $msg[] = '';
    $msg[] = "The current __DIR__ is $currentDir";
    $msg = join(PHP_EOL, $msg);
    throw new ImageNotFoundException($msg);
}

如您所见,TesseractOCR使用功能file_exists

此函数返回false,表示您设置了错误的文件路径,或者符号链接断开,或者用户(Apache?)无法访问该文件,或其他原因。