mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-10 23:08:37 +02:00
* Enable event snapshot API to honour query params * fix unused imports * Fixes * Run ruff check --fix * Web changes * Further config and web fixes * Further docs tweak * Fix missing quality default in MediaEventsSnapshotQueryParams * Manual events: don't save annotated jpeg; store frame time * Remove unnecessary grayscale helper * Add caveat to docs on snapshot_frame_time pre-0.18 * JPG snapshot should not be treated as clean * Ensure tracked details uses uncropped, bbox'd snapshot * Ensure all UI pages / menu actions use uncropped, bbox'd * web lint * Add missed config helper text * Expect SnapshotsConfig not Any * docs: Remove pre-0.18 note * Specify timestamp=0 in the UI * Move tests out of http media * Correct missed settings.json wording Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> * Revert to default None for quality * Correct camera snapshot config wording Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> * Fix quality=0 handling Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> * Fix quality=0 handling #2 Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> * ReRun generate_config_translations --------- Co-authored-by: leccelecce <example@example.com> Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
import os
|
|
import tempfile
|
|
from types import SimpleNamespace
|
|
from unittest import TestCase
|
|
from unittest.mock import patch
|
|
|
|
import cv2
|
|
import numpy as np
|
|
|
|
from frigate.util import file as file_util
|
|
|
|
|
|
class TestFileUtils(TestCase):
|
|
def _write_clean_snapshot(
|
|
self, clips_dir: str, event_id: str, image: np.ndarray
|
|
) -> None:
|
|
assert cv2.imwrite(
|
|
os.path.join(clips_dir, f"front_door-{event_id}-clean.webp"),
|
|
image,
|
|
)
|
|
|
|
def test_get_event_snapshot_bytes_reads_clean_webp(self):
|
|
event_id = "clean-webp"
|
|
image = np.zeros((100, 200, 3), np.uint8)
|
|
event = SimpleNamespace(
|
|
id=event_id,
|
|
camera="front_door",
|
|
label="Mock",
|
|
top_score=100,
|
|
score=0,
|
|
start_time=0,
|
|
data={
|
|
"box": [0.25, 0.25, 0.25, 0.5],
|
|
"score": 0.85,
|
|
"attributes": [],
|
|
},
|
|
)
|
|
|
|
with (
|
|
tempfile.TemporaryDirectory() as clips_dir,
|
|
patch.object(file_util, "CLIPS_DIR", clips_dir),
|
|
):
|
|
self._write_clean_snapshot(clips_dir, event_id, image)
|
|
|
|
snapshot_image, is_clean = file_util.load_event_snapshot_image(
|
|
event, clean_only=True
|
|
)
|
|
|
|
assert is_clean
|
|
assert snapshot_image is not None
|
|
assert snapshot_image.shape[:2] == image.shape[:2]
|
|
|
|
rendered_bytes, _ = file_util.get_event_snapshot_bytes(
|
|
event,
|
|
ext="jpg",
|
|
timestamp=False,
|
|
bounding_box=True,
|
|
crop=False,
|
|
height=40,
|
|
quality=None,
|
|
timestamp_style=None,
|
|
colormap={},
|
|
)
|
|
assert rendered_bytes is not None
|
|
|
|
rendered_image = cv2.imdecode(
|
|
np.frombuffer(rendered_bytes, dtype=np.uint8),
|
|
cv2.IMREAD_COLOR,
|
|
)
|
|
assert rendered_image is not None
|
|
assert rendered_image.shape[0] == 40
|
|
assert rendered_image.max() > 0
|