我正在从扫描的文档中提取数据。我使用以下代码来构建和解析参数:
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:UsersAdityaanacondalibsite-packagesIPythoncoreinteractiveshell.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
(