forked from Github/frigate
Support manual detections in review items (#10784)
* Only update frame time if it is older * Support manual detections as review items * Don't handle api detections in recordings * Store recordings for manual events
This commit is contained in:
@@ -6,10 +6,12 @@ import logging
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
import cv2
|
||||
|
||||
from frigate.comms.detections_updater import DetectionPublisher, DetectionTypeEnum
|
||||
from frigate.comms.events_updater import EventUpdatePublisher
|
||||
from frigate.config import CameraConfig, FrigateConfig
|
||||
from frigate.const import CLIPS_DIR
|
||||
@@ -19,11 +21,19 @@ from frigate.util.image import draw_box_with_label
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ManualEventState(str, Enum):
|
||||
complete = "complete"
|
||||
start = "start"
|
||||
end = "end"
|
||||
|
||||
|
||||
class ExternalEventProcessor:
|
||||
def __init__(self, config: FrigateConfig) -> None:
|
||||
self.config = config
|
||||
self.default_thumbnail = None
|
||||
self.event_sender = EventUpdatePublisher()
|
||||
self.detection_updater = DetectionPublisher(DetectionTypeEnum.api)
|
||||
self.event_camera = {}
|
||||
|
||||
def create_manual_event(
|
||||
self,
|
||||
@@ -47,6 +57,11 @@ class ExternalEventProcessor:
|
||||
thumbnail = self._write_images(
|
||||
camera_config, label, event_id, draw, snapshot_frame
|
||||
)
|
||||
end = (
|
||||
now + duration + camera_config.record.events.post_capture
|
||||
if duration is not None
|
||||
else None
|
||||
)
|
||||
|
||||
self.event_sender.publish(
|
||||
(
|
||||
@@ -60,11 +75,7 @@ class ExternalEventProcessor:
|
||||
"score": score,
|
||||
"camera": camera,
|
||||
"start_time": now - camera_config.record.events.pre_capture,
|
||||
"end_time": now
|
||||
+ duration
|
||||
+ camera_config.record.events.post_capture
|
||||
if duration is not None
|
||||
else None,
|
||||
"end_time": end,
|
||||
"thumbnail": thumbnail,
|
||||
"has_clip": camera_config.record.enabled and include_recording,
|
||||
"has_snapshot": True,
|
||||
@@ -73,6 +84,23 @@ class ExternalEventProcessor:
|
||||
)
|
||||
)
|
||||
|
||||
if source_type == "api":
|
||||
self.event_camera[event_id] = camera
|
||||
self.detection_updater.send_data(
|
||||
(
|
||||
camera,
|
||||
now,
|
||||
{
|
||||
"state": (
|
||||
ManualEventState.complete if end else ManualEventState.start
|
||||
),
|
||||
"label": f"{label}: {sub_label}" if sub_label else label,
|
||||
"event_id": event_id,
|
||||
"end_time": end,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
return event_id
|
||||
|
||||
def finish_manual_event(self, event_id: str, end_time: float) -> None:
|
||||
@@ -86,6 +114,16 @@ class ExternalEventProcessor:
|
||||
)
|
||||
)
|
||||
|
||||
if event_id in self.event_camera:
|
||||
self.detection_updater.send_data(
|
||||
(
|
||||
self.event_camera[event_id],
|
||||
end_time,
|
||||
{"state": ManualEventState.end, "event_id": event_id},
|
||||
)
|
||||
)
|
||||
self.event_camera.pop(event_id)
|
||||
|
||||
def _write_images(
|
||||
self,
|
||||
camera_config: CameraConfig,
|
||||
@@ -143,3 +181,4 @@ class ExternalEventProcessor:
|
||||
|
||||
def stop(self):
|
||||
self.event_sender.stop()
|
||||
self.detection_updater.stop()
|
||||
|
||||
Reference in New Issue
Block a user