error: argument are required -i/--image

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

在这部分之后,我在 conturs 上使用 for 循环来检测图像 但它显示此错误

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

如果您不想提供 -i 参数,请从以下行中删除 required=True

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

这将使参数成为可选参数,并且默认为 "~C:/Users/hp/Desktop/test2.png"