-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShow_thread.py
58 lines (41 loc) · 1.41 KB
/
Show_thread.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
from threading import Thread
import cv2 as cv
class Show_thread:
"""
The Show_thread class is used to display the data capturing stream
- This should help with processing speed and free up the main thread to
focus more on data processing
"""
def __init__(self, curr_frame = None):
# grabs the current frame and saves it
self.frame = curr_frame
# Sets task not to end
self.end_task = False
def start(self):
'''
start() initiates the thread to start displaying frames
'''
T = Thread(target=self.show_frame)
T.setDaemon(True)
T.start()
return self
def show_frame(self):
'''
show_frame() displays the most recent frame
- set to run on its own thread to help with processing time
Note: This seems to run into issues while run on MacOS
The process will keep running until:
- the user presses "q" to end task
- Process is manually stopped
'''
while not self.end_task:
# Show current frame
cv.imshow("Frame", self.frame)
# End scream if necessary
if cv.waitKey(1) == ord("q"):
self.end_task = True
def stop(self):
'''
stop() ends the process and stops displaying the frames
'''
self.end_task= True