Last active
December 28, 2019 11:17
-
-
Save sayakpaul/d8f4bcd25df9f728ce82496dabaa248a 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
def separate_frames(output_dir, df): | |
if not os.path.exists(output_dir): | |
os.mkdir(output_dir) | |
# storing the frames from training videos | |
for i in tqdm(range(df.shape[0])): | |
count = 0 | |
videoFile = df['video_name'][i] | |
videoPath = os.path.join("Videos", "UCF-101", videoFile) | |
cap = cv2.VideoCapture(videoPath) # capturing the video from the given path | |
frameRate = cap.get(5) #frame rate | |
x=1 | |
while(cap.isOpened()): | |
frameId = cap.get(1) #current frame number | |
(grabbed, frame) = cap.read() | |
if (grabbed != True): | |
break | |
if (frameId % math.floor(frameRate) == 0): | |
# storing the frames in a new folder named train_1 | |
frameName = videoFile.split('/')[1].split(' ')[0] + "_frame%d.jpg" % count | |
filename = os.path.join(output_dir, frameName) | |
count+=1 | |
cv2.imwrite(filename, frame) | |
cap.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment