forked from matthewcrotty/Smart-Traffic-Lights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoprocessing.py
38 lines (32 loc) · 850 Bytes
/
videoprocessing.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 numpy
import cv2
import os
import pickle
#Read all video files from input folder
filedir = [f for f in os.listdir("./inputframes") if ".png" in f]
#Create directory with video data
imgcontent = []
for f in filedir:
cap = cv2.VideoCapture("./inputvideo/"+f)
while(cap.isOpened()):
success, frame = cap.read()
if success:
imgcontent.append(frame)
else:
break
cap.release()
#Write to file
try:
with open("./videodata/videodata", 'wb') as f:
pickle.dump(imgcontent, f, pickle.HIGHEST_PROTOCOL)
except Exception as e:
print('Unable to save data to file. Error:', e)
'''
cap = cv2.VideoCapture('563398107.mp4')
while(cap.isOpened()):
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(0) & 0xFF == ord('q'):
break
cap.release()
'''