frame_name = name_pattern % (length_id + offset)
frame_path = directory + "/" + frame_name
cv_img_origin = cv2.imread(frame_path, cv_read_flag)
if cv_img_origin is None:
raise(RuntimeError("Could not load file %s. Check data path." % (frame_path)))
if new_width > 0 and new_height > 0:
cv_img = cv2.resize(cv_img_origin, (new_width, new_height), interpolation)
else:
cv_img = cv_img_origin
cv_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)
sampled_list.append(cv_img)
// the shape of clip_input will be H x W x C, and C = num_segments * new_length * 3
clip_input = np.concatenate(sampled_list, axis=2)
return nd.array(clip_input)
After Change
if cv_img is None:
if length_id == 1:
raise(RuntimeError("Could not load file %s starting at frame %d. Check data path." % (frame_path, offset)))
sampled_list.append(np.zeros((new_height, new_width, 3))) // pad black frames if this video clip does not have `skip_length` frames
continue
if new_width > 0 and new_height > 0:
h, w, _ = cv_img.shape