From a4594b64817d8c4f34ae9b882bf81a11d6e31e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erce=20G=C3=BCder?= Date: Fri, 7 Jun 2024 13:17:58 +0300 Subject: [PATCH 1/2] fix broadcasting --- scripts/sampling/simple_video_sample.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/sampling/simple_video_sample.py b/scripts/sampling/simple_video_sample.py index 29a8b8581..8fa2d69f5 100644 --- a/scripts/sampling/simple_video_sample.py +++ b/scripts/sampling/simple_video_sample.py @@ -136,7 +136,7 @@ def sample( # resize object in frame image_arr = np.array(image) - in_w, in_h = image_arr.shape[:2] + in_h, in_w = image_arr.shape[:2] ret, mask = cv2.threshold( np.array(image.split()[-1]), 0, 255, cv2.THRESH_BINARY ) @@ -145,13 +145,19 @@ def sample( side_len = ( int(max_size / image_frame_ratio) if image_frame_ratio is not None - else in_w + else max(in_w, in_h) ) padded_image = np.zeros((side_len, side_len, 4), dtype=np.uint8) center = side_len // 2 + + y_start = center - h // 2 + y_start = 0 if y_start < 0 else y_start + x_start = center - w // 2 + x_start = 0 if x_start < 0 else x_start + padded_image[ - center - h // 2 : center - h // 2 + h, - center - w // 2 : center - w // 2 + w, + y_start : y_start + h, + x_start : x_start + w, ] = image_arr[y : y + h, x : x + w] # resize frame to 576x576 rgba = Image.fromarray(padded_image).resize((576, 576), Image.LANCZOS) From a85d8fff6181b6e57a9bb1236f48225cb9d4d3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erce=20G=C3=BCder?= Date: Sat, 8 Jun 2024 21:04:29 +0300 Subject: [PATCH 2/2] fix file extension check --- scripts/sampling/simple_video_sample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sampling/simple_video_sample.py b/scripts/sampling/simple_video_sample.py index 8fa2d69f5..3cadb10c0 100644 --- a/scripts/sampling/simple_video_sample.py +++ b/scripts/sampling/simple_video_sample.py @@ -107,7 +107,7 @@ def sample( path = Path(input_path) all_img_paths = [] if path.is_file(): - if any([input_path.endswith(x) for x in ["jpg", "jpeg", "png"]]): + if any([input_path.lower().endswith(x) for x in ["jpg", "jpeg", "png"]]): all_img_paths = [input_path] else: raise ValueError("Path is not valid image file.")