Fix deprecated MQTT client usage and enhance dayglo detection
- Updated MQTT client to use MQTTv5 to resolve deprecation warning. - Fine-tuned color thresholds for dayglo detection. - Added cropping to focus on the center 80% of the image for more accurate analysis. - Improved functionality to process an image provided via command line before continuing with MQTT message handling.
This commit is contained in:
@@ -21,8 +21,9 @@ DISCOVERY_PREFIX = "homeassistant"
|
|||||||
last_rating = 0
|
last_rating = 0
|
||||||
|
|
||||||
# Default color thresholds for dayglo detection
|
# Default color thresholds for dayglo detection
|
||||||
LOWER_COLOR = np.array([20, 100, 100])
|
# Fine-tune color thresholds for dayglo detection
|
||||||
UPPER_COLOR = np.array([40, 255, 255])
|
LOWER_COLOR = np.array([25, 150, 150])
|
||||||
|
UPPER_COLOR = np.array([35, 255, 255])
|
||||||
|
|
||||||
# Track if the initial snapshot has been processed
|
# Track if the initial snapshot has been processed
|
||||||
initial_snapshot_processed = False
|
initial_snapshot_processed = False
|
||||||
@@ -92,7 +93,14 @@ def process_snapshot(payload):
|
|||||||
|
|
||||||
def calculate_dayglo_rating(image):
|
def calculate_dayglo_rating(image):
|
||||||
print("Calculating dayglo rating...")
|
print("Calculating dayglo rating...")
|
||||||
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
# Crop the image to focus on the center area
|
||||||
|
height, width = image.shape[:2]
|
||||||
|
crop_margin = 0.1 # 10% margin
|
||||||
|
cropped_image = image[int(height * crop_margin):int(height * (1 - crop_margin)),
|
||||||
|
int(width * crop_margin):int(width * (1 - crop_margin))]
|
||||||
|
|
||||||
|
print("Calculating dayglo rating...")
|
||||||
|
hsv_image = cv2.cvtColor(cropped_image, cv2.COLOR_BGR2HSV)
|
||||||
mask = cv2.inRange(hsv_image, LOWER_COLOR, UPPER_COLOR)
|
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]
|
||||||
@@ -123,7 +131,7 @@ if len(sys.argv) > 1:
|
|||||||
print(f"File not found: {image_file}")
|
print(f"File not found: {image_file}")
|
||||||
|
|
||||||
# Set up MQTT client for normal operation
|
# Set up MQTT client for normal operation
|
||||||
client = mqtt.Client()
|
client = mqtt.Client(client_id='', clean_session=True, protocol=mqtt.MQTTv5)
|
||||||
client.username_pw_set(MQTT_USERNAME, MQTT_PASSWORD)
|
client.username_pw_set(MQTT_USERNAME, MQTT_PASSWORD)
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- /etc/localtime:/etc/localtime:ro
|
- /etc/localtime:/etc/localtime:ro
|
||||||
|
- /home/docker/compose/frigate/debug-image/:/tmp/debug-image/
|
||||||
environment:
|
environment:
|
||||||
MQTT_BROKER: '10.59.221.172'
|
MQTT_BROKER: '10.59.221.172'
|
||||||
MQTT_PORT: '1883'
|
MQTT_PORT: '1883'
|
||||||
|
|||||||
Reference in New Issue
Block a user