When I execute the script below with python3 ocr-test.py
, it runs correctly:
from PIL import Image
import pytesseract
# If you don't have tesseract executable in your PATH, include the following:
pytesseract.pytesseract.tesseract_cmd = r'/opt/homebrew/bin/tesseract'
# Simple image to string
print(pytesseract.image_to_string(Image.open('receipt1.jpg')))
However, when I excute the below script with python3 ocr-test.py process
, the process/function does not get called and nothing happens:
from PIL import Image
import pytesseract
def process():
# If you don't have tesseract executable in your PATH, include the following:
pytesseract.pytesseract.tesseract_cmd = r'/opt/homebrew/bin/tesseract'
# Simple image to string
print(pytesseract.image_to_string(Image.open('receipt1.jpg')))
Why is this (not) happening?
you need to add
if __name__ == '__main__':
globals()[sys.argv[1]]()
to the bottom of the file.
as explained here.