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

Functions

def crop_square_roi (img, size, interpolation=cv.INTER_AREA, debug_level=debug_level)
 
def patch_sqaure_roi (orig, frame, interpolation=cv.INTER_AREA, debug_level=debug_level)
 
def consumer (accel_mode, fpgas_queue, frame, debug_level=debug_level)
 

Variables

bool ROI = False
 
bool accel_mode = True
 
 debug_level = logging.INFO
 
string config_file = os.environ['cFpRootDir'] + "HOST/vision/median_blur/languages/cplusplus/include/config.h"
 
 level
 
 width = int(line.split()[2])
 
 height = int(line.split()[2])
 
 total_size = height * width
 
 fpgas_queue = Queue(maxsize=100)
 
 tic_capture = time.perf_counter()
 
 cap = cv.VideoCapture(fn)
 
list frames = []
 
list frames_ret = []
 
 ret
 
 frame
 
 toc_capture = time.perf_counter()
 
 tic_consumers = time.perf_counter()
 
list consumers = [consumer.remote(accel_mode, fpgas_queue, frames[i], debug_level=debug_level) for i in range(len(frames))]
 
 toc_consumers = time.perf_counter()
 
 tic_exec = time.perf_counter()
 
 results = ray.get(consumers)
 
 toc_exec = time.perf_counter()
 
 tic_save = time.perf_counter()
 
string video_name = str(fn)+"_out.avi"
 
 video_out = cv.VideoWriter(video_name, cv.VideoWriter_fourcc('M','J','P','G'), 30, (results[0].shape[1],results[0].shape[0]))
 
 toc_save = time.perf_counter()
 

Function Documentation

◆ consumer()

def test_median_blur_video_threaded_ray.consumer (   accel_mode,
  fpgas_queue,
  frame,
  debug_level = debug_level 
)

Definition at line 135 of file test_median_blur_video_threaded_ray.py.

135 def consumer(accel_mode, fpgas_queue, frame, debug_level=debug_level):
136  logging.basicConfig(level=debug_level)
137 
138  orig = frame
139  frame_ret = cv.cvtColor(frame, cv.COLOR_RGB2GRAY)
140  # Adjusting the image file if needed
141  #frame_ret = crop_square_roi(frame_ret, width, interpolation = cv.INTER_AREA, debug_level=debug_level)
142  if accel_mode:
143  next_item = fpgas_queue.get(block=True, timeout=100)
144  logging.debug(f"will work on {next_item} and then put in back in the fpgas_queue")
145  # Flattening the image from 2D to 1D
146  image = frame_ret.flatten()
147  output_array = trieres.vision.median_blur(image, total_size, next_item[0], int(next_item[1]), debug_level=debug_level)
148  frame_ret = np.reshape(output_array, (height, width))
149  #frame_ret = cv.medianBlur(frame_ret, 9)
150  fpgas_queue.put(next_item)
151  logging.debug(f"finished working on {next_item} Now it is back in the fpgas_queue")
152  else:
153  frame_ret = cv.medianBlur(frame_ret, 9)
154  if ROI:
155  frame_ret = patch_sqaure_roi(orig, frame_ret, cv.INTER_AREA, debug_level=debug_level)
156  else:
157  frame_ret = cv.cvtColor(np.uint8(frame_ret),cv.COLOR_GRAY2RGB)
158  return frame_ret
159 
160 
161 try:
162  fn = sys.argv[1]
163 except:
164  fn = 0
165 
def patch_sqaure_roi(orig, frame, interpolation=cv.INTER_AREA, debug_level=debug_level)
def consumer(accel_mode, fpgas_queue, frame, debug_level=debug_level)
Here is the call graph for this function:

◆ crop_square_roi()

def test_median_blur_video_threaded_ray.crop_square_roi (   img,
  size,
  interpolation = cv.INTER_AREA,
  debug_level = debug_level 
)

Definition at line 72 of file test_median_blur_video_threaded_ray.py.

