我正在使用Postman将base64映像发送到我的Apache Web服务器上的PHP文件。图像始终成功发送。 PHP脚本执行python脚本以从图像中提取文本(使用Pytesseract/Tesseract-OCR)并将输出发送回PHP。 (使用Windows 10,如果有的话)PHP无法通过shell_exec()执行Python中的Pytesseract()
前两个打印语句总是在Postman中返回,但第三个和第四个打印语句不返回。仅当pytesseract行被注释掉时,最后的打印语句才会返回。
当我自己运行python脚本时,所有的打印语句都成功返回。
的Python(test.py)
from PIL import Image
import pytesseract
import sys
print "Print 1"
print "Print 2"
filename = "test.jpg"
#filename = sys.argv[1]
text = pytesseract.image_to_string(Image.open("Images/"+filename))
print text
#Final print statement appears on POSTMAN only if the tesseract code does not run
a = "Print"
b = 1+2
print a, b
PHP(connection.php)
<?php
header('Content-type : bitmap; charset=utf-8');
if(isset($_POST["encoded_string"])){
$encoded_string = $_POST["encoded_string"];
$device_name = $_POST["device_name"];
/*$image_name = $device_name.'.jpg';*/
$image_name = "test.jpg";
$decoded_string = base64_decode($encoded_string);
$path = 'images/'.$image_name;
$file = fopen($path, 'wb');
$is_written = fwrite($file, $decoded_string);
fclose($file);
$extracted = shell_exec("python test.py $image_name");
echo $extracted;
}
else {
echo "Failed :(";
}
?>
我相信问题是能够运行python脚本,但Python脚本不能当PHP执行它时执行tesseract。
请问,如果你在命令行手动运行Python文件(如相同的用户PHP)的工作? –
@CharlotteDunois是的! – 0248881
有人可以真正帮助解决这个问题吗? – 0248881