首页 > 解决方案 > 试图将图像传递给代码以进行进一步处理并在 Python 中遇到 argparse 问题?

问题描述

这都是关于使用argparsepython将图像传递给数据集

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

标签: pythoncomputer-visionargparse

解决方案


推荐阅读