72 def crop_square_roi(img, size, interpolation=cv.INTER_AREA, debug_level=debug_level):
73  logging.basicConfig(level=debug_level)
74 
75  h, w = img.shape[:2]
76  if ROI:
77  if (h>height) and (w>width):
78  roi_x_pos = int((w-width) /2)
79  roi_y_pos = int((h-height)/2)
80  crop_img = img[int(roi_y_pos):int(roi_y_pos+height), int(roi_x_pos):int(roi_x_pos+width)]
81  else:
82  crop_img = img
83  logging.warning(f"The input image of [{h}x{w}] is not bigger to embed a ROI of [{height}x{width}]. Will just resize")
84  else:
85  min_size = np.amin([np.amin([h,w]), np.amin([height,width])])
86  # Centralize and crop
87  crop_img = img[int(h/2-min_size/2):int(h/2+min_size/2), int(w/2-min_size/2):int(w/2+min_size/2)]
88 
89  # Adjusting the image file if needed
90  if ((crop_img.shape[0] != height) or (crop_img.shape[1] != width)):
91  logging.warning(f"The image was resized from [{crop_img.shape[0]} x {crop_img.shape[1]}] to [{height}x{width}]")
92  resized = cv.resize(crop_img , (size, size), interpolation=interpolation)
93  else:
94  resized = crop_img
95  return resized
96 
def crop_square_roi(img, size, interpolation=cv.INTER_AREA, debug_level=debug_level)
Here is the caller graph for this function:

◆ patch_sqaure_roi()

def test_median_blur_video_threaded_ray.patch_sqaure_roi (   orig,
  frame,
  interpolation = cv.INTER_AREA,
  debug_level = debug_level 
)

Definition at line 97 of file test_median_blur_video_threaded_ray.py.

97 def patch_sqaure_roi(orig, frame, interpolation=cv.INTER_AREA, debug_level=debug_level):
98  logging.basicConfig(level=debug_level)
99 
100  h_orig, w_orig = orig.shape[:2]
101  h_frame, w_frame = frame.shape[:2]
102 
103  patched_img = orig.copy()
104 
105  if (h_orig>h_frame) and (w_orig>w_frame):
106  roi_x_pos = int((w_orig-w_frame)/2)
107  roi_y_pos = int((h_orig-h_frame)/2)
108  frame_backtorgb = cv.cvtColor(np.float32(frame),cv.COLOR_GRAY2RGB)
109  patched_img[int(roi_y_pos):int(roi_y_pos+h_frame), int(roi_x_pos):int(roi_x_pos+w_frame),:] = frame_backtorgb
110  else:
111  patched_img = frame
112  logging.warning(f"The input image of [{h_orig}x{w_orig}] is not bigger to embed a ROI of [{h_frame}x{w_frame}]. Will just resize")
113  # Adjusting the image file if needed
114  if ((patched_img.shape[0] != h_orig) or (patched_img.shape[1] != w_orig)):
115  logging.warning(f"The image was resized from [{patched_img.shape[0]} x {patched_img.shape[1]}] to [{h_orig}x{w_orig}]")
116  resized = cv.resize(patched_img , (w_orig, h_orig), interpolation=interpolation)
117  else:
118  resized = patched_img
119  return resized
120 
121 
122 #ray.init(dashboard_port=50051, num_cpus=12)
123 ray.init(address='ray://10.12.0.10:10001')
124 
125 print('''This cluster consists of
126  {} nodes in total
127  {} CPU resources in total
128  {} cloudFPGA resources in total
129 '''.format(len(ray.nodes()), ray.cluster_resources()['CPU'], ray.cluster_resources()['cloudFPGA']))
130 
131 # You can pass this object around to different tasks/actors
Here is the caller graph for this function:

Variable Documentation

◆ accel_mode

bool test_median_blur_video_threaded_ray.accel_mode = True

Definition at line 53 of file test_median_blur_video_threaded_ray.py.

◆ cap

test_median_blur_video_threaded_ray.cap = cv.VideoCapture(fn)

Definition at line 168 of file test_median_blur_video_threaded_ray.py.

◆ config_file

string test_median_blur_video_threaded_ray.config_file = os.environ['cFpRootDir'] + "HOST/vision/median_blur/languages/cplusplus/include/config.h"

