-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
executable file
·56 lines (39 loc) · 1.22 KB
/
app.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
#!/usr/bin/env python3
import numpy as np
from vcamera import VCamera
class MyVCamera(VCamera):
"""
Slow motion
"""
FRAMES = 10
LAMBDA = 0.2
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.prev_frame = None
def transform(self, bgr_frame):
if self.prev_frame is None:
self.prev_frame = bgr_frame
frame = (
MyVCamera.LAMBDA * bgr_frame + (1.0 - MyVCamera.LAMBDA) * self.prev_frame
)
self.prev_frame = frame
return frame.astype(np.uint8)
class MementoCamera(VCamera):
FRAMES = 100
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.new_memory = []
self.current_memory = []
def transform(self, bgr_frame):
self.new_memory.append(bgr_frame)
if len(self.new_memory) == MementoCamera.FRAMES:
self.current_memory = self.new_memory
self.new_memory = []
if len(self.current_memory) == 0:
return bgr_frame
else:
return self.current_memory[-1 - len(self.new_memory)]
if __name__ == "__main__":
vcam = MementoCamera(flip=True)
vcam.start()
vcam.join()