From 004dc7ae825f86cae0c715a6437b7e75f1ae1695 Mon Sep 17 00:00:00 2001 From: MDP G14 RPI Date: Tue, 1 Oct 2019 02:43:53 +0000 Subject: [PATCH] Refactor SymbolDetector to fit into threaded process --- src/communicator/MultiThread.py | 9 +++++++-- src/detector/SymbolDetector.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/communicator/MultiThread.py b/src/communicator/MultiThread.py index af0e032..53d0b00 100644 --- a/src/communicator/MultiThread.py +++ b/src/communicator/MultiThread.py @@ -40,6 +40,7 @@ def __init__(self): # self.android.connect() # self.arduino.connect() # self.pc.connect() + self.detector.start() self.android_queue = queue.Queue(maxsize= 0) self.arduino_queue = queue.Queue(maxsize=0) @@ -110,6 +111,10 @@ def write_pc(self, pc_queue): log.info('Write PC: ' + str(msg)) def detect_symbols(self): - self.detector.start() - self.detector.detect() + while True: + frame = self.detector.get_frame() + symbol_match = self.detector.detect(frame) + if symbol_match is not None: + # Push to queue + print('Symbol Match ID: ' + str(symbol_match)) diff --git a/src/detector/SymbolDetector.py b/src/detector/SymbolDetector.py index 657ec33..67a5288 100755 --- a/src/detector/SymbolDetector.py +++ b/src/detector/SymbolDetector.py @@ -41,7 +41,6 @@ def get_frame(self): return self.video_stream.read() def detect(self, image): - image = self.video_stream.read() pre_proc_frame = preprocess_frame(image) # Uncomment if debugging threshold value @@ -109,7 +108,8 @@ def detect(self, image): self.match_count = self.match_count + 1 if (self.match_count == MATCH_CONFIDENCE_COUNT): # TO-DO: Ping to PC/N7 about the detected Symbol's ID - log.info('Found: ' + str(closest_match['symbol']) + '; ID: ' + str(closest_match['id'])) + # log.info('Found: ' + str(closest_match['symbol']) + '; ID: ' + str(closest_match['id'])) + return(closest_match['id']) else: self.match_symbol_id = closest_match['id'] self.match_count = 1