Created
December 28, 2019 11:19
-
-
Save sayakpaul/1c22a7037ca33fb3af82fd04aa82ea0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
single_digits = [i for i in range(10)] | |
def extract_frames(df, output_dir): | |
if not os.path.exists(output_dir): | |
os.mkdir(output_dir) | |
for i in tqdm(range(df.shape[0])): | |
count = 0 | |
videoFile = df['video_name'][i] | |
videoPath = os.path.join("Videos", "UCF-101", videoFile) | |
# print(videoFile, videoPath) | |
cap = cv2.VideoCapture(videoPath) # capturing the video from the given path | |
while True: | |
(grabbed, frame) = cap.read() | |
if not grabbed: | |
break | |
if count == 60: | |
break | |
# This is to ensure the order of the frames | |
if count in single_digits: | |
frameName = videoFile.split("/")[1].split(" ")[0] + "_0%d.jpg" % count | |
else: | |
frameName = videoFile.split("/")[1].split(" ")[0] + "_%d.jpg" % count | |
framePath = os.path.join(output_dir, frameName) | |
cv2.imwrite(framePath, frame) | |
count+=1 | |
cap.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment