Add "magic sorting" feature
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 10 KiB |
22
detect.py
@ -319,6 +319,9 @@ def detect(calibration_width, img_file, show, quick):
|
|||||||
# 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)
|
||||||
|
if objtype == "Unknown":
|
||||||
|
objtype = magicSort(c)
|
||||||
|
output = "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh)
|
||||||
if circular:
|
if circular:
|
||||||
cv2.putText(orig, str(objtype),
|
cv2.putText(orig, str(objtype),
|
||||||
(int(x - 25), int(y + radius + 20)
|
(int(x - 25), int(y + radius + 20)
|
||||||
@ -331,8 +334,7 @@ def detect(calibration_width, img_file, show, quick):
|
|||||||
0.6, (50, 50, 220), 2)
|
0.6, (50, 50, 220), 2)
|
||||||
output = ""
|
output = ""
|
||||||
objname = objtype;
|
objname = objtype;
|
||||||
if objtype == "Unknown":
|
|
||||||
output = "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh)
|
|
||||||
if objtype == "Screw" or objtype == "Standoff":
|
if objtype == "Screw" or objtype == "Standoff":
|
||||||
output = str(iteml) + "in"
|
output = str(iteml) + "in"
|
||||||
objname += str(iteml)
|
objname += str(iteml)
|
||||||
@ -359,3 +361,19 @@ def detect(calibration_width, img_file, show, quick):
|
|||||||
cv2.waitKey(0)
|
cv2.waitKey(0)
|
||||||
return (list, orig)
|
return (list, orig)
|
||||||
|
|
||||||
|
def magicSort(contour):
|
||||||
|
moments = cv2.moments(contour)
|
||||||
|
humoments = cv2.HuMoments(moments)
|
||||||
|
humoments[6] = abs(humoments[6]) #it's possible for the last number to change sign if item is mirrored
|
||||||
|
magicNumber = 0
|
||||||
|
for i in range(0,7):
|
||||||
|
humoments[i] = -1 * math.copysign(1.0, humoments[i]) * math.log10(abs(humoments[i]))
|
||||||
|
|
||||||
|
for i in range(0,7):
|
||||||
|
magicNumber += humoments[i]
|
||||||
|
print(str(humoments[i]))
|
||||||
|
#print(magicNumber)
|
||||||
|
name = "Unknown: "
|
||||||
|
name += str(int(round(magicNumber[0] / 2) * 2))
|
||||||
|
print(name)
|
||||||
|
return name
|
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 7.4 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 5.1 KiB |