I am using Postman to send a base64 image to the PHP file on my Apache web-server. The image is always sent successfully. The PHP script executes a python script to extract text from the image (Using Pytesseract/Tesseract-OCR) and sends the output back to PHP. (Using Windows 10, if that matters)
The first two print statements are always returned in Postman but the third and fourth print statements do not return. The last print statement returns only when the pytesseract line is commented out.
When I run the python script by itself, all 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 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 :(";
}
?>
I believe the problem is able to run the python script but the python script isn't able to execute tesseract when it has been executed by PHP.