Files
frigate/frigate/test/test_util_image.py
T
Josh Hawkins 3ad3802988 bound per-request work in recordings, image, password and motion search endpoints
- /recordings/unavailable walked the requested span one scale bucket at a time on the event loop, so a huge or non-finite range hung the whole API, including /auth. It now walks the gaps between recordings and rejects non-finite bounds.
- latest, mjpeg, event snapshot and recording snapshot heights are capped at the source frame height, and recording frame grabs time out after 30 s.
- Password verify and hash run in a worker thread, so a password change no longer freezes the API while PBKDF2 runs.
- Motion search collected every decoded frame of a run before detecting, up to about 190 MB per run. Frames now stream through detection, and keyframe mode stops reading at the probed keyframe count before falling back to cadence.
2026-11-23 12:55:03 -06:00

37 lines
1.0 KiB
Python

import unittest
import cv2
import numpy as np
from frigate.util.image import get_snapshot_bytes
class TestSnapshotBytes(unittest.TestCase):
def snapshot_shape(self, height: int, crop: bool = False) -> tuple[int, int]:
jpg, _ = get_snapshot_bytes(
np.zeros((90, 160, 3), np.uint8),
0.0,
"jpg",
crop=crop,
height=height,
label="person",
box=(70, 35, 90, 55),
score=None,
area=None,
attributes=None,
color=(255, 255, 255),
)
image = cv2.imdecode(np.frombuffer(jpg, np.uint8), cv2.IMREAD_COLOR)
return image.shape[:2]
def test_height_capped_at_frame_height(self):
self.assertEqual(self.snapshot_shape(45), (45, 80))
self.assertEqual(self.snapshot_shape(5000), (90, 160))
def test_crop_can_scale_up_to_frame_height(self):
self.assertEqual(self.snapshot_shape(5000, crop=True)[0], 90)
if __name__ == "__main__":
unittest.main()