From d7a2e2602bc0dac4e365b11e7e099309ef699474 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Tue, 25 Feb 2020 17:17:27 +0000 Subject: [PATCH] Update 'run_detect.py' --- run_detect.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) mode change 100755 => 100644 run_detect.py diff --git a/run_detect.py b/run_detect.py old mode 100755 new mode 100644 index f01c88a..4e70dd8 --- a/run_detect.py +++ b/run_detect.py @@ -29,6 +29,14 @@ def go(): #selectedBin = sort.sort(itema) #control_motor.goToBin(selectedBin) +def sendString(string): + print("Found " + string) + try: + conn.sendall(string.encode('utf-8')) + except socket.error: + print("Error Occured.") + + if not video: elapsed_time = timeit.timeit(go, number=1)/1 print(elapsed_time) @@ -39,17 +47,21 @@ else : host = '' # Symbolic name meaning all available interfaces port = 9001 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + #s.setsockopt(s, socket.SOL_SOCKET, socket.SO_REUSEADDR) s.bind((host, port)) + print("waiting for connection") s.listen(1) conn, addr = s.accept() print('Connected to', addr) - time.sleep(1) + time.sleep(2) waitForPi = True while waitForPi is True: try: + print("waiting for data") data = conn.recv(1024) if not data: break - print "Client: "+data + encoding = 'utf-8' + print ("Client: "+str(data)) waitForPi = False except socket.error: print("Error Occured.") @@ -68,6 +80,7 @@ else : #print('frame') if x > 1: ret,frame = capture.retrieve() + frame = frame[130:1000, 450:1475] items,output = detect.detect(calibration_width, frame, True, True) cv2.imshow('Item Sorter', output) x = 0 @@ -101,12 +114,6 @@ else : break if cv2.waitKey(1)&0xFF == ord('q'): + s.close() break -def sendString(string): - print("Found " + string) - try: - conn.sendall(string) - except socket.error: - print("Error Occured.") - break \ No newline at end of file