-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractScreenshots.py
More file actions
47 lines (35 loc) · 1.66 KB
/
extractScreenshots.py
File metadata and controls
47 lines (35 loc) · 1.66 KB
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
39
40
41
42
43
44
45
46
47
import os
import cv2
def is_cv2():
(major, _, _) = cv2.__version__.split(".")
return major == 2
def extract_images(fullFilePath, outputFolderPath, intervalInSeconds, startTimeInSeconds):
if os.path.exists(fullFilePath):
_, filename = os.path.split(fullFilePath)
filename,_ = os.path.splitext(filename)
vidCap = cv2.VideoCapture(fullFilePath)
fps = vidCap.get(cv2.CAP_PROP_FPS)
if is_cv2():
totalFrames = int(vidCap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
else:
totalFrames = int(vidCap.get(cv2.CAP_PROP_FRAME_COUNT))
intervalInFrames = int(intervalInSeconds * fps) - 1
startFrame = int(startTimeInSeconds * fps)
currFrame = 0
frameOfInterest = startFrame
while currFrame <= totalFrames:
_, frame = vidCap.read()
if currFrame == frameOfInterest:
print('Extracting screenshot at frame {0}'.format(currFrame))
outputFileName = filename + '_Frame_' + str(currFrame) + '.jpg'
outputFilePath = os.path.join(outputFolderPath, outputFileName)
cv2.imwrite(outputFilePath, frame)
frameOfInterest = currFrame + intervalInFrames
currFrame = currFrame + 1
vidCap.release()
if __name__ == '__main__':
videoPath = 'C:\\Users\\reyl2\\Documents\\src\\arup\\CentralFootbridge_190228-0723-0823_15fps_tracked.mp4'
outputFolderPath = 'C:\\Users\\reyl2\\Documents\\src\\arup\\screenshots\\'
if not os.path.exists(outputFolderPath):
os.mkdir(outputFolderPath)
extract_images(videoPath, outputFolderPath, 5, 0)