update demo

cascade
Cole Deck 5 years ago
parent 9d1cf4cab1
commit c523faafe9

@ -52,7 +52,7 @@ if type(args["number"]) == type(selected):
image = cv2.imread(args["image"]) image = cv2.imread(args["image"])
image = cv2.resize(image, (image.shape[1]*2, image.shape[0]*2), interpolation = cv2.INTER_NEAREST) image = cv2.resize(image, (image.shape[1]*2, image.shape[0]*2), interpolation = cv2.INTER_NEAREST)
if args2.show: if args2.show:
cv2.imshow("Image", image) cv2.imshow("Screw Length Detection", image)
cv2.waitKey(0) cv2.waitKey(0)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (7, 7), 0) gray = cv2.GaussianBlur(gray, (7, 7), 0)
@ -64,7 +64,7 @@ edged = cv2.Canny(gray, 50, 100)
edged = cv2.dilate(edged, None, iterations=1) edged = cv2.dilate(edged, None, iterations=1)
edged = cv2.erode(edged, None, iterations=1) edged = cv2.erode(edged, None, iterations=1)
if args2.show: if args2.show:
cv2.imshow("Image", edged) cv2.imshow("Screw Length Detection", edged)
cv2.waitKey(0) cv2.waitKey(0)
# find contours in the edge map # find contours in the edge map
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,
@ -160,7 +160,7 @@ for c in cnts:
dimA = dA / pixelsPerMetric dimA = dA / pixelsPerMetric
dimB = dB / pixelsPerMetric dimB = dB / pixelsPerMetric
if num == selected: if num == num:
iteml = larger(dimA, dimB) iteml = larger(dimA, dimB)
print("Screw Length (RAW): " + str(iteml)) print("Screw Length (RAW): " + str(iteml))
iteml = sizeVexScrew(iteml) iteml = sizeVexScrew(iteml)
@ -170,12 +170,13 @@ for c in cnts:
cv2.putText(orig, "{:.5f}in".format(larger(dimA, dimB)), cv2.putText(orig, "{:.5f}in".format(larger(dimA, dimB)),
(int(trbrX + 20), int(trbrY)), cv2.FONT_HERSHEY_SIMPLEX, (int(trbrX + 20), int(trbrY)), cv2.FONT_HERSHEY_SIMPLEX,
0.65, (255, 255, 255), 2) 0.65, (255, 255, 255), 2)
cv2.putText(orig, "{:.3f}in".format(iteml), # print screw length if num > 1:
(int(trbrX + 20), int(trbrY + 20)), cv2.FONT_HERSHEY_SIMPLEX, cv2.putText(orig, "{:.3f}in screw".format(iteml), # print screw length
0.65, (255, 255, 255), 2) (int(trbrX + 20), int(trbrY + 20)), cv2.FONT_HERSHEY_SIMPLEX,
0.65, (255, 255, 255), 2)
# show the output image # show the output image
cv2.imshow("Image", orig) cv2.imshow("Screw Length Detection", orig)
cv2.waitKey(0) cv2.waitKey(0)

Loading…
Cancel
Save