From b18e8ca4689f8176f5c7a27be99c0520056d82f2 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 12 Jan 2020 07:14:42 -0600 Subject: [PATCH] notify mqtt when objects deregistered --- frigate/mqtt.py | 9 ++++++++- frigate/objects.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/frigate/mqtt.py b/frigate/mqtt.py index 6dc8491c2..6c09abbb1 100644 --- a/frigate/mqtt.py +++ b/frigate/mqtt.py @@ -44,4 +44,11 @@ class MqttObjectPublisher(threading.Thread): expired_objects = [obj_name for obj_name, status in current_object_status.items() if status == 'ON' and not obj_name in obj_counter] for obj_name in expired_objects: current_object_status[obj_name] = 'OFF' - self.client.publish(self.topic_prefix+'/'+obj_name, 'OFF', retain=False) \ No newline at end of file + self.client.publish(self.topic_prefix+'/'+obj_name, 'OFF', retain=False) + # send updated snapshot snapshot over mqtt if we have it as well + if obj_name in self.camera.best_frames.best_frames: + best_frame = cv2.cvtColor(self.camera.best_frames.best_frames[obj_name], cv2.COLOR_RGB2BGR) + ret, jpg = cv2.imencode('.jpg', best_frame) + if ret: + jpg_bytes = jpg.tobytes() + self.client.publish(self.topic_prefix+'/'+obj_name+'/snapshot', jpg_bytes, retain=True) \ No newline at end of file diff --git a/frigate/objects.py b/frigate/objects.py index 511163efc..9703da123 100644 --- a/frigate/objects.py +++ b/frigate/objects.py @@ -27,6 +27,7 @@ class ObjectCleaner(threading.Thread): if not frame_time in self.camera.frame_cache: del self.camera.detected_objects[frame_time] + objects_deregistered = False with self.camera.object_tracker.tracked_objects_lock: now = datetime.datetime.now().timestamp() for id, obj in list(self.camera.object_tracker.tracked_objects.items()): @@ -34,6 +35,11 @@ class ObjectCleaner(threading.Thread): # and not in the most recent frame, deregister if (now - obj['frame_time']) > 10 and self.camera.object_tracker.most_recent_frame_time > obj['frame_time']: self.camera.object_tracker.deregister(id) + objects_deregistered = True + + if objects_deregistered: + with self.camera.objects_tracked: + self.camera.objects_tracked.notify_all() class DetectedObjectsProcessor(threading.Thread): def __init__(self, camera):