2 Commits

258 changed files with 50 additions and 21098 deletions

View File

@ -1,24 +0,0 @@
/home/cole/item-sort/positives/IMG_10208.jpg 1 4 3 80 110
/home/cole/item-sort/positives/IMG_1155.jpg 1 1 1 30 32
/home/cole/item-sort/positives/IMG_1184.jpg 1 1 1 34 30
/home/cole/item-sort/positives/IMG_1287.jpg 1 2 2 35 29
/home/cole/item-sort/positives/IMG_13351.jpg 1 2 2 165 75
/home/cole/item-sort/positives/IMG_13857.jpg 1 2 5 90 142
/home/cole/item-sort/positives/IMG_1472.jpg 1 1 1 43 29
/home/cole/item-sort/positives/IMG_1584.jpg 1 1 1 45 31
/home/cole/item-sort/positives/IMG_1683.jpg 1 1 0 48 32
/home/cole/item-sort/positives/IMG_1764.jpg 1 2 1 38 39
/home/cole/item-sort/positives/IMG_1776.jpg 1 1 0 45 36
/home/cole/item-sort/positives/IMG_19530.jpg 1 4 4 120 149
/home/cole/item-sort/positives/IMG_2200.jpg 1 1 0 46 42
/home/cole/item-sort/positives/IMG_2772.jpg 1 0 0 83 32
/home/cole/item-sort/positives/IMG_2784.jpg 1 1 1 46 55
/home/cole/item-sort/positives/IMG_2800.jpg 1 1 1 53 48
/home/cole/item-sort/positives/IMG_3285.jpg 1 1 1 71 43
/home/cole/item-sort/positives/IMG_3604.jpg 1 1 0 104 33
/home/cole/item-sort/positives/IMG_4550.jpg 1 1 1 127 32
/home/cole/item-sort/positives/IMG_4879.jpg 1 2 2 37 114
/home/cole/item-sort/positives/IMG_7412.jpg 1 2 2 105 65
/home/cole/item-sort/positives/IMG_7654.jpg 1 4 2 80 84
/home/cole/item-sort/positives/IMG_7740.jpg 1 1 2 126 57

38
bg.txt
View File

@ -1,38 +0,0 @@
negatives/IMG_10285.jpg
negatives/IMG_1190.jpg
negatives/IMG_1225.jpg
negatives/IMG_1443.jpg
negatives/IMG_1482.jpg
negatives/IMG_17202.jpg
negatives/IMG_18939.jpg
negatives/IMG_19860.jpg
negatives/IMG_2116.jpg
negatives/IMG_2408.jpg
negatives/IMG_2475.jpg
negatives/IMG_2548.jpg
negatives/IMG_2597.jpg
negatives/IMG_2700.jpg
negatives/IMG_27048.jpg
negatives/IMG_2805.jpg
negatives/IMG_28583.jpg
negatives/IMG_30940.jpg
negatives/IMG_35235.jpg
negatives/IMG_3599.jpg
negatives/IMG_36040.jpg
negatives/IMG_36400.jpg
negatives/IMG_3666.jpg
negatives/IMG_3840.jpg
negatives/IMG_3844.jpg
negatives/IMG_40176.jpg
negatives/IMG_42840.jpg
negatives/IMG_5041.jpg
negatives/IMG_5184.jpg
negatives/IMG_5402.jpg
negatives/IMG_5700.jpg
negatives/IMG_5820.jpg
negatives/IMG_6014.jpg
negatives/IMG_6016.jpg
negatives/IMG_6240.jpg
negatives/IMG_6435.jpg
negatives/IMG_7482.jpg
negatives/IMG_9800.jpg

70
main.py
View File

