doupian6118 2013-06-04 21:57
浏览 125
已采纳

如何在WAMP服务器上安装Tesseract OCR,由PHP运行?

I am attempting to install the OCR software Tesseract onto my WAMP server so that I can then automate the OCR process for some images. When I search for how to install software onto a WAMP server, all I get back is how to install a WAMP server so that route turned up no answers. I have successfully installed Tesseract on my computer and know that the files I am using work properly, my issue is that I am unable to run Tesseract from a PHP script. I used the Windows installer that is provided and installed it to my www directory in WAMP. I then attempted to use the PHP exec() to perform some OCR and got no output. This is my simple script:

<?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);
?>

The image is being saved correctly. I can change the positions in the imagecopyresampled() and the image is changed accordingly. I suspect my problem is with the installation since everywhere I look everyone says to use exec() just like I would from a command line. I have also tried specifying the command like Tesseract-OCR/tesseract.exe temp.jpg out. The Tesseract-OCR folder is in the same directory as my PHP script. I admit to being new to this, so please bear with me if there is something simple I've overlooked. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • duanlang1196 2013-10-07 22:08
    关注

    what do you mean by "successfully installed Tesseract" ? how did you verify that? can you run tesseract.exe -v and get proper in command line (or however you call CMD on windows these days)?

    if this works, than make sure that you get the same results by doing this via php:

    make sure that you have errors turned on: error_reporting(-1) and check if you are getting any errors. than try if you actually can execute tesseract via php by:

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

    (shell_exec returns the all output, compare to exec what returns just the last line)

    if that works, than try setting absolute path while extracting:

    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
    

    if nothing helps, than share your results/errors.

    last hint: try to install linux

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目
  • ¥30 海外项目,如何降低Google Map接口费用?
  • ¥15 fluentmeshing
  • ¥15 手机/平板的浏览器里如何实现类似荧光笔的效果
  • ¥15 盘古气象大模型调用(python)
  • ¥15 传人记程序做的plc 485从机程序该如何写
  • ¥15 已知手指抓握过程中掌指关节、手指各关节和指尖每一帧的坐标,用贝塞尔曲线可以拟合手指抓握的运动轨迹吗?
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部