Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix array broadcasting #364

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions scripts/sampling/simple_video_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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
)
Expand All @@ -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)
Expand Down