Use the largest item instead of quitting when there is more than one
This commit is contained in:
parent
052ea30f73
commit
42ca50e4be
20
detect.py
20
detect.py
@ -106,7 +106,7 @@ def detect(calibration_width, img_file, show, quick):
|
||||
edged = cv2.erode(edged, None, iterations=2)
|
||||
edged = cv2.dilate(edged, None, iterations=1)
|
||||
edged = cv2.erode(edged, None, iterations=1)
|
||||
edged = cv2.dilate(edged, None, iterations=1)
|
||||
edged = cv2.dilate(edged, None, iterations=2)
|
||||
#edged = cv2.erode(edged, None, iterations=1)
|
||||
#edged = cv2.dilate(edged, None, iterations=1)
|
||||
if show and not quick:
|
||||
@ -178,14 +178,24 @@ def detect(calibration_width, img_file, show, quick):
|
||||
orig = image.copy()
|
||||
objtype = "Object"
|
||||
objname = ""
|
||||
c = None
|
||||
# loop over the contours individually
|
||||
for c in cnts:
|
||||
if len(cnts) == 0:
|
||||
return ((),edged)
|
||||
area = cv2.contourArea(cnts[0])
|
||||
if area < 400:
|
||||
area = 0
|
||||
for contour in cnts:
|
||||
if cv2.contourArea(contour) >= area and cv2.contourArea(contour) > 400:
|
||||
area = cv2.contourArea(contour)
|
||||
c = contour
|
||||
if c is not None:
|
||||
#orig = image.copy()
|
||||
num += 1
|
||||
# if the contour is not sufficiently large, ignore it
|
||||
#pixelsPerMetric = 75
|
||||
if cv2.contourArea(c) < 300 or pixelsPerMetric is None:
|
||||
continue
|
||||
#if cv2.contourArea(c) < 300 or pixelsPerMetric is None:
|
||||
#continue
|
||||
# compute the rotated bounding box of the contour
|
||||
box = cv2.minAreaRect(c)
|
||||
box = cv2.cv.BoxPoints(box) if imutils.is_cv2() else cv2.boxPoints(box)
|
||||
@ -347,7 +357,7 @@ def detect(calibration_width, img_file, show, quick):
|
||||
#cv2.waitKey(1)
|
||||
if not quick:
|
||||
cv2.waitKey(0)
|
||||
return (list, orig)
|
||||
return (list, edged)
|
||||
|
||||
def magicSort(contour):
|
||||
moments = cv2.moments(contour)
|
||||
|
@ -30,7 +30,7 @@ def go():
|
||||
#control_motor.goToBin(selectedBin)
|
||||
|
||||
def sendString(string):
|
||||
print("[ INFO ] Item found: " + string)
|
||||
print("[ INFO ] Sending message: " + string)
|
||||
try:
|
||||
conn.sendall(string.encode('utf-8'))
|
||||
except socket.error:
|
||||
@ -42,7 +42,8 @@ if not video:
|
||||
print(elapsed_time)
|
||||
|
||||
else :
|
||||
#capture = cv2.VideoCapture('tcpclientsrc port=5001 host=192.168.1.129 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! videorate ! video/x-raw,framerate=5/1 ! appsink', cv2.CAP_GSTREAMER)
|
||||
#capture = cv2.VideoCapture('tcpclientsrc port=5000 host=192.168.1.129 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! videorate ! video/x-raw,framerate=5/1 ! appsink', cv2.CAP_GSTREAMER)
|
||||
#capture = cv2.VideoCapture('tcpclientsrc host=192.168.1.129 port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! autovideosink 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)
|
||||
host = '' # Symbolic name meaning all available interfaces
|
||||
port = 9001 # Arbitrary non-privileged port
|
||||
@ -72,6 +73,7 @@ else :
|
||||
x = 0
|
||||
currentItem = ""
|
||||
samples = 0
|
||||
intake = False
|
||||
while True:
|
||||
ret = capture.grab()
|
||||
x+=1
|
||||
@ -81,14 +83,16 @@ else :
|
||||
#print('frame')
|
||||
if x > 1:
|
||||
ret,frame = capture.retrieve()
|
||||
frame = frame[130:1100, 300:1300]
|
||||
frame = frame[300:1080, 300:1620]
|
||||
#frame = frame[170:900, 475:1100]
|
||||
items,output = detect.detect(calibration_width, frame, True, True)
|
||||
cv2.imshow('Item Sorter', output)
|
||||
x = 0
|
||||
if len(items) > 0:
|
||||
#items.remove("Penny")
|
||||
sendString("Pause ")
|
||||
if intake is True:
|
||||
sendString("Pause ")
|
||||
intake = False
|
||||
itema = items[0]
|
||||
valid = True
|
||||
for item in items:
|
||||
@ -105,6 +109,7 @@ else :
|
||||
if samples >= 10:
|
||||
samples = 0
|
||||
capture.release()
|
||||
time.sleep(2)
|
||||
sendString(currentItem)
|
||||
waitForPi = True
|
||||
while waitForPi is True:
|
||||
@ -122,8 +127,10 @@ else :
|
||||
else:
|
||||
if samples > 0:
|
||||
samples -= 1
|
||||
if samples == 0:
|
||||
if samples == 0 and intake is False:
|
||||
sendString("Intake")
|
||||
intake = True
|
||||
time.sleep(0.25)
|
||||
if cv2.waitKey(1)&0xFF == ord('q'):
|
||||
print("[ EXIT ] Shutting down.")
|
||||
s.shutdown(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user