From 3eec67a555b8a3154be5296a31533bf95c3f3840 Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 24 Dec 2019 15:57:10 -0800 Subject: [PATCH] added deduping for snapshots --- frigate/mqtt.py | 10 ++++++++-- frigate/video.py | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/frigate/mqtt.py b/frigate/mqtt.py index 155c28580..b613caaeb 100644 --- a/frigate/mqtt.py +++ b/frigate/mqtt.py @@ -3,7 +3,7 @@ import cv2 import threading class MqttObjectPublisher(threading.Thread): - def __init__(self, client, topic_prefix, objects_parsed, detected_objects, best_person_frame, label): + def __init__(self, client, topic_prefix, objects_parsed, detected_objects, best_person_frame, label, dedupe_snapshot_publish): threading.Thread.__init__(self) self.client = client self.topic_prefix = topic_prefix @@ -11,9 +11,11 @@ class MqttObjectPublisher(threading.Thread): self._detected_objects = detected_objects self.best_person_frame = best_person_frame self.label = label + self.dedupe_snapshot_publish = dedupe_snapshot_publish def run(self): last_sent_payload = "" + last_sent_snapshot_time = 0 while True: # initialize the payload @@ -35,7 +37,11 @@ class MqttObjectPublisher(threading.Thread): last_sent_payload = new_payload self.client.publish(self.topic_prefix+'/objects', new_payload, retain=False) # send the snapshot over mqtt as well - if not self.best_person_frame.best_frame is None: + if not self.best_person_frame.best_frame is None and not self.best_person_frame.best_person is None: + snapshot_time = self.best_person_frame.best_person['frame_time'] + if self.dedupe_snapshot_publish and snapshot_time == last_sent_snapshot_time: + continue + last_sent_snapshot_time = snapshot_time ret, jpg = cv2.imencode('.jpg', self.best_person_frame.best_frame) if ret: jpg_bytes = jpg.tobytes() diff --git a/frigate/video.py b/frigate/video.py index 54c7c532f..978e69c0a 100644 --- a/frigate/video.py +++ b/frigate/video.py @@ -131,6 +131,7 @@ class Camera: self.mqtt_client = mqtt_client self.mqtt_topic_prefix = '{}/{}'.format(mqtt_prefix, self.name) self.label = config.get('label', 'person') + self.dedupe_snapshot_publish = config.get('dedupe_snapshot_publish', True) # create a numpy array for the current frame in initialize to zeros self.current_frame = np.zeros(self.frame_shape, np.uint8) @@ -179,7 +180,7 @@ class Camera: self.object_cleaner.start() # start a thread to publish object scores (currently only person) - mqtt_publisher = MqttObjectPublisher(self.mqtt_client, self.mqtt_topic_prefix, self.objects_parsed, self.detected_objects, self.best_person_frame, self.label) + mqtt_publisher = MqttObjectPublisher(self.mqtt_client, self.mqtt_topic_prefix, self.objects_parsed, self.detected_objects, self.best_person_frame, self.label, self.dedupe_snapshot_publish) mqtt_publisher.start() # create a watchdog thread for capture process