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