-
Notifications
You must be signed in to change notification settings - Fork 143
/
video.py
56 lines (46 loc) · 1.5 KB
/
video.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import cv2
import numpy as np
import time
class Video(object):
def __init__(self):
self.dirname = ""
self.cap = None
t0 = 0
def start(self):
print("Start video")
if self.dirname == "":
print("invalid filename!")
return
self.cap = cv2.VideoCapture(self.dirname)
fps = self.cap.get(cv2.CAP_PROP_FPS)
self.frame_count = self.cap.get(cv2.CAP_PROP_FRAME_COUNT)
print(fps)
self.t0 = time.time()
print(self.t0)
self.valid = False
try:
resp = self.cap.read()
self.shape = resp[1].shape
self.valid = True
except:
self.shape = None
def stop(self):
if self.cap is not None:
self.cap.release()
print("Stop video")
def get_frame(self):
if self.valid:
_,frame = self.cap.read()
if frame is None:
print("End of video")
self.stop()
print(time.time()-self.t0)
return
else:
frame = cv2.resize(frame,(640,480))
else:
frame = np.ones((480,640,3), dtype=np.uint8)
col = (0,256,256)
cv2.putText(frame, "(Error: Can not load the video)",
(65,220), cv2.FONT_HERSHEY_PLAIN, 2, col)
return frame