cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
var.video_threaded Namespace Reference

Classes

class  FPS
 
class  DummyTask
 

Functions

def main ()
 

Function Documentation

◆ main()

def var.video_threaded.main ( )

Definition at line 103 of file video_threaded.py.

103 def main():
104  import sys
105 
106  try:
107  fn = sys.argv[1]
108  except:
109  fn = 0
110  cap = video.create_capture(fn)
111  fps = FPS().start()
112 
113 
114  def process_frame(frame, t0):
115  # some intensive computation...
116  frame = cv.medianBlur(frame, 19)
117  frame = cv.medianBlur(frame, 19)
118  return frame, t0
119 
120  threadn = cv.getNumberOfCPUs()
121  pool = ThreadPool(processes = threadn)
122  pending = deque()
123 
124  threaded_mode = True
125 
126  latency = StatValue()
127  frame_interval = StatValue()
128  last_frame_time = clock()
129  while True:
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()
140  t = clock()
141  frame_interval.update(t - last_frame_time)
142  last_frame_time = t
143  if threaded_mode:
144  task = pool.apply_async(process_frame, (frame.copy(), t))
145  else:
146  task = DummyTask(process_frame(frame, t))
147  pending.append(task)
148  ch = cv.waitKey(1)
149  if ch == ord(' '):
150  threaded_mode = not threaded_mode
151  if ch == 27:
152  break
153  # update the FPS counter
154  fps.update()
155 
156  print('Done')
157 
158  # stop the timer and display FPS information
159  fps.stop()
160  print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
161  print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
162 
def clock()
Definition: common.py:174
def draw_str(dst, target, s)
Definition: common.py:113
Here is the call graph for this function: