mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-08-13 13:47:36 +02:00
added deduping for snapshots
This commit is contained in:
parent
49ee0e0ee2
commit
3eec67a555
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user