试图将图像传递给代码进行进一步处理,却在Python中遇到argparse问题?

2024-10-02 10:30:42 发布

您现在位置:Python中文网/ 问答频道 /正文

这完全是关于在python中使用argparse将图像传递到数据集

import argparse
import imutils
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True,
    help="path to input image")
ap.add_argument("-o", "--output", required=True,
    help="path to output image")
args = vars(ap.parse_args())  #here is where the problem occured

不应该有任何错误,作为一个初学者,我不能理解这个错误:

usage: [-h] -i INPUT -o OUTPUT
: error: the following arguments are required: -i/--input, -o/--output
An exception has occurred, use %tb to see the full traceback.

%tb
Traceback (most recent call last):

  File "<ipython-input-26-269e7792981c>", line 11, in <module>
    args = vars(ap.parse_args())

  File "E:\SoftwaresInstalled\envs\tensorflow-gpu\lib\argparse.py", line 1734, in parse_args
    args, argv = self.parse_known_args(args, namespace)

  File "E:\SoftwaresInstalled\envs\tensorflow-gpu\lib\argparse.py", line 1766, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)

  File "E:\SoftwaresInstalled\envs\tensorflow-gpu\lib\argparse.py", line 2001, in _parse_known_args
    ', '.join(required_actions))

  File "E:\SoftwaresInstalled\envs\tensorflow-gpu\lib\argparse.py", line 2393, in error
    self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

  File "E:\SoftwaresInstalled\envs\tensorflow-gpu\lib\argparse.py", line 2380, in exit
    _sys.exit(status)

SystemExit: 2

Tags: theinpyinputgpuparselibtensorflow

热门问题