-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo_players.py
More file actions
75 lines (55 loc) · 1.74 KB
/
video_players.py
File metadata and controls
75 lines (55 loc) · 1.74 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Author: Aiden Stevenson Bradwell
Date: 2021-11-19
Affiliation: University of Ottawa, Ottawa, Ontario (Student)
Description:
Declare two class...
VideoGetter: Read frames from webcam
VideoShower: Display frames after being filtered
Libraries required:
N/A
"""
from threading import Thread
import cv2
class VideoGetter:
""" Read frames from webcam """
def __init__(self, src):
self.camera = src
(self.grabbed, self.frame) = self.camera.read()
self.stopped = False
self.frame_queue = []
def start(self):
Thread(target=self.get, args=()).start()
return self
def get(self):
while not self.stopped:
if not self.grabbed:
self.stop()
else:
(self.grabbed, cur_frame) = self.camera.read()
self.frame_queue.append(cur_frame)
def stop(self):
self.stopped = True
class VideoShower:
""" Display frames after being filtered """
def __init__(self, frame_queue, gui_frame):
self.frame_queue = frame_queue
self.gui = gui_frame
self.stopped = False
self.cur_image = None
self.panel = None
self.flip = True
def start(self):
Thread(target=self.show, args=()).start()
return self
def show(self):
while not self.stopped:
cv2.waitKey(10)
# if the panel is not None, we need to initialize it
if len(self.frame_queue) > 0:
image = self.frame_queue.pop()
if self.flip:
image = cv2.flip(image, 0)
cv2.imshow("Video Feed...", image)
def stop(self):
self.stopped = True