PHP Unable to execute Pytesseract in Python via shell_exec() -
i using postman send base64 image php file on apache web-server. image sent successfully. php script executes python script extract text image (using pytesseract/tesseract-ocr) , sends output php. (using windows 10, if matters)
the first 2 print statements returned in postman third , fourth print statements not return. last print statement returns when pytesseract line commented out.
when run python script itself, print statements return successfully.
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 if tesseract code not run = "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 :("; } ?>
i believe problem able run python script python script isn't able execute tesseract when has been executed php.
hopefully you're still on it, found solution here ! add theses lines in php script, , work:
$path = getenv('path'); putenv("path=$path:/usr/local/bin");
Comments
Post a Comment