Make box in timeline relative coordinates

This commit is contained in:
Nick Mowen 2023-04-21 08:54:37 -06:00
parent 50e4b82b01
commit a6cde7d98f
2 changed files with 29 additions and 5 deletions

View File

@ -292,7 +292,7 @@ class FrigateApp:
def start_timeline_processor(self) -> None: def start_timeline_processor(self) -> None:
self.timeline_processor = TimelineProcessor( self.timeline_processor = TimelineProcessor(
self.timeline_queue, self.stop_event self.config, self.timeline_queue, self.stop_event
) )
self.timeline_processor.start() self.timeline_processor.start()

View File

@ -6,6 +6,7 @@ import queue
from enum import Enum from enum import Enum
from frigate.config import FrigateConfig
from frigate.models import Timeline from frigate.models import Timeline
from multiprocessing.queues import Queue from multiprocessing.queues import Queue
@ -23,9 +24,15 @@ class TimelineSourceEnum(str, Enum):
class TimelineProcessor(threading.Thread): class TimelineProcessor(threading.Thread):
"""Handle timeline queue and update DB.""" """Handle timeline queue and update DB."""
def __init__(self, queue: Queue, stop_event: MpEvent) -> None: def __init__(
self,
config: FrigateConfig,
queue: Queue,
stop_event: MpEvent,
) -> None:
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.name = "timeline_processor" self.name = "timeline_processor"
self.config = config
self.queue = queue self.queue = queue
self.stop_event = stop_event self.stop_event = stop_event
@ -55,6 +62,8 @@ class TimelineProcessor(threading.Thread):
event_data: dict[any, any], event_data: dict[any, any],
) -> None: ) -> None:
"""Handle object detection.""" """Handle object detection."""
camera_config = self.config.cameras[camera]
if event_type == "start": if event_type == "start":
Timeline.insert( Timeline.insert(
timestamp=event_data["frame_time"], timestamp=event_data["frame_time"],
@ -63,7 +72,12 @@ class TimelineProcessor(threading.Thread):
source_id=event_data["id"], source_id=event_data["id"],
class_type="visible", class_type="visible",
data={ data={
"box": event_data["box"], # TODO store as relative "box": [
event_data["box"][0] / camera_config.detect.width,
event_data["box"][1] / camera_config.detect.height,
event_data["box"][2] / camera_config.detect.width,
event_data["box"][3] / camera_config.detect.height,
],
"label": event_data["label"], "label": event_data["label"],
"region": event_data["region"], "region": event_data["region"],
}, },
@ -80,7 +94,12 @@ class TimelineProcessor(threading.Thread):
source_id=event_data["id"], source_id=event_data["id"],
class_type="entered_zone", class_type="entered_zone",
data={ data={
"box": event_data["box"], # TODO store as relative "box": [
event_data["box"][0] / camera_config.detect.width,
event_data["box"][1] / camera_config.detect.height,
event_data["box"][2] / camera_config.detect.width,
event_data["box"][3] / camera_config.detect.height,
],
"label": event_data["label"], "label": event_data["label"],
"region": event_data["region"], "region": event_data["region"],
"zones": event_data["current_zones"], "zones": event_data["current_zones"],
@ -94,7 +113,12 @@ class TimelineProcessor(threading.Thread):
source_id=event_data["id"], source_id=event_data["id"],
class_type="gone", class_type="gone",
data={ data={
"box": event_data["box"], # TODO store as relative "box": [
event_data["box"][0] / camera_config.detect.width,
event_data["box"][1] / camera_config.detect.height,
event_data["box"][2] / camera_config.detect.width,
event_data["box"][3] / camera_config.detect.height,
],
"label": event_data["label"], "label": event_data["label"],
"region": event_data["region"], "region": event_data["region"],
}, },