|
|
@ -98,21 +98,16 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
cv2.imshow("Item Sorter", image)
|
|
|
|
cv2.imshow("Item Sorter", 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, (5, 5), 0)
|
|
|
|
gray = cv2.GaussianBlur(gray, (7, 7), 0)
|
|
|
|
if show and not quick:
|
|
|
|
|
|
|
|
cv2.imshow("Item Sorter", gray)
|
|
|
|
|
|
|
|
cv2.waitKey(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# perform edge detection, then perform a dilation + erosion to
|
|
|
|
# perform edge detection, then perform a dilation + erosion to
|
|
|
|
# close gaps in between object edges
|
|
|
|
# close gaps in between object edges
|
|
|
|
edged = cv2.Canny(gray, 50, 100)
|
|
|
|
edged = cv2.Canny(gray, 50, 100)
|
|
|
|
if show and not quick:
|
|
|
|
edged = cv2.dilate(edged, None, iterations=2)
|
|
|
|
cv2.imshow("Item Sorter", edged)
|
|
|
|
edged = cv2.erode(edged, None, iterations=2)
|
|
|
|
cv2.waitKey(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
edged = cv2.dilate(edged, None, iterations=1)
|
|
|
|
if show and not quick:
|
|
|
|
if show and not quick:
|
|
|
|
cv2.imshow("Item Sorter", edged)
|
|
|
|
cv2.imshow("Item Sorter", edged)
|
|
|
|
cv2.waitKey(0)
|
|
|
|
cv2.waitKey(0)
|
|
|
@ -127,7 +122,6 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
pixelsPerMetric = None
|
|
|
|
pixelsPerMetric = None
|
|
|
|
num = 0
|
|
|
|
num = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Calibration loop
|
|
|
|
# Calibration loop
|
|
|
|
for c in cnts:
|
|
|
|
for c in cnts:
|
|
|
|
# if the contour is not sufficiently large, ignore it
|
|
|
|
# if the contour is not sufficiently large, ignore it
|
|
|
@ -262,7 +256,8 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
objtype = "Penny"
|
|
|
|
objtype = "Penny"
|
|
|
|
iteml = 0
|
|
|
|
iteml = 0
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if circular and near(radius * 2 / pixelsPerMetric, 0.38, 0.03):
|
|
|
|
|
|
|
|
|
|
|
|
if circular and near(radius * 2 / pixelsPerMetric, 0.4, 0.03):
|
|
|
|
# Keps nut or spacer
|
|
|
|
# Keps nut or spacer
|
|
|
|
objtype = "Spacer"
|
|
|
|
objtype = "Spacer"
|
|
|
|
mask = np.zeros(gray.shape, np.uint8)
|
|
|
|
mask = np.zeros(gray.shape, np.uint8)
|
|
|
@ -270,11 +265,13 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
#pixelpoints = np.transpose(np.nonzero(mask))
|
|
|
|
#pixelpoints = np.transpose(np.nonzero(mask))
|
|
|
|
hsv = cv2.cvtColor(orig, cv2.COLOR_BGR2HSV)
|
|
|
|
hsv = cv2.cvtColor(orig, cv2.COLOR_BGR2HSV)
|
|
|
|
mean_val = cv2.mean(hsv, mask=mask)
|
|
|
|
mean_val = cv2.mean(hsv, mask=mask)
|
|
|
|
#print(str(mean_val[0]))
|
|
|
|
mean_rgb = cv2.mean(orig, mask=mask)
|
|
|
|
if near(mean_val[0], 47, 5) and near(mean_val[1], 70, 5) and near(mean_val[2], 78, 5):
|
|
|
|
if near(mean_rgb[2], 59, 3) and near(mean_val[1], 85, 5): #and near(mean_val[2], 78, 5):
|
|
|
|
objtype = "Keps Nut"
|
|
|
|
objtype = "Keps Nut"
|
|
|
|
if circular and near(radius / pixelsPerMetric, 0.23, 0.02):
|
|
|
|
print(str(mean_rgb[2]) + objtype + str(mean_val[1]))
|
|
|
|
|
|
|
|
elif circular and near(radius / pixelsPerMetric, 0.23, 0.02):
|
|
|
|
objtype = "Washer"
|
|
|
|
objtype = "Washer"
|
|
|
|
|
|
|
|
#print(str(radius * 2 / pixelsPerMetric) + objtype)
|
|
|
|
epsilon = 3 # 0.02*cv2.arcLength(c,True)
|
|
|
|
epsilon = 3 # 0.02*cv2.arcLength(c,True)
|
|
|
|
# print(str(epsilon))
|
|
|
|
# print(str(epsilon))
|
|
|
|
approx = cv2.approxPolyDP(c, epsilon, True)
|
|
|
|
approx = cv2.approxPolyDP(c, epsilon, True)
|
|
|
@ -359,7 +356,7 @@ def detect(calibration_width, img_file, show, quick):
|
|
|
|
if show and not quick:
|
|
|
|
if show and not quick:
|
|
|
|
cv2.imshow("Item Sorter", orig)
|
|
|
|
cv2.imshow("Item Sorter", orig)
|
|
|
|
#cv2.waitKey(1)
|
|
|
|
#cv2.waitKey(1)
|
|
|
|
if quick:
|
|
|
|
if not quick:
|
|
|
|
return (list, orig)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
cv2.waitKey(0)
|
|
|
|
cv2.waitKey(0)
|
|
|
|
|
|
|
|
return (list, orig)
|
|
|
|
|
|
|
|
|
|
|
|