110 cap = video.create_capture(fn)
114 def process_frame(frame, t0):
116 frame = cv.medianBlur(frame, 19)
117 frame = cv.medianBlur(frame, 19)
120 threadn = cv.getNumberOfCPUs()
121 pool = ThreadPool(processes = threadn)
126 latency = StatValue()
127 frame_interval = StatValue()
128 last_frame_time =
clock()
130 while len(pending) > 0
and pending[0].ready():
131 res, t0 = pending.popleft().get()
132 latency.update(
clock() - t0)
133 draw_str(res, (20, 20),
"threaded : " +
str(threaded_mode))
134 draw_str(res, (20, 40),
"latency : %.1f ms" % (latency.value*1000))
135 draw_str(res, (20, 60),
"frame interval : %.1f ms" % (frame_interval.value*1000))
136 draw_str(res, (20, 80),
"FPS : %.1f" % (1.0/frame_interval.value))
137 cv.imshow(
'threaded video', res)
138 if len(pending) < threadn:
139 _ret, frame = cap.read()
141 frame_interval.update(t - last_frame_time)
144 task = pool.apply_async(process_frame, (frame.copy(), t))
146 task = DummyTask(process_frame(frame, t))
150 threaded_mode =
not threaded_mode
160 print(
"[INFO] elasped time: {:.2f}".format(fps.elapsed()))
161 print(
"[INFO] approx. FPS: {:.2f}".format(fps.fps()))
def draw_str(dst, target, s)