diff --git a/img4.jpg b/img4.jpg new file mode 100644 index 0000000..0010577 Binary files /dev/null and b/img4.jpg differ diff --git a/main.py b/main.py index f354af8..347bc2e 100644 --- a/main.py +++ b/main.py @@ -35,16 +35,19 @@ ap.add_argument("-w", "--width", type=float, required=True, help="width of the left-most object in the image (in inches)") ap.add_argument("-n", "--number", type=int, required=False, help="object # to measure (from left to right)") -ap.add_argument("-s", "--show", type=bool, required=False, +ap.add_argument("-s", "--show", action="store_true", help="show on the screen") args = vars(ap.parse_args()) - +args2 = ap.parse_args() selected = 2 if type(args["number"]) == type(selected): selected = args["number"] # load the image, convert it to grayscale, and blur it slightly image = cv2.imread(args["image"]) +if args2.show: + cv2.imshow("Image", image) + cv2.waitKey(0) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) gray = cv2.GaussianBlur(gray, (7, 7), 0) @@ -54,7 +57,7 @@ gray = cv2.GaussianBlur(gray, (7, 7), 0) edged = cv2.Canny(gray, 50, 100) edged = cv2.dilate(edged, None, iterations=1) edged = cv2.erode(edged, None, iterations=1) -if args["show"] == True: +if args2.show: cv2.imshow("Image", edged) cv2.waitKey(0) # find contours in the edge map @@ -162,7 +165,7 @@ for c in cnts: iteml = sizeVexScrew(iteml) print("Rounded Length: " + str(iteml)) # draw the object sizes on the image - if args["show"] == True: + if args2.show: cv2.putText(orig, "{:.5f}in".format(dimA), (int(tltrX - 15), int(tltrY - 10)), cv2.FONT_HERSHEY_SIMPLEX, 0.65, (255, 255, 255), 2)