mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-02-18 00:16:41 +01:00
publish event updates on zone change
This commit is contained in:
parent
4b95a37e65
commit
ff3e95bbf7
@ -73,7 +73,7 @@ class TrackedObject():
|
|||||||
self.top_score = self.computed_score = 0.0
|
self.top_score = self.computed_score = 0.0
|
||||||
self.thumbnail_data = None
|
self.thumbnail_data = None
|
||||||
self.frame = None
|
self.frame = None
|
||||||
self.previous = None
|
self.previous = self.to_dict()
|
||||||
self._snapshot_jpg_time = 0
|
self._snapshot_jpg_time = 0
|
||||||
ret, jpg = cv2.imencode('.jpg', np.zeros((300,300,3), np.uint8))
|
ret, jpg = cv2.imencode('.jpg', np.zeros((300,300,3), np.uint8))
|
||||||
self._snapshot_jpg = jpg.tobytes()
|
self._snapshot_jpg = jpg.tobytes()
|
||||||
@ -99,7 +99,7 @@ class TrackedObject():
|
|||||||
return median(scores)
|
return median(scores)
|
||||||
|
|
||||||
def update(self, current_frame_time, obj_data):
|
def update(self, current_frame_time, obj_data):
|
||||||
previous = self.to_dict()
|
significant_update = False
|
||||||
self.obj_data.update(obj_data)
|
self.obj_data.update(obj_data)
|
||||||
# if the object is not in the current frame, add a 0.0 to the score history
|
# if the object is not in the current frame, add a 0.0 to the score history
|
||||||
if self.obj_data['frame_time'] != current_frame_time:
|
if self.obj_data['frame_time'] != current_frame_time:
|
||||||
@ -129,7 +129,7 @@ class TrackedObject():
|
|||||||
'region': self.obj_data['region'],
|
'region': self.obj_data['region'],
|
||||||
'score': self.obj_data['score']
|
'score': self.obj_data['score']
|
||||||
}
|
}
|
||||||
self.previous = previous
|
significant_update = True
|
||||||
|
|
||||||
# check zones
|
# check zones
|
||||||
current_zones = []
|
current_zones = []
|
||||||
@ -143,8 +143,13 @@ class TrackedObject():
|
|||||||
if name in self.current_zones or not zone_filtered(self, zone.filters):
|
if name in self.current_zones or not zone_filtered(self, zone.filters):
|
||||||
current_zones.append(name)
|
current_zones.append(name)
|
||||||
self.entered_zones.add(name)
|
self.entered_zones.add(name)
|
||||||
|
|
||||||
|
# if the zones changed, signal an update
|
||||||
|
if not self.false_positive and set(self.current_zones) != set(current_zones):
|
||||||
|
significant_update = True
|
||||||
|
|
||||||
self.current_zones = current_zones
|
self.current_zones = current_zones
|
||||||
|
return significant_update
|
||||||
|
|
||||||
def to_dict(self, include_thumbnail: bool = False):
|
def to_dict(self, include_thumbnail: bool = False):
|
||||||
return {
|
return {
|
||||||
@ -327,16 +332,16 @@ class CameraState():
|
|||||||
|
|
||||||
for id in updated_ids:
|
for id in updated_ids:
|
||||||
updated_obj = self.tracked_objects[id]
|
updated_obj = self.tracked_objects[id]
|
||||||
updated_obj.update(frame_time, current_detections[id])
|
significant_update = updated_obj.update(frame_time, current_detections[id])
|
||||||
|
|
||||||
if (not updated_obj.false_positive
|
if significant_update:
|
||||||
and updated_obj.thumbnail_data['frame_time'] == frame_time
|
# ensure this frame is stored in the cache
|
||||||
and frame_time not in self.frame_cache):
|
if updated_obj.thumbnail_data['frame_time'] == frame_time and frame_time not in self.frame_cache:
|
||||||
self.frame_cache[frame_time] = np.copy(current_frame)
|
self.frame_cache[frame_time] = np.copy(current_frame)
|
||||||
|
|
||||||
# call event handlers
|
# call event handlers
|
||||||
for c in self.callbacks['update']:
|
for c in self.callbacks['update']:
|
||||||
c(self.name, updated_obj, frame_time)
|
c(self.name, updated_obj, frame_time)
|
||||||
|
|
||||||
for id in removed_ids:
|
for id in removed_ids:
|
||||||
# publish events to mqtt
|
# publish events to mqtt
|
||||||
@ -421,9 +426,10 @@ class TrackedObjectProcessor(threading.Thread):
|
|||||||
self.event_queue.put(('start', camera, obj.to_dict()))
|
self.event_queue.put(('start', camera, obj.to_dict()))
|
||||||
|
|
||||||
def update(camera, obj: TrackedObject, current_frame_time):
|
def update(camera, obj: TrackedObject, current_frame_time):
|
||||||
if not obj.thumbnail_data is None and obj.thumbnail_data['frame_time'] == current_frame_time:
|
after = obj.to_dict()
|
||||||
message = { 'before': obj.previous, 'after': obj.to_dict() }
|
message = { 'before': obj.previous, 'after': after }
|
||||||
self.client.publish(f"{self.topic_prefix}/events", json.dumps(message), retain=False)
|
self.client.publish(f"{self.topic_prefix}/events", json.dumps(message), retain=False)
|
||||||
|
obj.previous = after
|
||||||
|
|
||||||
def end(camera, obj: TrackedObject, current_frame_time):
|
def end(camera, obj: TrackedObject, current_frame_time):
|
||||||
if not obj.false_positive:
|
if not obj.false_positive:
|
||||||
|
Loading…
Reference in New Issue
Block a user