使用 argparse.ArgumentParser() 构建解析器时出错

getting Error while constructing parser using argparse.ArgumentParser()

我正在从扫描的数据中提取数据 document.I 我正在使用以下代码构建和解析参数:

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())

args = vars(ap.parse_args()) 行抛出如下错误:

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)

因为我是处理图像的新手,所以需要帮助来解决这个错误。

像这样解析参数: args = ap.parse_args(),启动脚本时必须给--image-i参数(因为你有required=True