I dont deeply understand about the meaning of argparse. And when i tested with this code, it always this error:
usage: test1.py [-h] -i IMAGE
test1.py: error: the following arguments are required: -i/--image
This is my code:
# (1) import the necessary packages
import argparse
import imutils
import cv2
# (2) construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to the input image")
args = vars(ap.parse_args())
# (3) load the image, convert it to grayscale, blur it slightly,
# and threshold it
image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imwrite('C:\\Users\\Hoang Cao Chuyen\\Downloads\\shapes.png', gray)
blurred = cv2.GaussianBlur(gray, (5,5), 0)
cv2.imwrite('C:\\Users\\Hoang Cao Chuyen\\Downloads\\shapes.png', blurred)
thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]
cv2.imwrite('C:\\Users\\Hoang Cao Chuyen\\Downloads\\shapes.png', thresh)
# find contours in the thresholded image
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]