precompute the layout offsets and dimensions

This commit is contained in:
Blake Blackshear 2021-06-11 19:26:00 -05:00
parent cbd418b8de
commit babe1dd1eb
2 changed files with 23 additions and 16 deletions

View File

@ -135,7 +135,13 @@ class BirdsEyeFrameManager:
) )
channel_dims = self.cameras[camera]["channel_dims"] 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): def camera_active(self, object_box_count, motion_box_count):
if self.mode == "continuous": if self.mode == "continuous":
@ -192,6 +198,16 @@ class BirdsEyeFrameManager:
self.active_cameras = set() 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) removed_cameras = self.active_cameras.difference(active_cameras)
added_cameras = active_cameras.difference(self.active_cameras) added_cameras = active_cameras.difference(self.active_cameras)

View File

@ -235,29 +235,20 @@ def yuv_crop_and_resize(frame, region, height=None):
def copy_yuv_to_position( def copy_yuv_to_position(
position,
destination_frame, destination_frame,
destination_dim, destination_offset,
destination_shape,
source_frame=None, source_frame=None,
source_channel_dim=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 # get the coordinates of the channels for this position in the layout
y, u1, u2, v1, v2 = get_yuv_crop( y, u1, u2, v1, v2 = get_yuv_crop(
destination_frame.shape, destination_frame.shape,
( (
x_offset, destination_offset[1],
y_offset, destination_offset[0],
x_offset + layout_shape[1], destination_offset[1] + destination_shape[1],
y_offset + layout_shape[0], destination_offset[0] + destination_shape[0],
), ),
) )