forked from matthewcrotty/Smart-Traffic-Lights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videotoframes.py
36 lines (31 loc) · 886 Bytes
/
videotoframes.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
import numpy
import cv2
import os
import pickle
import shutil
import numpy as np
inputfolder = "./inputvideo/"
outputfolder = "./inputframes/"
#Read all video files from input folder
filedir = [f for f in os.listdir(inputfolder) if ".mp4" in f]
if os.path.exists(outputfolder):
shutil.rmtree(outputfolder)
if not os.path.exists(outputfolder):
os.makedirs(outputfolder)
#Create directory with video data
counter = 0;
for f in filedir:
cap = cv2.VideoCapture(inputfolder+f)
while(cap.isOpened()):
success, frame = cap.read();
if(counter > 10):
# break
pass
if success:
counter+=1
cv2.imwrite(outputfolder+str(counter)+'.png',frame);
edges = cv2.Canny(frame,10,60)
cv2.imwrite(outputfolder+"e"+str(counter)+'.png',edges);
else:
break
cap.release()