mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Refactor latest_frame function to get current frame and frame time together
This commit is contained in:
parent
0b77a8a9e3
commit
094e7de785
@ -1156,7 +1156,7 @@ def latest_frame(camera_name):
|
||||
resize_quality = request.args.get("quality", default=70, type=int)
|
||||
|
||||
if camera_name in current_app.frigate_config.cameras:
|
||||
frame = current_app.detected_frames_processor.get_current_frame(
|
||||
frame, frame_time = current_app.detected_frames_processor.get_current_frame(
|
||||
camera_name, draw_options
|
||||
)
|
||||
retry_interval = float(
|
||||
@ -1164,6 +1164,7 @@ def latest_frame(camera_name):
|
||||
or 10
|
||||
)
|
||||
|
||||
latest_frame = frame_time + retry_interval
|
||||
now = datetime.now().timestamp()
|
||||
if frame is None or now > latest_frame:
|
||||
if (
|
||||
@ -1180,7 +1181,7 @@ def latest_frame(camera_name):
|
||||
)
|
||||
frame = current_app.camera_waiting_image
|
||||
logger.warning(
|
||||
f"Return waiting image for camera {camera_name}: latensy is {datetime.now().timestamp() - latest_frame}s"
|
||||
f"Return waiting image for camera {camera_name}: latency is {datetime.now().timestamp() - latest_frame}s, retry_interval: {retry_interval}s"
|
||||
)
|
||||
else:
|
||||
if current_app.camera_error_image is None:
|
||||
@ -1195,7 +1196,7 @@ def latest_frame(camera_name):
|
||||
|
||||
frame = current_app.camera_error_image
|
||||
logger.warning(
|
||||
f"Return error image for camera {camera_name}: latensy is {datetime.now().timestamp() - latest_frame}s"
|
||||
f"Return error image for camera {camera_name}: latency is {datetime.now().timestamp() - latest_frame}s"
|
||||
)
|
||||
|
||||
height = int(request.args.get("h", str(frame.shape[0])))
|
||||
|
||||
@ -11,6 +11,7 @@ from typing import Callable
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
from cv2 import Mat
|
||||
|
||||
from frigate.comms.dispatcher import Dispatcher
|
||||
from frigate.config import (
|
||||
@ -1032,18 +1033,17 @@ class TrackedObjectProcessor(threading.Thread):
|
||||
else:
|
||||
return {}
|
||||
|
||||
def get_current_frame(self, camera, draw_options={}):
|
||||
def get_current_frame(self, camera, draw_options={}) -> tuple[Mat, float]:
|
||||
if camera == "birdseye":
|
||||
return self.frame_manager.get(
|
||||
"birdseye",
|
||||
(self.config.birdseye.height * 3 // 2, self.config.birdseye.width),
|
||||
)
|
||||
|
||||
return self.camera_states[camera].get_current_frame(draw_options)
|
||||
|
||||
def get_current_frame_time(self, camera) -> int:
|
||||
"""Returns the latest frame time for a given camera."""
|
||||
return self.camera_states[camera].current_frame_time
|
||||
return (
|
||||
self.camera_states[camera].get_current_frame(draw_options),
|
||||
self.camera_states[camera].current_frame_time,
|
||||
)
|
||||
|
||||
def run(self):
|
||||
while not self.stop_event.is_set():
|
||||
|
||||
Loading…
Reference in New Issue
Block a user