Definition at line 56 of file test_median_blur_video_threaded_ray.py.

◆ consumers

list test_median_blur_video_threaded_ray.consumers = [consumer.remote(accel_mode, fpgas_queue, frames[i], debug_level=debug_level) for i in range(len(frames))]

Definition at line 192 of file test_median_blur_video_threaded_ray.py.

◆ debug_level

test_median_blur_video_threaded_ray.debug_level = logging.INFO

Definition at line 54 of file test_median_blur_video_threaded_ray.py.

◆ fpgas_queue

test_median_blur_video_threaded_ray.fpgas_queue = Queue(maxsize=100)

Definition at line 132 of file test_median_blur_video_threaded_ray.py.

◆ frame

test_median_blur_video_threaded_ray.frame

Definition at line 180 of file test_median_blur_video_threaded_ray.py.

◆ frames

list test_median_blur_video_threaded_ray.frames = []

Definition at line 169 of file test_median_blur_video_threaded_ray.py.

◆ frames_ret

list test_median_blur_video_threaded_ray.frames_ret = []

Definition at line 170 of file test_median_blur_video_threaded_ray.py.

◆ height

test_median_blur_video_threaded_ray.height = int(line.split()[2])

Definition at line 64 of file test_median_blur_video_threaded_ray.py.

◆ level

test_median_blur_video_threaded_ray.level

Definition at line 57 of file test_median_blur_video_threaded_ray.py.

◆ results

test_median_blur_video_threaded_ray.results = ray.get(consumers)

Definition at line 234 of file test_median_blur_video_threaded_ray.py.

◆ ret

test_median_blur_video_threaded_ray.ret

Definition at line 180 of file test_median_blur_video_threaded_ray.py.

◆ ROI

bool test_median_blur_video_threaded_ray.ROI = False

Definition at line 52 of file test_median_blur_video_threaded_ray.py.

◆ tic_capture

test_median_blur_video_threaded_ray.tic_capture = time.perf_counter()

Definition at line 166 of file test_median_blur_video_threaded_ray.py.

◆ tic_consumers

test_median_blur_video_threaded_ray.tic_consumers = time.perf_counter()

Definition at line 191 of file test_median_blur_video_threaded_ray.py.

◆ tic_exec

test_median_blur_video_threaded_ray.tic_exec = time.perf_counter()

Definition at line 233 of file test_median_blur_video_threaded_ray.py.

◆ tic_save

test_median_blur_video_threaded_ray.tic_save = time.perf_counter()

Definition at line 238 of file test_median_blur_video_threaded_ray.py.

◆ toc_capture

test_median_blur_video_threaded_ray.toc_capture = time.perf_counter()

Definition at line 189 of file test_median_blur_video_threaded_ray.py.

◆ toc_consumers

test_median_blur_video_threaded_ray.toc_consumers = time.perf_counter()

Definition at line 231 of file test_median_blur_video_threaded_ray.py.

◆ toc_exec

test_median_blur_video_threaded_ray.toc_exec = time.perf_counter()

Definition at line 235 of file test_median_blur_video_threaded_ray.py.

◆ toc_save

test_median_blur_video_threaded_ray.toc_save = time.perf_counter()

Definition at line 246 of file test_median_blur_video_threaded_ray.py.

◆ total_size

test_median_blur_video_threaded_ray.total_size = height * width

Definition at line 67 of file test_median_blur_video_threaded_ray.py.

◆ video_name

string test_median_blur_video_threaded_ray.video_name = str(fn)+"_out.avi"

Definition at line 239 of file test_median_blur_video_threaded_ray.py.

◆ video_out

test_median_blur_video_threaded_ray.video_out = cv.VideoWriter(video_name, cv.VideoWriter_fourcc('M','J','P','G'), 30, (results[0].shape[1],results[0].shape[0]))

Definition at line 241 of file test_median_blur_video_threaded_ray.py.

◆ width

test_median_blur_video_threaded_ray.width = int(line.split()[2])

Definition at line 62 of file test_median_blur_video_threaded_ray.py.