-
Notifications
You must be signed in to change notification settings - Fork 91
/
run.py
66 lines (53 loc) · 2.1 KB
/
run.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
63
64
65
66
import cv2
import numpy as np
from pulse import Pulse
import time
from threading import Lock, Thread
from plot_cont import DynamicPlot
from capture_frames import CaptureFrames
from process_mask import ProcessMasks
from utils import *
import multiprocessing as mp
import sys
from optparse import OptionParser
class RunPOS():
def __init__(self, sz=270, fs=28, bs=30, plot=False):
self.batch_size = bs
self.frame_rate = fs
self.signal_size = sz
self.plot = plot
def __call__(self, source):
time1=time.time()
mask_process_pipe, chil_process_pipe = mp.Pipe()
self.plot_pipe = None
if self.plot:
self.plot_pipe, plotter_pipe = mp.Pipe()
self.plotter = DynamicPlot(self.signal_size, self.batch_size)
self.plot_process = mp.Process(target=self.plotter, args=(plotter_pipe,), daemon=True)
self.plot_process.start()
process_mask = ProcessMasks(self.signal_size, self.frame_rate, self.batch_size)
mask_processer = mp.Process(target=process_mask, args=(chil_process_pipe, self.plot_pipe, source, ), daemon=True)
mask_processer.start()
capture = CaptureFrames(self.batch_size, source, show_mask=True)
capture(mask_process_pipe, source)
mask_processer.join()
if self.plot:
self.plot_process.join()
time2=time.time()
time2=time.time()
print(f'time {time2-time1}')
def get_args():
parser = OptionParser()
parser.add_option('-s', '--source', dest='source', default=0,
help='Signal Source: 0 for webcam or file path')
parser.add_option('-b', '--batch-size', dest='batchsize', default=30,
type='int', help='batch size')
parser.add_option('-f', '--frame-rate', dest='framerate', default=25,
help='Frame Rate')
(options, _) = parser.parse_args()
return options
if __name__=="__main__":
args = get_args()
source = args.source
runPOS = RunPOS(270, args.framerate, args.batchsize, True)
runPOS(source)