简体   繁体   English

hello.py: 错误: 需要以下 arguments: -i/--image

[英]hello.py: error: the following arguments are required: -i/--image

I have taken a piece of code from the web which uses OpenCV to find circles in an image.我从 web 中获取了一段代码,它使用 OpenCV 在图像中查找圆圈。

# import the necessary packages
import numpy as np
import argparse
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = r"C:\Users\user\Desktop\Sem 8T\Mini Project\Data\Imagestraffic.jpg")
args = vars(ap.parse_args())

# load the image, clone it for output, and then convert it to grayscale
image = cv2.imread(args["image"])
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# detect circles in the image
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 100)

# ensure at least some circles were found
if circles is not None:
    # convert the (x, y) coordinates and radius of the circles to integers
    circles = np.round(circles[0, :]).astype("int")
    # loop over the (x, y) coordinates and radius of the circles
    for (x, y, r) in circles:
        # draw the circle in the output image, then draw a rectangle
        # corresponding to the center of the circle
        cv2.circle(output, (x, y), r, (0, 255, 0), 4)
        cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
        
    # show the output image
    cv2.imshow("output", np.hstack([image, output]))
    cv2.waitKey(0)

However, I keep getting the same error: hello.py: error: the following arguments are required: -i/--image但是,我不断收到相同的错误:hello.py: error: the following arguments are required: -i/--image

I've tried ap.parse_args(args) instead of ap.parse_args() but that doesn't seem to solve it.我试过 ap.parse_args(args) 而不是 ap.parse_args() 但这似乎并没有解决它。

There are two ways to do it.有两种方法可以做到这一点。

ap.add_argument("-i",  r"C:\Users\user\Desktop\Sem 8T\Mini Project\Data\Imagestraffic.jpg", required=True,
    help="path to input image")

ap.add_argument("-i", "--image", required = True, help = "Path to the image")

Hope this will work !希望这会奏效!

# import the necessary packages
import numpy as np
import argparse
import cv2



# load the image, clone it for output, and then convert it to grayscale
image = cv2.imread(r"C:\Users\user\Desktop\Sem 8T\Mini Project\Data\Imagestraffic.jpg")
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# detect circles in the image
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 100)

# ensure at least some circles were found
if circles is not None:
    # convert the (x, y) coordinates and radius of the circles to integers
    circles = np.round(circles[0, :]).astype("int")
    # loop over the (x, y) coordinates and radius of the circles
    for (x, y, r) in circles:
        # draw the circle in the output image, then draw a rectangle
        # corresponding to the center of the circle
        cv2.circle(output, (x, y), r, (0, 255, 0), 4)
        cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
        
    # show the output image
    cv2.imshow("output", np.hstack([image, output]))
    cv2.waitKey(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 main.py:错误:需要以下参数:-i/--image - main.py: error: the following arguments are required: -i/--image 带有hello.py追溯的Python错误 - Python error with hello.py traceback 运行 make -f hello.py 时出现错误。 它说“hello.py:1: *** 缺少分隔符。停止。” - I'm getting an error when running make -f hello.py. It says " hello.py:1: *** missing separator. Stop. " 错误:需要以下 arguments:-i/--image - Error: the following arguments are required: -i/--image AH01215:(8)执行格式错误:'/var/www/python/hello.py'的执行失败:/var/www/python/hello.py - AH01215: (8) Exec format error: exec of '/var/www/python/hello.py' failed: /var/www/python/hello.py main.py:错误:需要以下 arguments - main.py: error: the following arguments are required Flask 错误'ImportError: cannot import name 'db' from 'hello' (C:\Users\admin\flask_stuff\venv\hello.py)' 当我尝试创建 SQL 数据库时 - Flask error 'ImportError: cannot import name 'db' from 'hello' (C:\Users\admin\flask_stuff\venv\hello.py)' when I try to create an SQL Database Flask hello.py 基本应用未运行? - Flask hello.py basic app not running? 错误:需要以下 arguments:-i/--image,-w/--width - error: the following arguments are required: -i/--image, -w/--width 我无法运行 hello.py 并得到 SyntaxError: invalid syntax - I am unable to run hello.py and get SyntaxError: invalid syntax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM