From 1cd5fce290116af492ff392055e43ae54dd730a9 Mon Sep 17 00:00:00 2001 From: Fischertechnik-OpenSource <fischertechnik-opensource@online.de> Date: Wed, 12 Feb 2025 11:47:27 +0100 Subject: [PATCH] Update to 3.1.8 --- lib/fischertechnik/camera/CameraFactory.py | 4 ++-- lib/fischertechnik/camera/LineDetector.py | 9 ++++++++- lib/fischertechnik/mqtt/Client.py | 7 ++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/fischertechnik/camera/CameraFactory.py b/lib/fischertechnik/camera/CameraFactory.py index d4cac43..209d25b 100644 --- a/lib/fischertechnik/camera/CameraFactory.py +++ b/lib/fischertechnik/camera/CameraFactory.py @@ -7,9 +7,9 @@ from .MotionDetector import MotionDetector class CameraFactory(): - def create_line_detector(self, x, y, width, height, min_line_width=5, max_line_width=20, start_range_value=-100, end_range_value=100, number_of_lines=1): + def create_line_detector(self, x, y, width, height, min_line_width=5, max_line_width=20, start_range_value=-100, end_range_value=100, number_of_lines=1, invert=False): """@ReturnType fischertechnik.camera.LineDetector""" - return LineDetector(x, y, width, height, min_line_width, max_line_width, start_range_value, end_range_value, number_of_lines) + return LineDetector(x, y, width, height, min_line_width, max_line_width, start_range_value, end_range_value, number_of_lines, invert) def create_ball_detector(self, x, y, width, height, min_ball_diameter=5, max_ball_diameter=20, start_range_value=-100, end_range_value=100, rgb=[255,0,0], hue_tolerance=20): """@ReturnType fischertechnik.camera.BallDetector""" diff --git a/lib/fischertechnik/camera/LineDetector.py b/lib/fischertechnik/camera/LineDetector.py index 5346b7f..8248be9 100644 --- a/lib/fischertechnik/camera/LineDetector.py +++ b/lib/fischertechnik/camera/LineDetector.py @@ -9,7 +9,7 @@ from .DetectorResult import DetectorResult class LineDetector(Detector): - def __init__(self, x, y, width, height, min_line_width=5, max_line_width=20, start_range_value=-100, end_range_value=100, number_of_lines=1, identifier="line_detector"): + def __init__(self, x, y, width, height, min_line_width=5, max_line_width=20, start_range_value=-100, end_range_value=100, number_of_lines=1, invert=False, identifier="line_detector"): Detector.__init__(self, identifier) self.__x = x self.__y = y @@ -20,6 +20,7 @@ class LineDetector(Detector): self.__start_range_value = start_range_value self.__end_range_value = end_range_value self.__number_of_lines = number_of_lines + self.__invert = invert self.__lines = None def analyze_frame(self, frame): @@ -30,6 +31,10 @@ class LineDetector(Detector): # convert to grayscale gray = cv2.cvtColor(crop, cv2.COLOR_BGR2GRAY) + # if invert True, white lines are detected + if self.__invert == True: + gray = cv2.bitwise_not(gray) + # blurred image blur = cv2.GaussianBlur(gray, (5, 5), 0) @@ -90,6 +95,8 @@ class LineDetector(Detector): mask = np.zeros(crop.shape[:2], np.uint8) cv2.drawContours(mask, [contour], -1, 255, -1) mask = cv2.erode(mask, None, iterations=2) + # FT-6868 RPC 6.1.5: Rot und Blau beim Linienfeld vertauscht + # [:3] entfernen, dreht das Array um mean = cv2.mean(crop, mask=mask)[:3] color = Color(rgb=[int(mean[0]), int(mean[1]), int(mean[2])]) diff --git a/lib/fischertechnik/mqtt/Client.py b/lib/fischertechnik/mqtt/Client.py index 1400e09..b94b520 100644 --- a/lib/fischertechnik/mqtt/Client.py +++ b/lib/fischertechnik/mqtt/Client.py @@ -6,7 +6,7 @@ import paho.mqtt.client as mqtt class Client: - KEEP_ALIVE = 60 + KEEP_ALIVE = 30 def __init__(self, client_id="", clean_session=True, userdata=None, protocol=mqtt.MQTTv311, transport="tcp", path="/"): @@ -39,6 +39,7 @@ class Client: def disconnect(self): if self.paho_client: self.paho_client.disconnect() + self.paho_client.loop_stop() def is_connected(self): return self.connected @@ -63,7 +64,7 @@ class Client: if rc != 0: print("Unexpected connection.") else: - for topic in self.handler: + for topic in self.handler.copy(): self.paho_client.subscribe(topic, self.handler[topic]["qos"]) self.connected = True @@ -74,6 +75,6 @@ class Client: self.connected = False def __on_message(self, client, userdata, msg): - for topic in self.handler: + for topic in self.handler.copy(): if mqtt.topic_matches_sub(topic, msg.topic): self.handler[topic]["callback"](msg) -- GitLab