forked from guglielmocamporese/hands-segmentation-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_frames.py
38 lines (34 loc) · 1.12 KB
/
extract_frames.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'''
Script to extract frames and name them sequentially from a video
Takes in the args [--pathIn] and [--pathOut]
'''
import sys
import argparse
import os
import cv2
print(cv2.__version__)
def extractImages(pathIn, pathOut):
# Create the pathOut if it doesnt exist
if not os.path.exists(pathOut):
os.mkdir(pathOut)
count = 0
vidcap = cv2.VideoCapture(pathIn)
success,image = vidcap.read()
success = True
while success:
# Uncomment this line to save 1 frame per 1000 frames
# vidcap.set(cv2.CAP_PROP_POS_MSEC,(count*1000)) # added this line
success,image = vidcap.read()
print ('Read a new frame: ', success)
if success == False:
break
imPath = os.path.join(pathOut, 'frame{}.jpg'.format(count))
cv2.imwrite(imPath, image) # save frame as JPEG file
count = count + 1
if __name__=="__main__":
a = argparse.ArgumentParser()
a.add_argument("--inPath", help="path to video")
a.add_argument("--outPath", help="path to images")
args = a.parse_args()
print(args)
extractImages(args.inPath, args.outPath)