in data/video_iterator.py [0:0]
def extract_frames(self, idxs, force_color=True):
assert self.cap is not None, "No opened video."
if len(idxs) < 1:
return []
frames = []
pre_idx = max(idxs)
for idx in idxs:
assert (self.frame_count < 0) or (idx < self.frame_count), \
"idxs: {} > total valid frames({})".format(idxs, self.frame_count)
if pre_idx != (idx - 1):
self.cap.set(cv2.CAP_PROP_POS_FRAMES, idx)
res, frame = self.cap.read() # in BGR/GRAY format
pre_idx = idx
if not res:
logging.warning("VideoIter:: >> failed to grab frame {} from `{}'".format(idx, self.vid_path))
return None
# Convert to RGB
if len(frame.shape) < 3:
if force_color:
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
else:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frames.append(frame)
return frames