mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
precompute the layout offsets and dimensions
This commit is contained in:
parent
cbd418b8de
commit
babe1dd1eb
@ -135,7 +135,13 @@ class BirdsEyeFrameManager:
|
||||
)
|
||||
channel_dims = self.cameras[camera]["channel_dims"]
|
||||
|
||||
copy_yuv_to_position(position, self.frame, self.layout_dim, frame, channel_dims)
|
||||
copy_yuv_to_position(
|
||||
self.frame,
|
||||
self.layout_offsets[position],
|
||||
self.layout_frame_shape,
|
||||
frame,
|
||||
channel_dims,
|
||||
)
|
||||
|
||||
def camera_active(self, object_box_count, motion_box_count):
|
||||
if self.mode == "continuous":
|
||||
@ -192,6 +198,16 @@ class BirdsEyeFrameManager:
|
||||
|
||||
self.active_cameras = set()
|
||||
|
||||
self.layout_offsets = []
|
||||
|
||||
# calculate the x and y offset for each position in the layout
|
||||
for position in range(0, len(self.camera_layout)):
|
||||
y_offset = self.layout_frame_shape[0] * math.floor(
|
||||
position / self.layout_dim
|
||||
)
|
||||
x_offset = self.layout_frame_shape[1] * (position % self.layout_dim)
|
||||
self.layout_offsets.append((y_offset, x_offset))
|
||||
|
||||
removed_cameras = self.active_cameras.difference(active_cameras)
|
||||
added_cameras = active_cameras.difference(self.active_cameras)
|
||||
|
||||
|
@ -235,29 +235,20 @@ def yuv_crop_and_resize(frame, region, height=None):
|
||||
|
||||
|
||||
def copy_yuv_to_position(
|
||||
position,
|
||||
destination_frame,
|
||||
destination_dim,
|
||||
destination_offset,
|
||||
destination_shape,
|
||||
source_frame=None,
|
||||
source_channel_dim=None,
|
||||
):
|
||||
# TODO: consider calculating this on layout reflow instead of all the time
|
||||
layout_shape = (
|
||||
(destination_frame.shape[0] // 3 * 2) // destination_dim,
|
||||
destination_frame.shape[1] // destination_dim,
|
||||
)
|
||||
# calculate the x and y offset for the frame in the layout
|
||||
y_offset = layout_shape[0] * math.floor(position / destination_dim)
|
||||
x_offset = layout_shape[1] * (position % destination_dim)
|
||||
|
||||
# get the coordinates of the channels for this position in the layout
|
||||
y, u1, u2, v1, v2 = get_yuv_crop(
|
||||
destination_frame.shape,
|
||||
(
|
||||
x_offset,
|
||||
y_offset,
|
||||
x_offset + layout_shape[1],
|
||||
y_offset + layout_shape[0],
|
||||
destination_offset[1],
|
||||
destination_offset[0],
|
||||
destination_offset[1] + destination_shape[1],
|
||||
destination_offset[0] + destination_shape[0],
|
||||
),
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user