Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: argument are required -i/--image

I wrote this code for shape detection but its showing error

# import the necessary packages
import shape_detector
import argparse
import imutils
import cv2
import sys

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i","--image", required=True,help="path to the input 
image",default = "~C:/Users/hp/Desktop/test2.png")
args = vars(ap.parse_args())
# load the image and resize it to a smaller factor so that
# the shapes can be approximated better
image = cv2.imread(args["image"])
resized = imutils.resize(image, width=300)
ratio = image.shape[0] / float(resized.shape[0])

# convert the resized image to grayscale, blur it slightly,
# and threshold it
gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]

# find contours in the thresholded image and initialize the
# shape detector
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
sd = ShapeDetector()
# loop over the contours

after this part i used for loop on the conturs to detect the image but it is showing this error

usage: working.py [-h] -i IMAGE
working.py: error: the following arguments are required: -i/--image

Please tell me where to mention the path of my image and i am new to it so feel free to tell me where i am making mistake

like image 765
aakarsh Avatar asked Oct 31 '25 18:10

aakarsh


1 Answers

If you don't want to provide the -i argument, remove the required=True from the following line:

ap.add_argument("-i","--image", required=True,help="path to the input 
image",default = "~C:/Users/hp/Desktop/test2.png")

This will cause the argument to be optional, and default to "~C:/Users/hp/Desktop/test2.png".

like image 106
gbrener Avatar answered Nov 02 '25 09:11

gbrener



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!