mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Add and use config for timestamp style
This commit is contained in:
parent
5075e4eee1
commit
211fcd64c7
@ -2,12 +2,12 @@ from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import dataclasses
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
|
||||
import cv2
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import voluptuous as vol
|
||||
@ -18,8 +18,13 @@ from frigate.util import create_mask
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_TRACKED_OBJECTS = ["person"]
|
||||
# TODO: Identify what the default format to display timestamps is
|
||||
DEFAULT_TIME_FORMAT = "%m/%d/%Y %H:%M:%S"
|
||||
# German Style:
|
||||
# DEFAULT_TIME_FORMAT = "%d.%m.%Y %H:%M:%S"
|
||||
|
||||
DEFAULT_TRACKED_OBJECTS = ["person"]
|
||||
DEFAULT_RGB_COLOR = {"red": 255, "green": 255, "blue": 255}
|
||||
DEFAULT_DETECTORS = {"coral": {"type": "edgetpu", "device": "usb"}}
|
||||
DETECTORS_SCHEMA = vol.Schema(
|
||||
{
|
||||
@ -322,7 +327,6 @@ class ZoneConfig:
|
||||
[[int(points[i]), int(points[i + 1])] for i in range(0, len(points), 2)]
|
||||
)
|
||||
else:
|
||||
print(f"Unable to parse zone coordinates for {name}")
|
||||
contour = np.array([])
|
||||
|
||||
return ZoneConfig(
|
||||
@ -607,6 +611,19 @@ def ensure_zones_and_cameras_have_different_names(cameras):
|
||||
return cameras
|
||||
|
||||
|
||||
def ensure_timeformat_is_legit(format_string):
|
||||
datetime.datetime.now().strftime(format_string)
|
||||
return format_string
|
||||
|
||||
|
||||
RGB_COLOR_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required("red"): vol.Range(min=0, max=255),
|
||||
vol.Required("green"): vol.Range(min=0, max=255),
|
||||
vol.Required("blue"): vol.Range(min=0, max=255),
|
||||
}
|
||||
)
|
||||
|
||||
CAMERAS_SCHEMA = vol.Schema(
|
||||
vol.All(
|
||||
{
|
||||
@ -653,6 +670,20 @@ CAMERAS_SCHEMA = vol.Schema(
|
||||
vol.Optional("objects", default={}): OBJECTS_SCHEMA,
|
||||
vol.Optional("motion", default={}): MOTION_SCHEMA,
|
||||
vol.Optional("detect", default={}): DETECT_SCHEMA,
|
||||
vol.Optional("timestamp_style", default={}): {
|
||||
vol.Optional("position", default="tl"): vol.In(
|
||||
["tl", "tr", "bl", "br"]
|
||||
),
|
||||
vol.Optional(
|
||||
"format", default=DEFAULT_TIME_FORMAT
|
||||
): ensure_timeformat_is_legit,
|
||||
vol.Optional("color", default=DEFAULT_RGB_COLOR): RGB_COLOR_SCHEMA,
|
||||
vol.Optional("scale", default=1.0): float,
|
||||
vol.Optional("thickness", default=2): int,
|
||||
vol.Optional("effect", default=None): vol.In(
|
||||
[None, "solid", "shadow"]
|
||||
),
|
||||
},
|
||||
}
|
||||
},
|
||||
vol.Msg(
|
||||
@ -726,6 +757,30 @@ class CameraMqttConfig:
|
||||
return dataclasses.asdict(self)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class TimestampStyleConfig:
|
||||
position: str
|
||||
format: str
|
||||
color: Tuple[int, int, int]
|
||||
scale: float
|
||||
thickness: int
|
||||
effect: str
|
||||
|
||||
@classmethod
|
||||
def build(cls, config) -> TimestampStyleConfig:
|
||||
return TimestampStyleConfig(
|
||||
config["position"],
|
||||
config["format"],
|
||||
(config["color"]["red"], config["color"]["green"], config["color"]["blue"]),
|
||||
config["scale"],
|
||||
config["thickness"],
|
||||
config["effect"],
|
||||
)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return dataclasses.asdict(self)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class CameraClipsConfig:
|
||||
enabled: bool
|
||||
@ -789,6 +844,7 @@ class CameraConfig:
|
||||
objects: ObjectConfig
|
||||
motion: MotionConfig
|
||||
detect: DetectConfig
|
||||
timestamp_style: TimestampStyleConfig
|
||||
|
||||
@property
|
||||
def frame_shape(self) -> Tuple[int, int]:
|
||||
@ -841,6 +897,7 @@ class CameraConfig:
|
||||
detect=DetectConfig.build(
|
||||
config["detect"], global_config["detect"], config.get("fps", 5)
|
||||
),
|
||||
timestamp_style=TimestampStyleConfig.build(config["timestamp_style"]),
|
||||
)
|
||||
|
||||
def _get_ffmpeg_cmd(self, ffmpeg_input):
|
||||
|
@ -20,7 +20,12 @@ import numpy as np
|
||||
from frigate.config import FrigateConfig, CameraConfig
|
||||
from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR
|
||||
from frigate.edgetpu import load_labels
|
||||
from frigate.util import SharedMemoryFrameManager, draw_box_with_label, draw_timestamp, calculate_region
|
||||
from frigate.util import (
|
||||
SharedMemoryFrameManager,
|
||||
draw_box_with_label,
|
||||
draw_timestamp,
|
||||
calculate_region,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -266,17 +271,17 @@ class TrackedObject:
|
||||
best_frame = cv2.resize(
|
||||
best_frame, dsize=(width, height), interpolation=cv2.INTER_AREA
|
||||
)
|
||||
|
||||
if timestamp:
|
||||
logger.info("Jetzad")
|
||||
draw_timestamp(
|
||||
frame_copy,
|
||||
best_frame,
|
||||
self.thumbnail_data["frame_time"],
|
||||
"%m/%d/%Y %H:%M:%S",
|
||||
font_effect=None,
|
||||
font_scale=1.0,
|
||||
font_thickness=2,
|
||||
font_color=(255, 255, 255),
|
||||
position="ul",
|
||||
self.camera_config.timestamp_style.format,
|
||||
font_effect=self.camera_config.timestamp_style.effect,
|
||||
font_scale=self.camera_config.timestamp_style.scale,
|
||||
font_thickness=self.camera_config.timestamp_style.thickness,
|
||||
font_color=self.camera_config.timestamp_style.color,
|
||||
position=self.camera_config.timestamp_style.position,
|
||||
)
|
||||
|
||||
ret, jpg = cv2.imencode(".jpg", best_frame, [int(cv2.IMWRITE_JPEG_QUALITY), 70])
|
||||
@ -402,12 +407,12 @@ class CameraState:
|
||||
draw_timestamp(
|
||||
frame_copy,
|
||||
frame_time,
|
||||
"%m/%d/%Y %H:%M:%S",
|
||||
font_effect=None,
|
||||
font_scale=1.0,
|
||||
font_thickness=2,
|
||||
font_color= (255, 255, 255),
|
||||
position="ul",
|
||||
self.camera_config.timestamp_style.format,
|
||||
font_effect=self.camera_config.timestamp_style.effect,
|
||||
font_scale=self.camera_config.timestamp_style.scale,
|
||||
font_thickness=self.camera_config.timestamp_style.thickness,
|
||||
font_color=self.camera_config.timestamp_style.color,
|
||||
position=self.camera_config.timestamp_style.position,
|
||||
)
|
||||
|
||||
return frame_copy
|
||||
|
Loading…
Reference in New Issue
Block a user