|
|
|
@ -101,7 +101,7 @@ cnts = imutils.grab_contours(cnts)
|
|
|
|
|
|
|
|
|
|
# sort the contours from left-to-right and initialize the
|
|
|
|
|
# 'pixels per metric' calibration variable
|
|
|
|
|
(cnts, _) = contours.sort_contours(cnts)
|
|
|
|
|
#(cnts, _) = contours.sort_contours(cnts)
|
|
|
|
|
pixelsPerMetric = None
|
|
|
|
|
num = 0
|
|
|
|
|
|
|
|
|
@ -220,7 +220,7 @@ for c in cnts:
|
|
|
|
|
#cv2.drawContours(orig, [box.astype("int")], -1, (0, 255, 0), 2)
|
|
|
|
|
else:
|
|
|
|
|
circular = True
|
|
|
|
|
cv2.circle(orig,(int(x),int(y)),int(radius),(0,255,0),2)
|
|
|
|
|
cv2.circle(orig,(int(x),int(y)),int(radius),(0,255,0),1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
objtype = "Unknown"
|
|
|
|
@ -246,8 +246,8 @@ for c in cnts:
|
|
|
|
|
hull2 = cv2.convexHull(c)
|
|
|
|
|
defects = cv2.convexityDefects(c,hull)
|
|
|
|
|
#print(str(defects.size) + " match")
|
|
|
|
|
cv2.drawContours(orig, (hull2), -1, (0, 0, 255), 8)
|
|
|
|
|
cv2.drawContours(orig, (approx), -1, (255, 0, 0), 6)
|
|
|
|
|
cv2.drawContours(orig, (hull2), -1, (0, 0, 255), 3)
|
|
|
|
|
cv2.drawContours(orig, (approx), -1, (255, 0, 0), 3)
|
|
|
|
|
convexness = area_contour / cv2.contourArea(hull2)
|
|
|
|
|
#print(str(convexness) + " % fill")
|
|
|
|
|
#if not cv2.isContourConvex(approx):
|
|
|
|
@ -282,7 +282,7 @@ for c in cnts:
|
|
|
|
|
swap(xpos, xpos2)
|
|
|
|
|
swap(ypos, ypos2)
|
|
|
|
|
if rectangular:
|
|
|
|
|
cv2.line(orig,(int(xpos),int(ypos)),(int(xpos2), int(ypos2)),(0,255,0),2)
|
|
|
|
|
cv2.line(orig,(int(xpos),int(ypos)),(int(xpos2), int(ypos2)),(0,255,0),1)
|
|
|
|
|
#print(str(iteml))
|
|
|
|
|
# draw the object sizes on the image
|
|
|
|
|
if args2.show:
|
|
|
|
@ -292,25 +292,19 @@ for c in cnts:
|
|
|
|
|
cv2.putText(orig, str(objtype),
|
|
|
|
|
(int(xpos2 + 10), int(ypos2 + 20)), cv2.FONT_HERSHEY_SIMPLEX,
|
|
|
|
|
0.65, (255, 255, 255), 2)
|
|
|
|
|
output = ""
|
|
|
|
|
if objtype == "Unknown":
|
|
|
|
|
cv2.putText(orig, "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh), # print axle length
|
|
|
|
|
(int(xpos2 + 10), int(ypos2 + 40)), cv2.FONT_HERSHEY_SIMPLEX,
|
|
|
|
|
0.65, (255, 255, 255), 2)
|
|
|
|
|
if objtype == "Screw":
|
|
|
|
|
cv2.putText(orig, str(iteml) + "in", # print screw length
|
|
|
|
|
(int(xpos2 + 10), int(ypos2 + 40)), cv2.FONT_HERSHEY_SIMPLEX,
|
|
|
|
|
0.65, (255, 255, 255), 2)
|
|
|
|
|
if objtype == "Standoff":
|
|
|
|
|
cv2.putText(orig, str(iteml) + "in", # print standoff length
|
|
|
|
|
(int(xpos2 + 10), int(ypos2 + 40)), cv2.FONT_HERSHEY_SIMPLEX,
|
|
|
|
|
0.65, (255, 255, 255), 2)
|
|
|
|
|
output = "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh)
|
|
|
|
|
if objtype == "Screw" or objtype == "Standoff":
|
|
|
|
|
output = str(iteml) + "in"
|
|
|
|
|
if objtype == "Axle":
|
|
|
|
|
cv2.putText(orig, "{:.2f}in".format(iteml), # print axle length
|
|
|
|
|
output = "{:.2f}in".format(iteml)
|
|
|
|
|
cv2.putText(orig, output, # print data
|
|
|
|
|
(int(xpos2 + 10), int(ypos2 + 40)), cv2.FONT_HERSHEY_SIMPLEX,
|
|
|
|
|
0.65, (255, 255, 255), 2)
|
|
|
|
|
|
|
|
|
|
# show the output image
|
|
|
|
|
cv2.imshow("Item Sorter", orig)
|
|
|
|
|
cv2.waitKey(100)
|
|
|
|
|
cv2.waitKey(25)
|
|
|
|
|
|
|
|
|
|
cv2.waitKey(0)
|