mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-02-14 00:17:05 +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 base64
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
import cv2
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -18,8 +18,13 @@ from frigate.util import create_mask
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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"}}
|
DEFAULT_DETECTORS = {"coral": {"type": "edgetpu", "device": "usb"}}
|
||||||
DETECTORS_SCHEMA = vol.Schema(
|
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)]
|
[[int(points[i]), int(points[i + 1])] for i in range(0, len(points), 2)]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(f"Unable to parse zone coordinates for {name}")
|
|
||||||
contour = np.array([])
|
contour = np.array([])
|
||||||
|
|
||||||
return ZoneConfig(
|
return ZoneConfig(
|
||||||
@ -607,6 +611,19 @@ def ensure_zones_and_cameras_have_different_names(cameras):
|
|||||||
return 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(
|
CAMERAS_SCHEMA = vol.Schema(
|
||||||
vol.All(
|
vol.All(
|
||||||
{
|
{
|
||||||
@ -653,6 +670,20 @@ CAMERAS_SCHEMA = vol.Schema(
|
|||||||
vol.Optional("objects", default={}): OBJECTS_SCHEMA,
|
vol.Optional("objects", default={}): OBJECTS_SCHEMA,
|
||||||
vol.Optional("motion", default={}): MOTION_SCHEMA,
|
vol.Optional("motion", default={}): MOTION_SCHEMA,
|
||||||
vol.Optional("detect", default={}): DETECT_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(
|
vol.Msg(
|
||||||
@ -726,6 +757,30 @@ class CameraMqttConfig:
|
|||||||
return dataclasses.asdict(self)
|
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
|
@dataclasses.dataclass
|
||||||
class CameraClipsConfig:
|
class CameraClipsConfig:
|
||||||
enabled: bool
|
enabled: bool
|
||||||
@ -789,6 +844,7 @@ class CameraConfig:
|
|||||||
objects: ObjectConfig
|
objects: ObjectConfig
|
||||||
motion: MotionConfig
|
motion: MotionConfig
|
||||||
detect: DetectConfig
|
detect: DetectConfig
|
||||||
|
timestamp_style: TimestampStyleConfig
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def frame_shape(self) -> Tuple[int, int]:
|
def frame_shape(self) -> Tuple[int, int]:
|
||||||
@ -841,6 +897,7 @@ class CameraConfig:
|
|||||||
detect=DetectConfig.build(
|
detect=DetectConfig.build(
|
||||||
config["detect"], global_config["detect"], config.get("fps", 5)
|
config["detect"], global_config["detect"], config.get("fps", 5)
|
||||||
),
|
),
|
||||||
|
timestamp_style=TimestampStyleConfig.build(config["timestamp_style"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_ffmpeg_cmd(self, ffmpeg_input):
|
def _get_ffmpeg_cmd(self, ffmpeg_input):
|
||||||
|
@ -20,7 +20,12 @@ import numpy as np
|
|||||||
from frigate.config import FrigateConfig, CameraConfig
|
from frigate.config import FrigateConfig, CameraConfig
|
||||||
from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR
|
from frigate.const import RECORD_DIR, CLIPS_DIR, CACHE_DIR
|
||||||
from frigate.edgetpu import load_labels
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -266,17 +271,17 @@ class TrackedObject:
|
|||||||
best_frame = cv2.resize(
|
best_frame = cv2.resize(
|
||||||
best_frame, dsize=(width, height), interpolation=cv2.INTER_AREA
|
best_frame, dsize=(width, height), interpolation=cv2.INTER_AREA
|
||||||
)
|
)
|
||||||
|
|
||||||
if timestamp:
|
if timestamp:
|
||||||
|
logger.info("Jetzad")
|
||||||
draw_timestamp(
|
draw_timestamp(
|
||||||
frame_copy,
|
best_frame,
|
||||||
self.thumbnail_data["frame_time"],
|
self.thumbnail_data["frame_time"],
|
||||||
"%m/%d/%Y %H:%M:%S",
|
self.camera_config.timestamp_style.format,
|
||||||
font_effect=None,
|
font_effect=self.camera_config.timestamp_style.effect,
|
||||||
font_scale=1.0,
|
font_scale=self.camera_config.timestamp_style.scale,
|
||||||
font_thickness=2,
|
font_thickness=self.camera_config.timestamp_style.thickness,
|
||||||
font_color=(255, 255, 255),
|
font_color=self.camera_config.timestamp_style.color,
|
||||||
position="ul",
|
position=self.camera_config.timestamp_style.position,
|
||||||
)
|
)
|
||||||
|
|
||||||
ret, jpg = cv2.imencode(".jpg", best_frame, [int(cv2.IMWRITE_JPEG_QUALITY), 70])
|
ret, jpg = cv2.imencode(".jpg", best_frame, [int(cv2.IMWRITE_JPEG_QUALITY), 70])
|
||||||
@ -402,12 +407,12 @@ class CameraState:
|
|||||||
draw_timestamp(
|
draw_timestamp(
|
||||||
frame_copy,
|
frame_copy,
|
||||||
frame_time,
|
frame_time,
|
||||||
"%m/%d/%Y %H:%M:%S",
|
self.camera_config.timestamp_style.format,
|
||||||
font_effect=None,
|
font_effect=self.camera_config.timestamp_style.effect,
|
||||||
font_scale=1.0,
|
font_scale=self.camera_config.timestamp_style.scale,
|
||||||
font_thickness=2,
|
font_thickness=self.camera_config.timestamp_style.thickness,
|
||||||
font_color= (255, 255, 255),
|
font_color=self.camera_config.timestamp_style.color,
|
||||||
position="ul",
|
position=self.camera_config.timestamp_style.position,
|
||||||
)
|
)
|
||||||
|
|
||||||
return frame_copy
|
return frame_copy
|
||||||
|
Loading…
Reference in New Issue
Block a user