From b3568e34179effeba98c57caac5a9bfe033bde39 Mon Sep 17 00:00:00 2001 From: neo-dl Date: Mon, 18 Jul 2022 18:20:16 +0200 Subject: [PATCH] localdev --- config/machine_settings/defaults.ini | 8 ++++--- config/vision/labels/labels.pbtxt | 4 ++-- config/vision/recipes/1.ini | 14 ++++-------- config/vision/recipes/2.ini | 34 ---------------------------- simulate.sh | 2 -- src/components/component.py | 2 +- src/components/vision.py | 20 +++++++++++++--- src/main.py | 3 +++ 8 files changed, 32 insertions(+), 55 deletions(-) delete mode 100644 config/vision/recipes/2.ini diff --git a/config/machine_settings/defaults.ini b/config/machine_settings/defaults.ini index 38347cc..0b9aa09 100644 --- a/config/machine_settings/defaults.ini +++ b/config/machine_settings/defaults.ini @@ -9,9 +9,9 @@ exposure_time: 10000 ; vertical_crop_resolution: 2048 ; rotate_90_clockwise times: 0 ; auto_white_balance: off -; balance_red: 1.0 -; balance_green: 1.0 -; balance_blue: 1.0 +balance_red: 1.66 +balance_green: 1.0 +balance_blue: 1.12 [vision_saver] time_format: %Y-%m-%d_%H-%M-%S @@ -44,4 +44,6 @@ baudrate: 9600 [vision] detection_threshold: 0.3 +neural_network: hs2-50000 + ; recipes_path: ./config/vision_test_recipes diff --git a/config/vision/labels/labels.pbtxt b/config/vision/labels/labels.pbtxt index 66912e7..5e6c94c 100644 --- a/config/vision/labels/labels.pbtxt +++ b/config/vision/labels/labels.pbtxt @@ -1,7 +1,7 @@ item { id: 1 name: 'hs-ok' - color: '0x00ff00' + color: '0x555555' } item { id: 2 @@ -11,5 +11,5 @@ item { item { id: 3 name: 'hs-empty' - color: '0x0000ff' + color: '0xaaaaaa' } diff --git a/config/vision/recipes/1.ini b/config/vision/recipes/1.ini index bee1461..c0f6df7 100644 --- a/config/vision/recipes/1.ini +++ b/config/vision/recipes/1.ini @@ -1,8 +1,8 @@ # LIEBHER RUBBER FLANGE [general] -name: RICETTA 1 -instruction: APPORRE I SEGNI CON IL PENNARELLO COME INDICATO IN FIGURA +name: TERMORESTRINGENTE +instruction: CONTROLLARE PRESENZA TERMORESTRINGENTE # POINTS FORMAT: # point_name: point_center point_size fill_color border_color border_thickness shape @@ -20,15 +20,9 @@ instruction: APPORRE I SEGNI CON IL PENNARELLO COME INDICATO IN FIGURA # name: X,Y S 0xAARRGGBB 0xAARRGGBB T TEXT [markers] -cross: 1100,1100 100,100 0x000000ff 0xff0000ff 25 cross -center: 1100,1100 2050,2050 0x0000ff00 0xff0000ff 50 ellipse [zones] -p1: 610,550 200 hs-ok # TOP LEFT WHITE POINT -p2: 1790,1290 200 hs-ok # RIGHT SIDE WHITE POINT -p3: 350,1190 200 hs-ok # LEFT SIDE BLUE POINT +p1: 800,700 100,200 hs-ok # HEATSINK PRESENT [labels] -p1: 510,825 100 0xffffffff 0xff000000 10 BIANCO -p2: 1690,1565 100 0xffffffff 0xff000000 10 BIANCO -p3: 250,1465 100 0xff0000ff 0xff000000 10 BLU +p1: 600,500 100 0xffffffff 0xffffffff 10 TERMORESTRINGENTE diff --git a/config/vision/recipes/2.ini b/config/vision/recipes/2.ini deleted file mode 100644 index 31e321a..0000000 --- a/config/vision/recipes/2.ini +++ /dev/null @@ -1,34 +0,0 @@ -# LIEBHER RUBBER FLANGE - -[general] -name: RICETTA 2 -instruction: APPORRE I SEGNI CON IL PENNARELLO COME INDICATO IN FIGURA - -# POINTS FORMAT: -# point_name: point_center point_size fill_color border_color border_thickness shape -# EXAMPLE: -# name: X,Y W,H 0xAARRGGBB 0xAARRGGBB T SHAPE CLASS -# ZONES FORMAT: -# region_name: region_center region_margin class -# margin can be a box (XM*2,YM*2) or a radius (R) -# EXAMPLES: -# name: X,Y XM,YM T SHAPE CLASS -# name: X,Y R T SHAPE CLASS -# LABELS FORMAT: -# label_name: label_start_location font_size fill_color border_color border_thickness text -# EXAMPLE: -# name: X,Y S 0xAARRGGBB 0xAARRGGBB T TEXT - -[markers] -cross: 1100,1100 100,100 0x000000ff 0xff0000ff 25 cross -center: 1100,1100 2050,2050 0x0000ff00 0xff0000ff 50 ellipse - -[zones] -p1: 610,550 200 hs-ok # TOP LEFT WHITE POINT -p2: 1790,1290 200 hs-ok # RIGHT SIDE WHITE POINT -p3: 350,1190 200 hs-ok # LEFT SIDE BLUE POINT - -[labels] -p1: 510,825 100 0xffffffff 0xff000000 10 BIANCO -p2: 1690,1565 100 0xffffffff 0xff000000 10 BIANCO -p3: 250,1465 100 0xff0000ff 0xff000000 10 BLU diff --git a/simulate.sh b/simulate.sh index 5cbbaeb..56f8ada 100755 --- a/simulate.sh +++ b/simulate.sh @@ -14,12 +14,10 @@ export QT_NO_WARNING_OUTPUT=0 # export QT_QPA_PLATFORM=${XDG_SESSION_TYPE} python -B -u "./src/main.py" \ --auto-login-admin \ ---auto-select \ --no-autotest \ --no-edgetpu \ --no-gpu \ --panel \ ---sim-camera \ --sim-modbus \ --sim-os-label-printer \ --sim-serial \ diff --git a/src/components/component.py b/src/components/component.py index 93c8a33..bd13e51 100644 --- a/src/components/component.py +++ b/src/components/component.py @@ -109,7 +109,7 @@ class Component(QObject): self._lock.release() return running - def wait_ready(self, timeout=5): + def wait_ready(self, timeout=10): """ waits untill the requested action has been completed by the component this will return immediately if threaded=False was passed at component initialization diff --git a/src/components/vision.py b/src/components/vision.py index b489bb0..302703f 100644 --- a/src/components/vision.py +++ b/src/components/vision.py @@ -7,6 +7,11 @@ from pathlib import Path import cv2 import numpy as np +from PyQt5.QtWidgets import QApplication + +if "--no-gpu" in sys.argv: + os.environ["CUDA_VISIBLE_DEVICES"] = "-1" + import tensorflow as tf from lib.helpers.object_detection.utils import label_map_util from PyQt5.QtCore import (QFileSystemWatcher, QLineF, QMutex, QPointF, QRectF, @@ -17,6 +22,7 @@ from PyQt5.QtGui import (QBrush, QColor, QFont, QImage, QPainter, QPainterPath, from .component import Component from .consumer import Consumer + if "--no-edgetpu" not in sys.argv: try: from pycoral.utils.edgetpu import make_interpreter @@ -42,8 +48,6 @@ else: def Interpreter(*args, **kwargs): raise ValueError("\"--no-tflite\" in sys.argv") -if "--no-gpu" in sys.argv: - os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # # Patch the location of gfile # tf.gfile = tf.io.gfile @@ -69,6 +73,9 @@ class Vision(Component): self.vision_consumer.moveToThread(self.vision_consumer_thread) self.vision_consumer_thread.started.connect(self.vision_consumer.start) self.vision_consumer_thread.start() + QApplication.processEvents() + QThread.msleep(1000) + QApplication.processEvents() self.vision_consumer.wait_ready() # RENDER THREAD self.render_consumer = Consumer(work=self.render_consumer_work, work_fifo=True, drop_fifo=True, work_maxlen=1, name="render_consumer", paused=False) @@ -77,6 +84,9 @@ class Vision(Component): self.render_consumer.moveToThread(self.render_consumer_thread) self.render_consumer_thread.started.connect(self.render_consumer.start) self.render_consumer_thread.start() + QApplication.processEvents() + QThread.msleep(1000) + QApplication.processEvents() self.render_consumer.wait_ready() # CONNECT CONSUMERS self.vision_consumer.out.connect(self.process_vision_consumed) @@ -275,6 +285,8 @@ class Vision(Component): "none", ]: model_name = sorted([d for d in os.listdir(self.models_dir) if os.path.isdir(self.models_dir / d)], reverse=True)[0] + else: + model_name = model self.log.info(f"loading neural network: {model_name!r}") self.loading_model_signal.emit({"status": "loading"}) self.lock.lock() @@ -429,8 +441,10 @@ class Vision(Component): # filtering out those that do not contain the detection min_distance = sys.maxsize closest_zone = None + outside_zone = True for zone_name, zone in self.zones.items(): if zone["shape"] == "rect": + distance = self.get_distance(detection["center"], zone["center"]) if self.zone_detection_filter_mode == "center_inside": outside_zone = any([ detection["center"][0] < zone["box"][0], @@ -512,7 +526,7 @@ class Vision(Component): "detection": detection, } return { - "ok": all(map(lambda detection: detection["ok"] is True, checked.values())), + "ok": False, # all(map(lambda detection: detection["ok"] is True, checked.values())), "results": checked, } diff --git a/src/main.py b/src/main.py index 701c4ce..33f9386 100644 --- a/src/main.py +++ b/src/main.py @@ -100,6 +100,9 @@ try: component = self.components[component_name] thread.started.connect(component.start) thread.start() + QApplication.processEvents() + QThread.msleep(1000) + QApplication.processEvents() if component_name == "vision": component.wait_ready(timeout=60) else: