|
|
@ -76,13 +76,13 @@ ap.add_argument("-n", "--number", type=int, required=False,
|
|
|
|
args = vars(ap.parse_args())
|
|
|
|
args = vars(ap.parse_args())
|
|
|
|
args2 = ap.parse_args()"""
|
|
|
|
args2 = ap.parse_args()"""
|
|
|
|
def detect(calibration_width, img_file, show, quick):
|
|
|
|
def detect(calibration_width, img_file, show, quick):
|
|
|
|
selected = 2
|
|
|
|
list = []
|
|
|
|
#if type(args["number"]) == type(selected):
|
|
|
|
#if type(args["number"]) == type(selected):
|
|
|
|
# selected = args["number"]
|
|
|
|
# selected = args["number"]
|
|
|
|
|
|
|
|
|
|
|
|
# load the image, convert it to grayscale, and blur it slightly
|
|
|
|
# load the image, convert it to grayscale, and blur it slightly
|
|
|
|
image = None
|
|
|
|
image = None
|
|
|
|
print(str(type(img_file)))
|
|
|
|
#print(str(type(img_file)))
|
|
|
|
if str(type(img_file)) == "<class 'numpy.ndarray'>":
|
|
|
|
if str(type(img_file)) == "<class 'numpy.ndarray'>":
|
|
|
|
image = img_file.copy()
|
|
|
|
image = img_file.copy()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -232,7 +232,7 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
dimA = dA / pixelsPerMetric
|
|
|
|
dimA = dA / pixelsPerMetric
|
|
|
|
dimB = dB / pixelsPerMetric
|
|
|
|
dimB = dB / pixelsPerMetric
|
|
|
|
|
|
|
|
|
|
|
|
if num == num or show:
|
|
|
|
# Item detection
|
|
|
|
area_box = dA * dB
|
|
|
|
area_box = dA * dB
|
|
|
|
(x, y), radius = cv2.minEnclosingCircle(c)
|
|
|
|
(x, y), radius = cv2.minEnclosingCircle(c)
|
|
|
|
area_contour = cv2.contourArea(c)
|
|
|
|
area_contour = cv2.contourArea(c)
|
|
|
@ -247,14 +247,12 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
circular = True
|
|
|
|
circular = True
|
|
|
|
cv2.circle(orig, (int(x), int(y)), int(radius), (255, 0, 0), 2)
|
|
|
|
cv2.circle(orig, (int(x), int(y)), int(radius), (255, 0, 0), 2)
|
|
|
|
|
|
|
|
|
|
|
|
objtype = "Unknown"
|
|
|
|
objtype = "Unknown"
|
|
|
|
itemw = larger(dimA, dimB)
|
|
|
|
itemw = larger(dimA, dimB)
|
|
|
|
itemwr = itemw
|
|
|
|
itemwr = itemw
|
|
|
|
itemwr *= 8
|
|
|
|
itemwr *= 8
|
|
|
|
itemwr = round(itemwr)
|
|
|
|
itemwr = round(itemwr)
|
|
|
|
itemwr /= 8
|
|
|
|
itemwr /= 8
|
|
|
|
|
|
|
|
|
|
|
|
itemh = smaller(dimA, dimB)
|
|
|
|
itemh = smaller(dimA, dimB)
|
|
|
|
itemhr = itemh
|
|
|
|
itemhr = itemh
|
|
|
|
itemhr *= 16
|
|
|
|
itemhr *= 16
|
|
|
@ -300,11 +298,9 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
if itemhr == 0.3125 and rectangular:
|
|
|
|
if itemhr == 0.3125 and rectangular:
|
|
|
|
objtype = "Standoff"
|
|
|
|
objtype = "Standoff"
|
|
|
|
iteml = sizeStandoff(itemw)
|
|
|
|
iteml = sizeStandoff(itemw)
|
|
|
|
|
|
|
|
|
|
|
|
if itemhr == 0.1875 and rectangular:
|
|
|
|
if itemhr == 0.1875 and rectangular:
|
|
|
|
objtype = "Axle"
|
|
|
|
objtype = "Axle"
|
|
|
|
iteml = (radius * 2 / pixelsPerMetric + itemw) / 2
|
|
|
|
iteml = (radius * 2 / pixelsPerMetric + itemw) / 2
|
|
|
|
|
|
|
|
|
|
|
|
rows, cols = orig.shape[:2]
|
|
|
|
rows, cols = orig.shape[:2]
|
|
|
|
[vx, vy, xx, yy] = cv2.fitLine(c, cv2.DIST_L2, 0, 0.01, 0.01)
|
|
|
|
[vx, vy, xx, yy] = cv2.fitLine(c, cv2.DIST_L2, 0, 0.01, 0.01)
|
|
|
|
lefty = int((-xx*vy/vx) + yy)
|
|
|
|
lefty = int((-xx*vy/vx) + yy)
|
|
|
@ -324,7 +320,6 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
(int(xpos2), int(ypos2)), (255, 127, 0), 2)
|
|
|
|
(int(xpos2), int(ypos2)), (255, 127, 0), 2)
|
|
|
|
# print(str(iteml))
|
|
|
|
# print(str(iteml))
|
|
|
|
# draw the object sizes on the image
|
|
|
|
# draw the object sizes on the image
|
|
|
|
if show or True:
|
|
|
|
|
|
|
|
# cv2.putText(orig, "{:.5f}in".format(itemhr),
|
|
|
|
# cv2.putText(orig, "{:.5f}in".format(itemhr),
|
|
|
|
# (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)
|
|
|
@ -348,7 +343,8 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
if objtype == "Axle":
|
|
|
|
if objtype == "Axle":
|
|
|
|
output = "{:.2f}in".format(iteml)
|
|
|
|
output = "{:.2f}in".format(iteml)
|
|
|
|
objname += str(itemwr)
|
|
|
|
objname += str(itemwr)
|
|
|
|
print(objname)
|
|
|
|
#print(objname)
|
|
|
|
|
|
|
|
list.append(objname)
|
|
|
|
if circular:
|
|
|
|
if circular:
|
|
|
|
cv2.putText(orig, output, # print data
|
|
|
|
cv2.putText(orig, output, # print data
|
|
|
|
(int(x - 25), int(y + radius + 40)
|
|
|
|
(int(x - 25), int(y + radius + 40)
|
|
|
@ -359,12 +355,11 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
(int(xpos2 + 10), int(ypos2 + 40)
|
|
|
|
(int(xpos2 + 10), int(ypos2 + 40)
|
|
|
|
), cv2.FONT_HERSHEY_SIMPLEX,
|
|
|
|
), cv2.FONT_HERSHEY_SIMPLEX,
|
|
|
|
0.5, (50, 50, 220), 1)
|
|
|
|
0.5, (50, 50, 220), 1)
|
|
|
|
|
|
|
|
|
|
|
|
# show the output image
|
|
|
|
# show the output image
|
|
|
|
if show:
|
|
|
|
if show and not quick:
|
|
|
|
cv2.imshow("Item Sorter", orig)
|
|
|
|
cv2.imshow("Item Sorter", orig)
|
|
|
|
#cv2.waitKey(1)
|
|
|
|
#cv2.waitKey(1)
|
|
|
|
if quick:
|
|
|
|
if quick:
|
|
|
|
return orig
|
|
|
|
return (list, orig)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
cv2.waitKey(0)
|
|
|
|
cv2.waitKey(0)
|
|
|
|