@ -66,8 +66,8 @@ def swap(a, b):
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to the input image")
ap.add_argument("-c", "--cascade", required=True,
help="path to the cascade")
#ap.add_argument("-c", "--cascade", required=True,
# help="path to the cascade")
ap.add_argument("-w", "--width", type=float, required=True,
help="width of the left-most object in the image (in inches)")
ap.add_argument("-n", "--number", type=int, required=False,
@ -91,14 +91,20 @@ if args2.show:
cv2.imshow("Item Sorter", image)
cv2.waitKey(0)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (7, 7), 0)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
if args2.show:
cv2.imshow("Item Sorter", gray)
cv2.waitKey(0)
# perform edge detection, then perform a dilation + erosion to
# close gaps in between object edges
edged = cv2.Canny(gray, 50, 100)
if args2.show:
cv2.imshow("Item Sorter", edged)
cv2.waitKey(0)
edged = cv2.dilate(edged, None, iterations=1)
#edged = cv2.erode(edged, None, iterations=1)
edged = cv2.erode(edged, None, iterations=1)
if args2.show:
cv2.imshow("Item Sorter", edged)
@ -114,18 +120,7 @@ cnts = imutils.grab_contours(cnts)
pixelsPerMetric = None
num = 0
cascade = cv2.CascadeClassifier()
if not cascade.load(cv2.samples.findFile(args2.cascade)):
print('--(!)Error loading face cascade')
exit(0)
screws = cascade.detectMultiScale(image)
frame = image.copy()
for (x,y,w,h) in screws:
center = (x + w//2, y + h//2)
frame = cv2.ellipse(frame, center, (w//2, h//2), 0, 0, 360, (255, 0, 255), 4)
if args2.show:
cv2.imshow("Item Sorter", frame)
cv2.waitKey(0)
# Calibration loop
for c in cnts:
# if the contour is not sufficiently large, ignore it
@ -168,7 +163,7 @@ for c in cnts:
#pixelpoints = np.transpose(np.nonzero(mask))
hsv = cv2.cvtColor(orig, cv2.COLOR_BGR2HSV)
mean_val = cv2.mean(hsv, mask=mask)
print(str(mean_val[0]))
#print(str(mean_val[0]))
#print(", " + str(mean_val[0]/mean_val[2]))
#print(", " + str(mean_val[2]/mean_val[1]))
if pixelsPerMetric is None and circular is True and near(mean_val[0], 16, 4.5):
@ -259,6 +254,19 @@ for c in cnts:
objtype = "Penny"
iteml = 0
else:
if circular and near(radius * 2 / pixelsPerMetric, 0.38, 0.03):
# Keps nut or spacer
objtype = "Spacer"
mask = np.zeros(gray.shape, np.uint8)
cv2.drawContours(mask, [c], 0, 255, -1)
#pixelpoints = np.transpose(np.nonzero(mask))
hsv = cv2.cvtColor(orig, cv2.COLOR_BGR2HSV)
mean_val = cv2.mean(hsv, mask=mask)
#print(str(mean_val[0]))
if near(mean_val[0], 47, 5) and near(mean_val[1], 70, 5) and near(mean_val[2], 78, 5):
objtype = "Keps Nut"
if circular and near(radius / pixelsPerMetric, 0.23, 0.02):
objtype = "Washer"
epsilon = 3 # 0.02*cv2.arcLength(c,True)
# print(str(epsilon))
approx = cv2.approxPolyDP(c, epsilon, True)
@ -272,18 +280,18 @@ for c in cnts:
#print(str(convexness) + " % fill")
# if not cv2.isContourConvex(approx):
# if cv2.matchShapes(hull, c, 1, 0.0) > 1:
if defects.size > 5 and (convexness < 0.9 or boxiness < 0.75):
if defects is not None and defects.size > 5 and (convexness < 0.9 or boxiness < 0.75) and rectangular:
objtype = "Screw"
iteml = larger(dimA, dimB)
#print("Screw Length (RAW): " + str(iteml))
iteml = sizeVexScrew(radius * 2 / pixelsPerMetric)
#print("Rounded Length: " + str(iteml))
else:
if itemhr == 0.3125:
if itemhr == 0.3125 and rectangular:
objtype = "Standoff"
iteml = sizeStandoff(itemw)
if itemhr == 0.1875:
if itemhr == 0.1875 and rectangular:
objtype = "Axle"
iteml = (radius * 2 / pixelsPerMetric + itemw) / 2
@ -310,10 +318,16 @@ for c in cnts:
# cv2.putText(orig, "{:.5f}in".format(itemhr),
# (int(trbrX + 20), int(trbrY)), cv2.FONT_HERSHEY_SIMPLEX,
# 0.65, (255, 255, 255), 2)
if circular:
cv2.putText(orig, str(objtype),
(int(x - 25), int(y + radius + 20)
), cv2.FONT_HERSHEY_SIMPLEX,
0.55, (255, 255, 255), 2)
else:
cv2.putText(orig, str(objtype),
(int(xpos2 + 10), int(ypos2 + 20)
), cv2.FONT_HERSHEY_SIMPLEX,
0.65, (255, 255, 255), 2)
0.55, (255, 255, 255), 2)
output = ""
if objtype == "Unknown":
output = "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh)
@ -321,13 +335,19 @@ for c in cnts:
output = str(iteml) + "in"
if objtype == "Axle":
output = "{:.2f}in".format(iteml)
if circular:
cv2.putText(orig, output, # print data
(int(xpos2 + 10), int(ypos2 + 40)
(int(x - 25), int(y + radius + 35)
), cv2.FONT_HERSHEY_SIMPLEX,
0.65, (255, 255, 255), 2)
0.5, (255, 255, 255), 1)
else:
cv2.putText(orig, output, # print data
(int(xpos2 + 10), int(ypos2 + 35)
), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (255, 255, 255), 1)
# show the output image
cv2.imshow("Item Sorter", orig)
cv2.waitKey(25)
cv2.waitKey(1)
cv2.waitKey(0)

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Some files were not shown because too many files have changed in this diff Show More