output item list and scan

video
Cole Deck 4 years ago
parent 129ad2a762
commit e21628b608

Binary file not shown.

@ -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)

@ -5,14 +5,28 @@ from imutils.video import FPS
calibration_width = 0.75
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")
video = False
def go():
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:
elapsed_time = timeit.timeit(go, number=1)/1
print(elapsed_time)
else :
#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)
@ -32,7 +46,8 @@ else :
#print('frame')
if x > 1:
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
if cv2.waitKey(1)&0xFF == ord('q'):
break

Loading…
Cancel
Save