Enhance dayglo color detection and resolve MQTT client deprecation warning
- Added broader color ranges for dayglo green and dayglo yellow to improve detection accuracy. - Updated MQTT client to use a unique client ID to avoid deprecated callback usage.
This commit is contained in:
@@ -22,8 +22,11 @@ last_rating = 0
|
||||
|
||||
# Default color thresholds for dayglo detection
|
||||
# Fine-tune color thresholds for dayglo detection
|
||||
LOWER_COLOR = np.array([25, 150, 150])
|
||||
UPPER_COLOR = np.array([35, 255, 255])
|
||||
# Fine-tune color thresholds for dayglo detection
|
||||
LOWER_COLOR_GREEN = np.array([60, 100, 100])
|
||||
UPPER_COLOR_GREEN = np.array([90, 255, 255])
|
||||
LOWER_COLOR_YELLOW = np.array([20, 100, 100])
|
||||
UPPER_COLOR_YELLOW = np.array([35, 255, 255])
|
||||
|
||||
# Track if the initial snapshot has been processed
|
||||
initial_snapshot_processed = False
|
||||
@@ -101,7 +104,9 @@ def calculate_dayglo_rating(image):
|
||||
|
||||
print("Calculating dayglo rating...")
|
||||
hsv_image = cv2.cvtColor(cropped_image, cv2.COLOR_BGR2HSV)
|
||||
mask = cv2.inRange(hsv_image, LOWER_COLOR, UPPER_COLOR)
|
||||
mask_green = cv2.inRange(hsv_image, LOWER_COLOR_GREEN, UPPER_COLOR_GREEN)
|
||||
mask_yellow = cv2.inRange(hsv_image, LOWER_COLOR_YELLOW, UPPER_COLOR_YELLOW)
|
||||
mask = cv2.bitwise_or(mask_green, mask_yellow)
|
||||
dayglo_pixels = cv2.countNonZero(mask)
|
||||
total_pixels = image.shape[0] * image.shape[1]
|
||||
rating = (dayglo_pixels / total_pixels) * 100
|
||||
@@ -131,7 +136,7 @@ if len(sys.argv) > 1:
|
||||
print(f"File not found: {image_file}")
|
||||
|
||||
# Set up MQTT client for normal operation
|
||||
client = mqtt.Client(protocol=mqtt.MQTTv5)
|
||||
client = mqtt.Client(client_id="dayglo_detector", protocol=mqtt.MQTTv5)
|
||||
client.username_pw_set(MQTT_USERNAME, MQTT_PASSWORD)
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
|
||||
Reference in New Issue
Block a user