簡體   English   中英

使用 argparse.ArgumentParser() 構造解析器時出錯

[英]getting Error while constructing parser using argparse.ArgumentParser()

我正在從掃描的文檔中提取數據。我正在使用以下代碼構建和解析 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())

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: args = ap.parse_args() ,並且你必須在啟動腳本時提供--image-i參數(因為你有required=True

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM