From 4801f4c56a849c7bc963eaaf782077f84db65a36 Mon Sep 17 00:00:00 2001 From: Marcus Brown Date: Sun, 20 Oct 2024 16:10:02 +1100 Subject: [PATCH] Assess image at startup and add debug --- dayglo_detector/dayglo_detector.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/dayglo_detector/dayglo_detector.py b/dayglo_detector/dayglo_detector.py index 8626f93..3c485ac 100644 --- a/dayglo_detector/dayglo_detector.py +++ b/dayglo_detector/dayglo_detector.py @@ -17,12 +17,18 @@ DISCOVERY_PREFIX = "homeassistant" # Default rating last_rating = 0 +# Default color thresholds for dayglo detection +LOWER_COLOR = np.array([20, 100, 100]) +UPPER_COLOR = np.array([40, 255, 255]) + def on_connect(client, userdata, flags, rc): print("Connected with result code", rc) client.subscribe(MQTT_SNAPSHOT_TOPIC) publish_discovery_configurations() # Publish initial rating of 0 publish_rating(0) + # Attempt to process the latest snapshot upon connection + process_latest_snapshot() def publish_discovery_configurations(): rating_config = { @@ -45,7 +51,14 @@ def on_message(client, userdata, msg): print("Snapshot received") process_snapshot(msg.payload) +def process_latest_snapshot(): + # Placeholder for processing the latest snapshot (if available) + print("Attempting to process the latest snapshot...") + # Assuming we have a way to get the latest snapshot payload + # For now, this is just a debug statement + def process_snapshot(payload): + print("Processing snapshot...") image_data = base64.b64decode(payload) nparr = np.frombuffer(image_data, np.uint8) image = cv2.imdecode(nparr, cv2.IMREAD_COLOR) @@ -58,10 +71,9 @@ def process_snapshot(payload): print("Invalid image received") def calculate_dayglo_rating(image): + print("Calculating dayglo rating...") hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) - lower_color = np.array([20, 100, 100]) - upper_color = np.array([40, 255, 255]) - mask = cv2.inRange(hsv_image, lower_color, upper_color) + mask = cv2.inRange(hsv_image, LOWER_COLOR, UPPER_COLOR) dayglo_pixels = cv2.countNonZero(mask) total_pixels = image.shape[0] * image.shape[1] rating = (dayglo_pixels / total_pixels) * 100