wip yuv_rgb refactor

This commit is contained in:
Blake Blackshear 2021-05-08 08:27:27 -05:00
parent 46e5a042ae
commit f4a0ec43a6

View File

@ -149,8 +149,9 @@ def get_yuv_crop(frame_shape, crop):
return y, u1, u2, v1, v2
def yuv_region_2_rgb(frame, region):
try:
def yuv_crop_and_resize(frame, region, height=None):
# Crops and resizes a YUV frame while maintaining aspect ratio
# https://stackoverflow.com/a/57022634
height = frame.shape[0] // 3 * 2
width = frame.shape[1]
@ -173,6 +174,7 @@ def yuv_region_2_rgb(frame, region):
# create the yuv region frame
# make sure the size is a multiple of 4
# TODO: this should be based on the size after resize now
size = (region[3] - region[1]) // 4 * 4
yuv_cropped_frame = np.zeros((size + size // 2, size), np.uint8)
# fill in black
@ -228,6 +230,13 @@ def yuv_region_2_rgb(frame, region):
+ uv_crop_width,
] = frame[v2[1] : v2[3], v2[0] : v2[2]]
return yuv_cropped_frame
def yuv_region_2_rgb(frame, region):
try:
# TODO: does this copy the numpy array?
yuv_cropped_frame = yuv_crop_and_resize(frame, region)
return cv2.cvtColor(yuv_cropped_frame, cv2.COLOR_YUV2RGB_I420)
except:
print(f"frame.shape: {frame.shape}")