-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFrameExtract.py
38 lines (31 loc) · 959 Bytes
/
FrameExtract.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
import cv2
import os
import shutil
from glob import glob
folderCounter = 1
folderBase = "FrameFolder"
num = 0
# Function to extract frames from videos
def FrameCapture(path):
global folderCounter, num
vidObj = cv2.VideoCapture(path)
# fps = vidObj.get(cv2.CAP_PROP_FPS)
# print("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))
success = 1
count = 0
folderName = folderBase + str(folderCounter)
os.mkdir(folderName)
folderCounter += 1
while success:
success, image = vidObj.read()
pathname = folderName + "/frame" + str(count) + '.jpg'
cv2.imwrite(pathname, image)
count += 1
num += count
if __name__ == '__main__':
for var in glob("/home/aman/Desktop/Mini-Project/VideoClips/*.mp4"):
print(var)
FrameCapture(var)
# FrameCapture("/home/aman/Desktop/Mini-Project/RoadAccident1.mp4")
print(num)
shutil.rmtree("VideoClips")