-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoSequence.py
62 lines (50 loc) · 1.84 KB
/
VideoSequence.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
57
58
59
60
61
62
import cv2
import numpy as np
from utils import toGray
class VideoSequence:
def __init__(self):
pass
def __readFrame__(self):
img = self.__cap__.read()[1]
return cv2.flip(img, 1)
def start(self):
self.__cap__ = cv2.VideoCapture(0)
for i in range(10):
self.__beforePrev__ = self.__readFrame__()
self.__beforePrev__ = self.__readFrame__()
self.__beforePrev_g__ = toGray(self.__beforePrev__)
cv2.waitKey(20)
self.__prev__ = self.__readFrame__()
self.__prev_g__ = toGray(self.__prev__)
cv2.waitKey(20)
self.__curr__ = self.__readFrame__()
self.__curr_g__ = toGray(self.__curr__)
cv2.waitKey(20)
return self
def process(self):
self.__beforePrev__ = self.__prev__
self.__prev__ = self.__curr__
self.__curr__ = self.__readFrame__()
self.__beforePrev_g__ = self.__prev_g__
self.__prev_g__ = self.__curr_g__
self.__curr_g__ = toGray(self.__curr__)
if cv2.waitKey(1) == 27:
quit() # esc to quit
def getFramesByType(fType):
return self.getFrames(fType)
return getFramesByType
def getFrames(self, fType):
if (fType.upper() == "BGR"):
return (self.__curr__, self.__beforePrev__, self.__prev__)
elif(fType.upper() == "GRAY"):
return (self.__curr_g__, self.__beforePrev_g__, self.__prev_g__)
else:
raise Exception("Not supported frames of type {}, only supproted are 'BGR', 'gray'".format(fType))
def __del__(self):
cv2.destroyAllWindows()
self.__cap__.release()
if __name__ == "__main__":
vs = VideoSequence().start()
while(True):
frames = vs.process()("BGR")
cv2.imshow("test diff", cv2.absdiff(frames[-2],frames[0]))