Skip to content

Commit

Permalink
Add ability to get snapshot of birdseye when birdseye restream is ena…
Browse files Browse the repository at this point in the history
…bled
  • Loading branch information
NickM-27 committed Dec 29, 2022
1 parent c491605 commit 45c7c97
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
18 changes: 18 additions & 0 deletions frigate/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,24 @@ def latest_frame(camera_name):

frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)

ret, jpg = cv2.imencode(
".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY), resize_quality]
)
response = make_response(jpg.tobytes())
response.headers["Content-Type"] = "image/jpeg"
response.headers["Cache-Control"] = "no-store"
return response
elif camera_name == "birdseye" and current_app.frigate_config.restream.birdseye:
frame = cv2.cvtColor(
current_app.detected_frames_processor.get_current_frame(camera_name),
cv2.COLOR_YUV2BGR_I420,
)

height = int(request.args.get("h", str(frame.shape[0])))
width = int(height * frame.shape[1] / frame.shape[0])

frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)

ret, jpg = cv2.imencode(
".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY), resize_quality]
)
Expand Down
6 changes: 6 additions & 0 deletions frigate/object_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,12 @@ def get_best(self, camera, label):
return {}

def get_current_frame(self, camera, draw_options={}):
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:
Expand Down
15 changes: 13 additions & 2 deletions frigate/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def run(self):


class BirdsEyeFrameManager:
def __init__(self, config, frame_manager: SharedMemoryFrameManager):
def __init__(self, config: FrigateConfig, frame_manager: SharedMemoryFrameManager):
self.config = config
self.mode = config.birdseye.mode
self.frame_manager = frame_manager
Expand Down Expand Up @@ -463,6 +463,12 @@ def receiveSignal(signalNumber, frame):

birdseye_manager = BirdsEyeFrameManager(config, frame_manager)

if config.restream.birdseye:
birdseye_buffer = frame_manager.create(
"birdseye",
birdseye_manager.yuv_shape[0] * birdseye_manager.yuv_shape[1],
)

while not stop_event.is_set():
try:
(
Expand Down Expand Up @@ -500,7 +506,12 @@ def receiveSignal(signalNumber, frame):
frame_time,
frame,
):
converters["birdseye"].write(birdseye_manager.frame.tobytes())
frame_bytes = birdseye_manager.frame.tobytes()

if config.restream.birdseye:
birdseye_buffer[:] = frame_bytes

converters["birdseye"].write(frame_bytes)

if camera in previous_frames:
frame_manager.delete(f"{camera}{previous_frames[camera]}")
Expand Down

0 comments on commit 45c7c97

Please sign in to comment.