cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_harris_numpi_video_threaded Namespace Reference

Classes

class  FPS
 
class  DummyTask
 

Functions

def main ()
 

Variables

string video_common_lib = os.environ['cFpRootDir'] + "HOST/vision/common/languages/python/var"
 
string trieres_lib = os.environ['cFpRootDir'] + "HOST/vision/harris/languages/python/build"
 
int height = 512
 
int total_size = height * width
 

Function Documentation

◆ main()

def test_harris_numpi_video_threaded.main ( )

Definition at line 105 of file test_harris_numpi_video_threaded.py.

105 def main():
106  import sys
107 
108  try:
109  fn = sys.argv[1]
110  except:
111  fn = 0
112  cap = video.create_capture(fn)
113  fps = FPS().start()
114 
115  video_name = str(fn)+"_out.avi"
116  video_out = cv.VideoWriter(video_name, cv.VideoWriter_fourcc('M','J','P','G'), 10, (width,height))
117 
118  fpgas = deque([ ["10.12.200.3" , "2718"],
119  ["10.12.200.165" , "2719"]])
120 
121 
122  def process_frame(frame, t0, accel_mode, fpga):
123  if accel_mode:
124  print("Will execute on fpga with ip:port: "+fpga[0]+":"+fpga[1])
125  # some intensive computation...
126  # frame = cv.medianBlur(frame, 19)
127  # Converting to grayscale
128  frame = cv.cvtColor(frame, cv.COLOR_RGB2GRAY)
129  # Adjusting the image file if needed
130  if ((frame.shape[0] != height) or (frame.shape[1] != width)):
131  print("WARNING: The image was resized from [", frame.shape[0] , " x ", frame.shape[1] , "] to [", height , " x ", width, "]")
132  dim = (width, height)
133  frame = cv.resize(frame, dim, interpolation = cv.INTER_LINEAR)
134  # Flattening the image from 2D to 1D
135  image = frame.flatten()
136  output_array = _trieres_harris_numpi.harris(image, total_size, fpga[0], fpga[1])
137  # Convert 1D array to a 2D numpy array
138  frame = np.reshape(output_array, (height, width))
139  print("Declare free the fpga: "+str(fpga))
140  fpgas.appendleft(fpga)
141  else:
142  frame = cv.medianBlur(frame, 19)
143  frame = cv.medianBlur(frame, 19)
144  frame = cv.medianBlur(frame, 19)
145  return frame, t0
146 
147  threadn = 4 #cv.getNumberOfCPUs()
148  pool = ThreadPool(processes = threadn)
149  pending = deque()
150 
151  threaded_mode = True
152  accel_mode = True
153  latency = StatValue()
154  frame_interval = StatValue()
155  last_frame_time = clock()
156  while True:
157  while len(pending) > 0 and pending[0].ready() and len(fpgas) > 0:
158  res, t0 = pending.popleft().get()
159  latency.update(clock() - t0)
160 # video_out.write(res)
161  draw_str(res, (20, 20), "threaded : " + str(threaded_mode))
162  draw_str(res, (20, 40), "cloudFPA : " + str(accel_mode))
163  draw_str(res, (20, 60), "latency : %.1f ms" % (latency.value*1000))
164  draw_str(res, (20, 80), "frame interval : %.1f ms" % (frame_interval.value*1000))
165  draw_str(res, (20, 100), "FPS : %.1f" % (1.0/frame_interval.value))
166  #cv.imshow('threaded video', res)
167  if len(pending) < threadn and len(fpgas) != 0:
168  _ret, frame = cap.read()
169  if _ret is False:
170  print("Reached EOF.")
171  print("Saved video: " + video_name)
172  video_out.release()
173  break
174  else:
175  video_out.write(frame)
176  t = clock()
177  frame_interval.update(t - last_frame_time)
178  last_frame_time = t
179  # update the FPS counter
180  fps.update()
181  if accel_mode:
182  fpga = fpgas.popleft()
183  else:
184  fpga = 0
185  if threaded_mode:
186  task = pool.apply_async(process_frame, (frame.copy(), t, accel_mode, fpga))
187  else:
188  task = DummyTask(process_frame(frame, t, accel_mode, fpga))
189  pending.append(task)
190  else:
191  if accel_mode:
192  print("Waiting for a free fpga")
193 
194  ch = cv.waitKey(1)
195  if ch == ord(' '):
196  threaded_mode = not threaded_mode
197  if ch == ord('f'):
198  accel_mode = not accel_mode
199  if ch == 27:
200  break
201 
202 
203  print('Done')
204 
205  # stop the timer and display FPS information
206  fps.stop()
207  print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
208  print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
209 
def clock()
Definition: common.py:174
def draw_str(dst, target, s)
Definition: common.py:113
Here is the call graph for this function:

Variable Documentation

◆ height

int test_harris_numpi_video_threaded.height = 512

Definition at line 63 of file test_harris_numpi_video_threaded.py.

◆ total_size

int test_harris_numpi_video_threaded.total_size = height * width

Definition at line 64 of file test_harris_numpi_video_threaded.py.

◆ trieres_lib

string test_harris_numpi_video_threaded.trieres_lib = os.environ['cFpRootDir'] + "HOST/vision/harris/languages/python/build"

Definition at line 57 of file test_harris_numpi_video_threaded.py.

◆ video_common_lib

string test_harris_numpi_video_threaded.video_common_lib = os.environ['cFpRootDir'] + "HOST/vision/common/languages/python/var"

Definition at line 45 of file test_harris_numpi_video_threaded.py.