0

I have the code below which if you run it from the command prompt like:

python first_ocr.py --image pyimagesearch_address.png

it runs just fine. but if you run the code itself it gives the error below: usage: first_ocr.py [-h] -i IMAGE first_ocr.py: error: the following arguments are required: -i/–image

How can I pass the image path to this code to be able to run and debug the code.

# USAGE
# python first_ocr.py --image pyimagesearch_address.png
# python first_ocr.py --image steve_jobs.png

# import the necessary packages
import pytesseract
import argparse
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
                help="path to input image to be OCR'd")
args = vars(ap.parse_args())

# load the input image and convert it from BGR to RGB channel
# ordering
image = cv2.imread(args["image"])
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# use Tesseract to OCR the image
text = pytesseract.image_to_string(image)
print(text)

1 Answer 1

1

Try this code out.

import pytesseract
import cv2
path = 'pyimagesearch_address.png'
image = cv2.imread(path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
text = pytesseract.image_to_string(image)
print(text)
Sign up to request clarification or add additional context in comments.

1 Comment

That did it. Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.