mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-09-10 17:51:45 +02:00
wip yuv_rgb refactor
This commit is contained in:
parent
46e5a042ae
commit
f4a0ec43a6
@ -149,8 +149,9 @@ def get_yuv_crop(frame_shape, crop):
|
|||||||
return y, u1, u2, v1, v2
|
return y, u1, u2, v1, v2
|
||||||
|
|
||||||
|
|
||||||
def yuv_region_2_rgb(frame, region):
|
def yuv_crop_and_resize(frame, region, height=None):
|
||||||
try:
|
# Crops and resizes a YUV frame while maintaining aspect ratio
|
||||||
|
# https://stackoverflow.com/a/57022634
|
||||||
height = frame.shape[0] // 3 * 2
|
height = frame.shape[0] // 3 * 2
|
||||||
width = frame.shape[1]
|
width = frame.shape[1]
|
||||||
|
|
||||||
@ -173,6 +174,7 @@ def yuv_region_2_rgb(frame, region):
|
|||||||
|
|
||||||
# create the yuv region frame
|
# create the yuv region frame
|
||||||
# make sure the size is a multiple of 4
|
# 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
|
size = (region[3] - region[1]) // 4 * 4
|
||||||
yuv_cropped_frame = np.zeros((size + size // 2, size), np.uint8)
|
yuv_cropped_frame = np.zeros((size + size // 2, size), np.uint8)
|
||||||
# fill in black
|
# fill in black
|
||||||
@ -228,6 +230,13 @@ def yuv_region_2_rgb(frame, region):
|
|||||||
+ uv_crop_width,
|
+ uv_crop_width,
|
||||||
] = frame[v2[1] : v2[3], v2[0] : v2[2]]
|
] = 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)
|
return cv2.cvtColor(yuv_cropped_frame, cv2.COLOR_YUV2RGB_I420)
|
||||||
except:
|
except:
|
||||||
print(f"frame.shape: {frame.shape}")
|
print(f"frame.shape: {frame.shape}")
|
||||||
|
Loading…
Reference in New Issue
Block a user