Assess image at startup and add debug

This commit is contained in:
2024-10-20 16:10:02 +11:00
parent 8c21481f6e
commit 4801f4c56a
+15 -3
View File
@@ -17,12 +17,18 @@ DISCOVERY_PREFIX = "homeassistant"
# Default rating # Default rating
last_rating = 0 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): def on_connect(client, userdata, flags, rc):
print("Connected with result code", rc) print("Connected with result code", rc)
client.subscribe(MQTT_SNAPSHOT_TOPIC) client.subscribe(MQTT_SNAPSHOT_TOPIC)
publish_discovery_configurations() publish_discovery_configurations()
# Publish initial rating of 0 # Publish initial rating of 0
publish_rating(0) publish_rating(0)
# Attempt to process the latest snapshot upon connection
process_latest_snapshot()
def publish_discovery_configurations(): def publish_discovery_configurations():
rating_config = { rating_config = {
@@ -45,7 +51,14 @@ def on_message(client, userdata, msg):
print("Snapshot received") print("Snapshot received")
process_snapshot(msg.payload) 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): def process_snapshot(payload):
print("Processing snapshot...")
image_data = base64.b64decode(payload) image_data = base64.b64decode(payload)
nparr = np.frombuffer(image_data, np.uint8) nparr = np.frombuffer(image_data, np.uint8)
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR) image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
@@ -58,10 +71,9 @@ def process_snapshot(payload):
print("Invalid image received") print("Invalid image received")
def calculate_dayglo_rating(image): def calculate_dayglo_rating(image):
print("Calculating dayglo rating...")
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower_color = np.array([20, 100, 100]) mask = cv2.inRange(hsv_image, LOWER_COLOR, UPPER_COLOR)
upper_color = np.array([40, 255, 255])
mask = cv2.inRange(hsv_image, lower_color, upper_color)
dayglo_pixels = cv2.countNonZero(mask) dayglo_pixels = cv2.countNonZero(mask)
total_pixels = image.shape[0] * image.shape[1] total_pixels = image.shape[0] * image.shape[1]
rating = (dayglo_pixels / total_pixels) * 100 rating = (dayglo_pixels / total_pixels) * 100