output item list and scan
This commit is contained in:
parent
129ad2a762
commit
e21628b608
Binary file not shown.
Binary file not shown.
19
detect.py
19
detect.py
@ -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)
|
||||||
|
@ -5,14 +5,28 @@ from imutils.video import FPS
|
|||||||
calibration_width = 0.75
|
calibration_width = 0.75
|
||||||
image = "img7.jpg"
|
image = "img7.jpg"
|
||||||
images = ("img.jpg", "img2.jpg", "img3.jpg", "img4.jpg", "img5.jpg", "img6.jpg", "img7.jpg", "img8.jpg")
|
images = ("img.jpg", "img2.jpg", "img3.jpg", "img4.jpg", "img5.jpg", "img6.jpg", "img7.jpg", "img8.jpg")
|
||||||
|
#images = ("img.jpg", "img2.jpg")
|
||||||
video = False
|
video = False
|
||||||
def go():
|
def go():
|
||||||
for file in images:
|
for file in images:
|
||||||
detect.detect(calibration_width, file, True, False)
|
items,output = detect.detect(calibration_width, file, True, True)
|
||||||
|
print(str(items))
|
||||||
|
if "Penny" in items:
|
||||||
|
items.remove("Penny")
|
||||||
|
itema = items[0]
|
||||||
|
valid = True
|
||||||
|
for item in items:
|
||||||
|
if item != itema:
|
||||||
|
print("Too many items!")
|
||||||
|
valid = False
|
||||||
|
break
|
||||||
|
if valid:
|
||||||
|
print("Found " + itema)
|
||||||
|
|
||||||
if not video:
|
if not video:
|
||||||
elapsed_time = timeit.timeit(go, number=1)/1
|
elapsed_time = timeit.timeit(go, number=1)/1
|
||||||
print(elapsed_time)
|
print(elapsed_time)
|
||||||
|
|
||||||
else :
|
else :
|
||||||
#tcp capture = cv2.VideoCapture('udpsrc port=5001 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! videorate ! video/x-raw,framerate=5/1 ! appsink', cv2.CAP_GSTREAMER)
|
#tcp capture = cv2.VideoCapture('udpsrc port=5001 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! videorate ! video/x-raw,framerate=5/1 ! appsink', cv2.CAP_GSTREAMER)
|
||||||
capture = cv2.VideoCapture('udpsrc port=9000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264" ! rtph264depay ! avdec_h264 ! videoconvert ! appsink sync=false', cv2.CAP_GSTREAMER)
|
capture = cv2.VideoCapture('udpsrc port=9000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264" ! rtph264depay ! avdec_h264 ! videoconvert ! appsink sync=false', cv2.CAP_GSTREAMER)
|
||||||
@ -32,7 +46,8 @@ else :
|
|||||||
#print('frame')
|
#print('frame')
|
||||||
if x > 1:
|
if x > 1:
|
||||||
ret,frame = capture.retrieve()
|
ret,frame = capture.retrieve()
|
||||||
cv2.imshow('Item Sorter', detect.detect(calibration_width, frame, True, True))
|
list,output = detect.detect(calibration_width, frame, True, True)
|
||||||
|
cv2.imshow('Item Sorter', output)
|
||||||
x = 0
|
x = 0
|
||||||
if cv2.waitKey(1)&0xFF == ord('q'):
|
if cv2.waitKey(1)&0xFF == ord('q'):
|
||||||
break
|
break
|
||||||
|
Loading…
x
Reference in New Issue
Block a user