【问题标题】:How do I install Tesseract OCR onto WAMP server, to be run by PHP?如何将 Tesseract OCR 安装到 WAMP 服务器上,由 PHP 运行?
【发布时间】:2013-06-05 05:57:56
【问题描述】:

我正在尝试将 OCR 软件 Tesseract 安装到我的 WAMP 服务器上,以便我可以自动执行某些图像的 OCR 过程。当我搜索如何在 WAMP 服务器上安装软件时,我得到的只是如何安装 WAMP 服务器,这样路由就没有答案了。我已经在我的计算机上成功安装了 Tesseract,并且知道我正在使用的文件可以正常工作,我的问题是我无法从 PHP 脚本运行 Tesseract。我使用了提供的 Windows 安装程序并将其安装到 WAMP 中的 www 目录中。然后我尝试使用 PHP exec() 执行一些 OCR,但没有得到任何输出。这是我的简单脚本:

<?php
    $path = getenv('PATH');
    putenv("PATH=$path:/usr/local/bin");
    $src = 'a.jpg';
    $srcImg = imagecreatefromjpeg($src);

    $img = imagecreatetruecolor($newClanWidth, $newHeight);
    imagecopyresampled($img, $srcImg, 0, 0, $positions["aPlayer"], $positions[0], $newClanWidth, $newHeight, $clanWidth, $height);
    imagejpeg($img, 'temp.jpg', 100);
    echo '<pre>';
    exec('tesseract temp.jpg out');
    //echo file_get_contents('out.txt');
    echo '</pre>';
    imagedestroy($img);
?>

图像正在正确保存。我可以更改imagecopyresampled() 中的位置,图像也会相应更改。我怀疑我的问题出在安装上,因为我看到每个人都说要使用exec(),就像我在命令行中一样。我也尝试过指定像Tesseract-OCR/tesseract.exe temp.jpg out 这样的命令。 Tesseract-OCR 文件夹与我的 PHP 脚本位于同一目录中。我承认对此很陌生,所以如果我忽略了一些简单的事情,请多多包涵。提前致谢。

【问题讨论】:

    标签: php ocr wampserver tesseract


    【解决方案1】:

    “成功安装 Tesseract”是什么意思? 你是怎么验证的? 你可以运行tesseract.exe -v 并在命令行中正确使用(或者这些天你在 Windows 上调用 CMD)吗?

    如果这可行,那么请确保通过 php 执行此操作获得相同的结果:

    确保您已打开错误:error_reporting(-1) 并检查您是否收到任何错误。 如果你真的可以通过 php 执行 tesseract,不如试试:

    $return = shell_exec('tesseract.exe -v'); // in your example you miss .exe it would be without extension on linux
    var_dump($return);
    

    (shell_exec 返回所有输出,与 exec 比较只返回最后一行)

    如果可行,请尝试在提取时设置绝对路径:

    imagejpeg($img, 'c:/temp.jpg', 100);
    $return = exec('tesseract.exe temp.jpg c:/out');
    var_dump($report); // in case it gives you some errors
    $content = file_get_contents('c:/out.txt');
    if ($content === false) die('something is still wrong');
    // otherwise process $content
    

    如果没有任何帮助,那就分享您的结果/错误。

    最后提示:尝试安装 linux

    【讨论】:

    • 我错过了 exec() 中的 .exe。感谢您指出这一点。
    猜你喜欢
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 1970-01-01
    相关资源
    最近更新 更多