0

I am doing data extraction from scanned document.I am using the below code for constructing and parsing the arguments:

from PIL import Image
import pytesseract
import argparse
import cv2
import os
import re
import io
import json
import ftfy

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
                help="path to input image to be OCR'd")
ap.add_argument("-p", "--preprocess", type=str, default="thresh",
                help="type of preprocessing to be done, choose from blur, linear, cubic or bilateral")
args = vars(ap.parse_args())

The line args = vars(ap.parse_args()) is throwing an error as below:

usage: [-h] -i IMAGE [-p PREPROCESS]
: error: the following arguments are required: -i/--image
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

C:\Users\Aditya\anaconda\lib\site-packages\IPython\core\interactiveshell.py:3339: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

As I am new on working with images, so need help to solve this error.

2
  • how are yoy calling this script? You need to provide command line arguments. Is this a ipython console? Commented Dec 11, 2020 at 11:28
  • 1
    The ipyhon help shows: ipython [subcommand] [options] [-c cmd | -m mod | file] [--] [arg] ... The arguments for your argparse are those [arg] after the --. If instead you are running this in a jupyter notebook, you can't use argparse. Commented Dec 11, 2020 at 17:47

1 Answer 1

1

Parse the args like this: args = ap.parse_args(), and you must give --image or -i parameter when launching the script (because you have required=True)

Sign up to request clarification or add additional context in comments.

Comments

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.