我使用的是windows应用程序tesseract,长话短说这是一个通过命令运行的OCR应用程序。
安装应用程序后,我使用命令进行了测试,并使用下面这行代码正常工作:
tesseract text.png out
它实际上获得了图像并输出到文本文件out.txt
我甚至更改了目录,可以从任何地方访问。
现在问题来了,当我使用php时,我使用的代码如下:
echo exec("tesseract text.png out 2>&1", $output);
var_dump($output);
这一次,它没有得到文件,而是说tesseract不被识别!
这是输出:
operable program or batch file.
C:\wamp64\www\prestashop\ocr\ocr.php:12:
array (size=4)
0 => string '' (length=0)
1 => string 'C:\wamp64\www\prestashop\ocr>tesseract text.png out' (length=51)
2 => string ''tesseract' is not recognized as an internal or external command,' (length=65)
3 => string 'operable program or batch file.' (length=31)
谁能帮帮我!?
谢谢
发布于 2016-07-28 08:13:26
我有答案了。我不知道为什么,但我不得不重新启动电脑,让它与PHP一起工作
发布于 2016-07-28 08:34:11
似乎未设置windows环境变量PATH
。
尝试重置PATH
echo exec("PATH %PATH% && tesseract text.png out 2>&1", $output);
var_dump($output);
或从父会话设置PATH
值
echo exec("PATH ".getenv('PATH')." && tesseract text.png out 2>&1", $output);
var_dump($output);
希望这能有所帮助
https://stackoverflow.com/questions/38630079
复制