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

This is the Sobel accelerated function from Vitis Vision Open Source Library. More...

Collaboration diagram for Sobel:

Modules

 Sobel Testbench
 This is a subgroup of Sobel accelerated function with only testbench-related functions/classes.
 
 Sobel HLS
 This is a subgroup of Sobel accelerated function with only synthesizable (HLS) functions/classes.
 
 Sobel Host
 This is a subgroup of Sobel accelerated function with only host code software.
 

Files

file  config.h
 The configuration of a Sobel Example application (UDP or TCP)
 
file  sobel_host.cpp
 Sobel userspace application for cF (x86, ppc64).
 
file  xf_sobel_config.h
 The Sobel configuration header.
 

Macros

#define CEIL(a, b)   (((a) + (b-1)) / (b))
 
#define FRAME_HEIGHT   1024
 
#define FRAME_WIDTH   1024
 
#define FRAME_INTERVAL   (1000/30)
 
#define PACK_SIZE   1024
 
#define BUF_LEN   65540
 
#define WRITE_OUTPUT_FILE
 
#define INPUT_TYPE_HOST   CV_8UC1
 
#define NET_TYPE   udp
 
#define DEBUG_LEVEL   dbgLevelNone
 
#define FRAME_TOTAL   FRAME_HEIGHT * FRAME_WIDTH
 
#define TOT_TRANSFERS   CEIL(FRAME_TOTAL, PACK_SIZE)
 
#define tcp   0
 
#define udp   1
 
#define PY_WRAP_SOBEL_NUMPI   0
 
#define PY_WRAP_SOBEL_FILENAME   1
 
#define NPC1   XF_NPPC1
 
#define PTR_WIDTH   128
 
#define TYPE   XF_8UC1
 
#define CH_TYPE   XF_GRAY
 
#define INPUT_PTR_WIDTH   8
 
#define OUTPUT_PTR_WIDTH   64
 
#define NPIX   XF_NPPC1
 
#define WIDTH   FRAME_WIDTH
 
#define HEIGHT   FRAME_HEIGHT
 
#define IMGSIZE   FRAME_TOTAL
 
#define BITS_PER_10GBITETHRNET_AXI_PACKET   64
 
#define BYTES_PER_10GBITETHRNET_AXI_PACKET   (BITS_PER_10GBITETHRNET_AXI_PACKET/8)
 
#define IMG_PACKETS   IMGSIZE/(BYTES_PER_10GBITETHRNET_AXI_PACKET)
 
#define MIN_RX_LOOPS   IMG_PACKETS*(BITS_PER_10GBITETHRNET_AXI_PACKET/INPUT_PTR_WIDTH)
 
#define MIN_TX_LOOPS   IMG_PACKETS*(BITS_PER_10GBITETHRNET_AXI_PACKET/OUTPUT_PTR_WIDTH)
 
#define OUT_TYPE   TYPE
 

Functions

void delay (unsigned int mseconds)
 
void print_cFpZoo (void)
 
void resizeCropSquare (const cv::Mat &input, const cv::Mat &output, const cv::Size &dstSize, int interpolation=INTER_LINEAR)
 Resize an image and crop if necessary in order to keep a rectangle area in the middle of the image. More...
 
int main (int argc, char *argv[])
 
void sobel_accel (xf::cv::Mat< XF_8UC1, 1024, 1024, XF_NPPC1 > &_src, xf::cv::Mat< XF_8UC1, 1024, 1024, XF_NPPC1 > &_dst)
 
void medianBlurAccelArray (ap_uint< 256 > *img_inp, ap_uint< 256 > *img_out, int rows, int cols)
 
void medianBlurAccelStream (hls::stream< ap_uint< 256 >> &img_in_axi_stream, hls::stream< ap_uint< 256 >> &img_out_axi_stream, int rows, int cols)
 Top-level accelerated function of the Sobel Application with array I/Fadd SOBEL. More...
 
void fakeSobelAccelStream (hls::stream< ap_axiu< 256, 0, 0, 0 > > &img_in_axi_stream, hls::stream< ap_axiu< 256, 0, 0, 0 > > &img_out_axi_stream, unsigned int min_rx_loops, unsigned int min_tx_loops)
 
void medianBlurAccelMem (membus_t *img_inp, membus_t *img_out, int rows, int cols)
 Top-level accelerated function of the MedianBlur Application with array I/F. More...
 

Detailed Description

This is the Sobel accelerated function from Vitis Vision Open Source Library.

Macro Definition Documentation

◆ BITS_PER_10GBITETHRNET_AXI_PACKET

#define BITS_PER_10GBITETHRNET_AXI_PACKET   64

Definition at line 109 of file xf_sobel_config.h.

◆ BUF_LEN

#define BUF_LEN   65540

Larger than maximum UDP packet size

Definition at line 55 of file config.h.

◆ BYTES_PER_10GBITETHRNET_AXI_PACKET

#define BYTES_PER_10GBITETHRNET_AXI_PACKET   (BITS_PER_10GBITETHRNET_AXI_PACKET/8)

Definition at line 110 of file xf_sobel_config.h.

◆ CEIL

#define CEIL (   a,
 
)    (((a) + (b-1)) / (b))

Ceiling function without using math.h

Definition at line 37 of file config.h.

◆ CH_TYPE

#define CH_TYPE   XF_GRAY

Definition at line 90 of file xf_sobel_config.h.

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   dbgLevelNone

The level of debugging. 0->None, 1-> Light Debug, 2-> Medium Debug , 3-> Insane Debug

Definition at line 78 of file config.h.

◆ FRAME_HEIGHT

#define FRAME_HEIGHT   1024

The maximum width of frame in pixels

Definition at line 43 of file config.h.

◆ FRAME_INTERVAL

#define FRAME_INTERVAL   (1000/30)

Definition at line 48 of file config.h.

◆ FRAME_TOTAL

#define FRAME_TOTAL   FRAME_HEIGHT * FRAME_WIDTH

Definition at line 82 of file config.h.

◆ FRAME_WIDTH

#define FRAME_WIDTH   1024

The maximum height of frame in pixels

Definition at line 46 of file config.h.

◆ HEIGHT

#define HEIGHT   FRAME_HEIGHT

Definition at line 105 of file xf_sobel_config.h.

◆ IMG_PACKETS

#define IMG_PACKETS   IMGSIZE/(BYTES_PER_10GBITETHRNET_AXI_PACKET)

Definition at line 112 of file xf_sobel_config.h.

◆ IMGSIZE

#define IMGSIZE   FRAME_TOTAL

Definition at line 107 of file xf_sobel_config.h.

◆ INPUT_PTR_WIDTH

#define INPUT_PTR_WIDTH   8

Definition at line 91 of file xf_sobel_config.h.

◆ INPUT_TYPE_HOST

#define INPUT_TYPE_HOST   CV_8UC1

If defined, images will be shown in pop-up windows
For HOST TB uncomment this. For normal host execution keep it commented
Keep it uncommented of you want the input to be from camera frames else, for images comment it For The OpenCV type fot th input image. TODO: We have to automatically fix it for every kernel

Definition at line 70 of file config.h.

◆ MIN_RX_LOOPS

Definition at line 114 of file xf_sobel_config.h.

◆ MIN_TX_LOOPS

Definition at line 115 of file xf_sobel_config.h.

◆ NET_TYPE

#define NET_TYPE   udp

The network socket type: tcp or udp

Definition at line 73 of file config.h.

◆ NPC1

#define NPC1   XF_NPPC1

Definition at line 70 of file xf_sobel_config.h.

◆ NPIX

#define NPIX   XF_NPPC1

Definition at line 101 of file xf_sobel_config.h.

◆ OUT_TYPE

#define OUT_TYPE   TYPE

Definition at line 118 of file xf_sobel_config.h.

◆ OUTPUT_PTR_WIDTH

#define OUTPUT_PTR_WIDTH   64

Definition at line 92 of file xf_sobel_config.h.

◆ PACK_SIZE

#define PACK_SIZE   1024

This is our custom MTU. We must use a multiple of 8 (Bytes per transaction)! 1450 4086 udp pack size; note that OSX limits < 8100 bytes

Definition at line 52 of file config.h.

◆ PTR_WIDTH

#define PTR_WIDTH   128

Definition at line 71 of file xf_sobel_config.h.

◆ PY_WRAP_SOBEL_FILENAME

#define PY_WRAP_SOBEL_FILENAME   1

Definition at line 91 of file config.h.

◆ PY_WRAP_SOBEL_NUMPI

#define PY_WRAP_SOBEL_NUMPI   0

Definition at line 90 of file config.h.

◆ tcp

#define tcp   0

Definition at line 87 of file config.h.

◆ TOT_TRANSFERS

#define TOT_TRANSFERS   CEIL(FRAME_TOTAL, PACK_SIZE)

The total TxRx transfers for a predefined MTU=PACK_SIZE

Definition at line 85 of file config.h.

◆ TYPE

#define TYPE   XF_8UC1

Definition at line 85 of file xf_sobel_config.h.

◆ udp

#define udp   1

Definition at line 88 of file config.h.

◆ WIDTH

#define WIDTH   FRAME_WIDTH

Definition at line 104 of file xf_sobel_config.h.

◆ WRITE_OUTPUT_FILE

#define WRITE_OUTPUT_FILE

If defined, output images will be written

Definition at line 58 of file config.h.

Function Documentation

◆ delay()

void delay ( unsigned int  mseconds)

Definition at line 51 of file sobel_host.cpp.

52 {
53  clock_t goal = mseconds + clock();
54  while (goal > clock());
55 }
def clock()
Definition: common.py:174
Here is the call graph for this function:

◆ fakeSobelAccelStream()

void fakeSobelAccelStream ( hls::stream< ap_axiu< 256, 0, 0, 0 > > &  img_in_axi_stream,
hls::stream< ap_axiu< 256, 0, 0, 0 > > &  img_out_axi_stream,
unsigned int  min_rx_loops,
unsigned int  min_tx_loops 
)
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main testbench and user-application for Sobel on host. Client

Returns
O on success, 1 on fail

Definition at line 108 of file sobel_host.cpp.

108  {
109  if ((argc < 3) || (argc > 4)) { // Test for correct number of arguments
110  cerr << "Usage: " << argv[0] << " <Server> <Server Port> <optional input image>\n";
111  exit(1);
112  }
113 #endif // PY_WRAP
114 
115  //------------------------------------------------------
116  //-- STEP-1 : Socket and variables definition
117  //------------------------------------------------------
118 
119  #ifndef PY_WRAP
120  assert ((argc == 3) || (argc == 4));
121  string s_servAddress = argv[1]; // First arg: server address
122  char *s_servPort = argv[2];
123  #endif
124 
125  string servAddress = s_servAddress;
126  unsigned short servPort;
127  bool net_type = NET_TYPE;
128  if (net_type == udp) {
129  servPort = Socket::resolveService(s_servPort, "udp");
130  }
131  else if (net_type == tcp) {
132  servPort = atoi(s_servPort);
133  }
134  else {
135  cout << "ERROR: Invalid type of socket type provided: " << net_type << " Choosed one of (tcp=0 or udp=1)" << endl;
136  }
137 
138  unsigned char buffer[BUF_LEN]; // Buffer for echo string
139  unsigned int recvMsgSize; // Size of received message
140  string input_string;
141 #ifdef INPUT_FROM_CAMERA
142  int input_num;
143 #ifdef PY_WRAP
144 #if PY_WRAP == PY_WRAP_SOBEL_FILENAME
145  input_num = atoi(input_str);
146  input_string = "./cam"+to_string(input_num);
147 #endif // PY_WRAP == PY_WRAP_SOBEL_FILENAME
148 #else // !PY_WRAP
149  if (argc == 3) {
150  input_num = 0;
151  }
152  else if (argc == 4) {
153  input_num = atoi(argv[3]);
154  }
155  input_string = "./cam"+to_string(input_num);
156 #endif // PY_WRAP
157 #else // !INPUT_FROM_CAMERA
158 #ifdef PY_WRAP
159 #if PY_WRAP == PY_WRAP_SOBEL_FILENAME
160  input_string.assign(input_str);
161 #endif // PY_WRAP == PY_WRAP_SOBEL_FILENAME
162 #else // !PY_WRAP
163  if (argc == 3) {
164  // Give a default image
165  input_string.assign("../../../../../../ROLE/vision/hls/sobel/test/8x8.png");
166  }
167  else if (argc == 4) {
168  input_string.assign(argv[3]);
169  }
170 #endif // PY_WRAP
171 #endif // INPUT_FROM_CAMERA
172 
173 
174 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
175 
176  // ksize: aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
177  int ksize = WINDOW_SIZE ;
178  string out_img_file;
179  string out_video_file;
180  // Define the codec and create VideoWriter object.The output is stored in 'outcpp.avi' file.
181  //#ifdef PY_WRAP
182  //out_video_file.assign(output_str);
183  //#else // !PY_WRAP
184  out_video_file.assign(input_string);
185  out_video_file += "_fpga_video_out.avi";
186  //#endif // PY_WRAP
187 #if CV_MAJOR_VERSION < 4
188  VideoWriter video(out_video_file,CV_FOURCC('M','J','P','G'),10, Size(FRAME_WIDTH,FRAME_HEIGHT));
189 #else
190  VideoWriter video(out_video_file,cv::VideoWriter::fourcc('M','J','P','G'),10, Size(FRAME_WIDTH,FRAME_HEIGHT));
191 #endif
192 
193 #endif // #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
194 
195  print_cFpZoo();
196 
197  try {
198 
199  //------------------------------------------------------
200  //-- STEP-2 : Initialize socket connection
201  //------------------------------------------------------
202 #if NET_TYPE == udp
203 #ifndef TB_SIM_CFP_VITIS
204  UDPSocket sock(servPort); // NOTE: It is very important to set port here in order to call
205  // bind() in the UDPSocket constructor
206 #else // TB_SIM_CFP_VITIS
207  UDPSocket sock; // NOTE: In HOST TB the port is already binded by sobel_host_fwd_tb.cpp
208 #endif // TB_SIM_CFP_VITIS
209 #else // tcp
210  TCPSocket sock(servAddress, servPort);
211 #endif // udp/tcp
212 
213 
214 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
215 
216 
217  //------------------------------------------------------------------------------------
218  //-- STEP-3 : Initialize a Greyscale OpenCV Mat either from image or from video/camera
219  //------------------------------------------------------------------------------------
220  Mat frame, send(FRAME_WIDTH, FRAME_HEIGHT, INPUT_TYPE_HOST, Scalar(0)), ocv_out_img;
221  vector < uchar > encoded;
222 
223 #ifdef INPUT_FROM_CAMERA
224 
225  VideoCapture cap(input_num); // Grab the camera
226  if (!cap.isOpened()) {
227  cerr << "OpenCV Failed to open camera " + input_num << endl;
228  exit(1);
229  }
230 
231 #else // INPUT_FROM_CAMERA
232 
233  VideoCapture cap(input_string); // Grab the image
234  if (!cap.isOpened()) {
235  cerr << "OpenCV Failed to open file " + input_string << endl;
236  exit(1);
237  }
238 
239 #endif // INPUT_FROM_CAMERA
240 
241  //frame = cv::imread(argv[3], cv::IMREAD_GRAYSCALE); // reading in the image in grey scale
242  unsigned int num_frame = 0;
243 
244  while (1) {
245  clock_t start_cycle_main = clock();
246  cap >> frame;
247  if (frame.empty()) break; // if input is an image, the loop will be executed once
248  if(frame.size().width==0) continue; //simple integrity check; skip erroneous data...
249  cout << " ___________________________________________________________________ " << endl;
250  cout << "/ \\" << endl;
251  cout << "INFO: Frame # " << ++num_frame << endl;
252 #if CV_MAJOR_VERSION < 4
253  cv::cvtColor(frame,frame,CV_BGR2GRAY);
254 #else
255  cv::cvtColor(frame,frame,cv::COLOR_BGR2GRAY);
256 #endif
257  resizeCropSquare(frame, send, Size(FRAME_WIDTH, FRAME_HEIGHT), INTER_LINEAR);
258  if ((frame.cols != FRAME_WIDTH) || (frame.rows != FRAME_HEIGHT)) {
259  cout << "WARNING: Input frame was resized from " << frame.cols << "x"
260  << frame.rows << " to " << send.cols << "x" << send.rows << endl;
261  }
262  assert(send.total() == FRAME_WIDTH * FRAME_HEIGHT);
263  // Ensure that the selection of MTU is a multiple of 8 (Bytes per transaction)
264  assert(PACK_SIZE % 8 == 0);
265 
266 #ifdef SHOW_WINDOWS
267  namedWindow("host_send", CV_WINDOW_NORMAL);
268  imshow("host_send", send);
269 
270 #endif // SHOW_WINDOWS
271 
272  // Ensure that the send Mat is in continuous memory space. Typically, imread or resize
273  // will return such a continuous Mat, but we should check it.
274  assert(send.isContinuous());
275 
276  unsigned int send_total = send.total();
277  unsigned int send_channels = send.channels();
278 
279 #else // PY_WRAP == PY_WRAP_SOBEL_NUMPI
280 
281  unsigned int send_total = (unsigned int)total_size;
282  unsigned int send_channels = 1; // FIXME: It is ok only for 1-d array, i.e. CV_8UC1
283  unsigned char * sendarr = input_img;
284 #endif // #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
285 
286  unsigned int total_pack = 1 + (send_total * send_channels - 1) / PACK_SIZE;
287  unsigned int total_bytes = total_pack * PACK_SIZE;
288  unsigned int bytes_in_last_pack = send_total * send_channels - (total_pack - 1) * PACK_SIZE;
289  assert(total_pack == TOT_TRANSFERS);
290 
291  //unsigned char * longbuf = new unsigned char[PACK_SIZE * total_pack];
292  unsigned char * longbuf = (unsigned char *) malloc (PACK_SIZE * total_pack * sizeof (unsigned char));
293 
294 // cout << "INFO: FPGA destination : " << servAddress << ":" << servPort << endl;
295 // cout << "INFO: Network socket : " << ((NET_TYPE == tcp) ? "TCP" : "UDP") << endl;
296 // cout << "INFO: Total packets to send/receive = " << total_pack << endl;
297 // cout << "INFO: Total bytes to send/receive = " << send_total * send_channels << endl;
298 // cout << "INFO: Total bytes in " << total_pack << " packets = " << total_bytes << endl;
299 // cout << "INFO: Bytes in last packet = " << bytes_in_last_pack << endl;
300 // cout << "INFO: Packet size (custom MTU) = " << PACK_SIZE << endl;
301 
302 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
303 
304  //--------------------------------------------------------
305  //-- STEP-4 : RUN SOBEL DETECTOR FROM OpenCV LIBRARY (SW)
306  //--------------------------------------------------------
307  clock_t start_cycle_sobel_sw = clock();
308  ocv_out_img.create(send.rows, send.cols, INPUT_TYPE_HOST); // create memory for opencv output image
309  ocv_ref(send, ocv_out_img, ksize);
310  clock_t end_cycle_sobel_sw = clock();
311  double duration_sobel_sw = (end_cycle_sobel_sw - start_cycle_sobel_sw) /
312  (double) CLOCKS_PER_SEC;
313 // cout << "INFO: SW exec. time:" << duration_sobel_sw << " seconds" << endl;
314 // cout << "INFO: Effective FPS SW:" << (1 / duration_sobel_sw) << " \tkbps:" <<
315 // (PACK_SIZE * total_pack / duration_sobel_sw / 1024 * 8) << endl;
316 
317  //------------------------------------------------------
318  //-- STEP-5 : RUN SOBEL DETECTOR FROM cF (HW)
319  //------------------------------------------------------
320 
321  //------------------------------------------------------
322  //-- STEP-5.1 : Preparation
323  //------------------------------------------------------
324 
325  // Anchor a pointer on cvMat raw data
326  unsigned char * sendarr = send.isContinuous()? send.data: send.clone().data;
327 
328 
329 #endif // !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
330 
331  clock_t start_cycle_sobel_hw = clock();
332 
333  //------------------------------------------------------
334  //-- STEP-5.2 : TX Loop
335  //------------------------------------------------------
336  clock_t last_cycle_tx = clock();
337  unsigned int sending_now = PACK_SIZE;
338  for (unsigned int i = 0; i < total_pack; i++) {
339  if ( i == total_pack - 1 ) {
340  sending_now = bytes_in_last_pack;
341  }
342  #if NET_TYPE == udp
343  sock.sendTo( & sendarr[i * PACK_SIZE], sending_now, servAddress, servPort);
344  #else
345  sock.send( & sendarr[i * PACK_SIZE], sending_now);
346  #endif
347  //delay(200);
348  }
349 
350  clock_t next_cycle_tx = clock();
351  double duration_tx = (next_cycle_tx - last_cycle_tx) / (double) CLOCKS_PER_SEC;
352 // cout << "INFO: Effective FPS TX:" << (1 / duration_tx) << " \tkbps:" << (PACK_SIZE *
353 // total_pack / duration_tx / 1024 * 8) << endl;
354  last_cycle_tx = next_cycle_tx;
355 
356 
357  //------------------------------------------------------
358  //-- STEP-5.3 : RX Loop
359  //------------------------------------------------------
360  clock_t last_cycle_rx = clock();
361  unsigned int receiving_now = PACK_SIZE;
362 // cout << "INFO: Expecting length of packs:" << total_pack << " from " << servAddress << ":" << servPort << endl;
363  //unsigned char * longbuf = new unsigned char[PACK_SIZE * total_pack];
364  unsigned int loopi=0;
365  for (unsigned int i = 0; i < send_total; ) {
366  //cout << "DEBUG: i=" << i << ", loopi=" << loopi++ << endl;
367  //if ( i == total_pack - 1 ) {
368  // receiving_now = bytes_in_last_pack;
369  //}
370  #if NET_TYPE == udp
371  recvMsgSize = sock.recvFrom(buffer, BUF_LEN, servAddress, servPort);
372  #else
373  recvMsgSize = sock.recv(buffer, BUF_LEN);
374  #endif
375  if (recvMsgSize != receiving_now) {
376  cerr << "WARNING: at i=" << i << " received unexpected size pack:" << recvMsgSize << ". Expected: " <<
377  receiving_now << endl;
378  //continue;
379  }
380  memcpy( & longbuf[i], buffer, recvMsgSize);
381  //cout << "DEBUG: i=" << i << " recvMsgSize=" << recvMsgSize << endl;
382  i += recvMsgSize;
383  //delay(200);
384  }
385 // cout << "INFO: Received packet from " << servAddress << ":" << servPort << endl;
386 
387  clock_t next_cycle_rx = clock();
388  double duration_rx = (next_cycle_rx - last_cycle_rx) / (double) CLOCKS_PER_SEC;
389 // cout << "INFO: Effective FPS RX:" << (1 / duration_rx) << " \tkbps:" << (PACK_SIZE *
390 // total_pack / duration_rx / 1024 * 8) << endl;
391  last_cycle_rx = next_cycle_rx;
392 
393  clock_t end_cycle_sobel_hw = next_cycle_rx;
394 
395  double duration_sobel_hw = (end_cycle_sobel_hw - start_cycle_sobel_hw) /
396  (double) CLOCKS_PER_SEC;
397 // cout << "INFO: HW exec. time:" << duration_sobel_hw << " seconds" << endl;
398 // cout << "INFO: Effective FPS HW:" << (1 / duration_sobel_hw) << " \tkbps:" <<
399 // (PACK_SIZE * total_pack / duration_sobel_hw / 1024 * 8) << endl;
400 
401 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
402 
403  frame = cv::Mat(FRAME_HEIGHT, FRAME_WIDTH, INPUT_TYPE_HOST, longbuf); // OR vec.data() instead of ptr
404  if (frame.size().width == 0) {
405  cerr << "receive failure!" << endl;
406  continue;
407  }
408 #ifdef SHOW_WINDOWS
409  namedWindow("host_recv", CV_WINDOW_NORMAL);
410  imshow("host_recv", frame);
411 #endif
412 
413  //------------------------------------------------------
414  //-- STEP-6 : Write output files and show in windows
415  //------------------------------------------------------
416 
417  ostringstream oss;
418 // oss << "cFp_Vitis E2E:" << "INFO: Effective FPS HW:" << (1 / duration_sobel_hw) <<
419 // " \tkbps:" << (PACK_SIZE * total_pack / duration_sobel_hw / 1024 * 8);
420  string windowName = "cFp_Vitis End2End"; //oss.str();
421 
422  //moveWindow(windowName, 0, 0);
423 #ifdef WRITE_OUTPUT_FILE
424  if (num_frame == 1) {
425  out_img_file.assign(input_string);
426  out_img_file += "_fpga_image_out_frame_" + to_string(num_frame) + ".png";
427 #if defined(PY_WRAP) && (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
428 
429  if (!strcpy(output_img_str, &out_img_file[0])) {
430  cerr << "ERROR: Cannot write to output image string." << endl;
431  }
432 #endif // defined(PY_WRAP) && (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
433  cout << "INFO: The output image file is stored at : " << out_img_file << endl;
434  // We save the image received from network after being processed by Sobel HW or HOST TB
435  imwrite(out_img_file, frame);
436  }
437  else if (num_frame > 1) {
438  // If the frame is empty, break immediately
439  if (frame.empty()) {
440  break;
441  }
442  cout << "INFO: The output video file is stored at : " << out_video_file << endl;
443  Mat tovideo;
444  if (frame.channels() != 1) {
445  tovideo = frame;
446  }
447  else {
448  cvtColor(frame, tovideo, COLOR_GRAY2BGR);
449  }
450  video.write(tovideo);
451  }
452 #endif // WRITE_OUTPUT_FILE
453  waitKey(FRAME_INTERVAL);
454  double duration_main = (clock() - start_cycle_main) / (double) CLOCKS_PER_SEC;
455 // cout << "INFO: Effective FPS E2E:" << (1 / duration_main) << endl;
456 // cout << "\\___________________________________________________________________/" << endl
457 // << endl;
458  //delete(longbuf);
459  free (longbuf);
460  } // while loop
461 
462  // When everything done, release the video capture and write object
463  cap.release();
464  video.release();
465 
466  // Closes all the windows
467  destroyAllWindows();
468 
469 #else // !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
470  //output_img = longbuf;
471  memcpy( output_img, longbuf, total_size);
472  free(longbuf);
473 #endif // !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_SOBEL_FILENAME)
474 
475  // Destructor closes the socket
476  } catch (SocketException & e) {
477  cerr << e.what() << endl;
478  exit(1);
479  }
480 
481 #ifndef PY_WRAP
482  return 0;
483 #endif
484 }
cat GET request dos socat stdio tcp
Definition: commands.txt:1
void ocv_ref(cv::Mat img_gray, cv::Mat &ocv_out_img, float Th)
Definition: xf_ocv_ref.hpp:552
#define FRAME_INTERVAL
Definition: config.h:48
#define INPUT_TYPE_HOST
Definition: config.h:68
#define FRAME_HEIGHT
Definition: config.h:43
#define FRAME_WIDTH
Definition: config.h:46
#define TOT_TRANSFERS
Definition: config.h:70
#define WINDOW_SIZE
#define udp
Definition: config.h:66
#define NET_TYPE
Definition: config.h:60
#define BUF_LEN
Definition: config.h:54
#define PACK_SIZE
Definition: config.h:51
void print_cFpZoo(void)
Definition: sobel_host.cpp:57
void resizeCropSquare(const cv::Mat &input, const cv::Mat &output, const cv::Size &dstSize, int interpolation=INTER_LINEAR)
Resize an image and crop if necessary in order to keep a rectangle area in the middle of the image.
Definition: sobel_host.cpp:82
def send(cFcluster cluster, node_id, data_obj, proto='udp', port=CF_DEFAULT_PORT)
Definition: comm.py:41

◆ medianBlurAccelArray()

void medianBlurAccelArray ( ap_uint< 256 > *  img_inp,
ap_uint< 256 > *  img_out,
int  rows,
int  cols 
)

◆ medianBlurAccelMem()

void medianBlurAccelMem ( membus_t img_inp,
membus_t img_out,
int  rows,
int  cols 
)

Top-level accelerated function of the MedianBlur Application with array I/F.

Returns
Nothing.

Definition at line 222 of file xf_median_blur_accel.cpp.

224  {
225  // clang-format on
226  #pragma HLS INLINE off
227 
228  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
229  // clang-format off
230  #pragma HLS stream variable=imgInput.data depth=2
231  // clang-format on
232 
233  #ifndef FAKE_MedianBlur
234  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
235  // clang-format off
236  #pragma HLS stream variable=imgOutput.data depth=2
237  // clang-format on
238  #endif
239 
240  // clang-format off
241  #pragma HLS DATAFLOW
242  // clang-format on
243 
244  // Feed a cv matrix from ddr memory
245  xf::cv::Array2xfMat<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_inp, imgInput);
246 
247  #ifdef FAKE_MedianBlur
248 
249  // Feed ddr memory from a cv matrix
250  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgInput, img_out);
251  #else
252 
253  xf::cv::medianBlur<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
254 
255  // Feed ddr memory from a cv matrix
256  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgOutput, img_out);
257 
258  #endif
259 
260 
261 }

◆ medianBlurAccelStream()

void medianBlurAccelStream ( hls::stream< ap_uint< 256 >> &  img_in_axi_stream,
hls::stream< ap_uint< 256 >> &  img_out_axi_stream,
int  rows,
int  cols 
)

Top-level accelerated function of the Sobel Application with array I/Fadd SOBEL.

Returns
Nothing.

Definition at line 71 of file xf_sobel_accel.cpp.

74  {
75  // clang-format on
76  #pragma HLS INLINE off
77 
78  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
79  // clang-format off
80  #pragma HLS stream variable=imgInput.data depth=2
81  // clang-format on
82 
83  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
84  // clang-format off
85  #pragma HLS stream variable=imgOutput.data depth=2
86  // clang-format on
87 
88  // clang-format off
89  #pragma HLS DATAFLOW
90  // clang-format on
91 
92  accel_utils accel_utils_obj;
93 
94  int dstMat_cols_align_npc = ((imgInput.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
95 
96  accel_utils_obj.hlsStrm2xfMat<INPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX, (HEIGHT * WIDTH) / NPIX>(img_in_axi_stream, imgInput, dstMat_cols_align_npc);
97 
98  xf::cv::medianBlur<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
99 
100  int srcMat_cols_align_npc = ((imgOutput.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
101 
102  accel_utils_obj.xfMat2hlsStrm<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX, HEIGHT*((WIDTH + NPIX - 1) / NPIX)>(imgOutput, img_out_axi_stream,
103  srcMat_cols_align_npc);
104 }
#define WIDTH
#define NPIX
#define HEIGHT
#define INPUT_PTR_WIDTH
#define OUTPUT_PTR_WIDTH
#define TYPE

◆ print_cFpZoo()

void print_cFpZoo ( void  )

Definition at line 57 of file sobel_host.cpp.

58 {
59  cout << " " << endl;
60  cout << "...build with: " << endl;
61  cout << " ██████╗███████╗██████╗ ███████╗ ██████╗ ██████╗ " << endl;
62  cout << "██╔════╝██╔════╝██╔══██╗ ╚══███╔╝██╔═══██╗██╔═══██╗ " << endl;
63  cout << "██║ █████╗ ██████╔╝ ███╔╝ ██║ ██║██║ ██║ " << endl;
64  cout << "██║ ██╔══╝ ██╔═══╝ ███╔╝ ██║ ██║██║ ██║ " << endl;
65  cout << "╚██████╗██║ ██║███████╗███████╗╚██████╔╝╚██████╔╝ " << endl;
66  cout << " ╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═════╝ ╚═════╝ " << endl;
67  cout << "A cloudFPGA project from IBM ZRL v1.0 " << endl;
68  cout << "Quantitative Finance Monte-Carlo European Pricing Engine " << endl;
69 }

◆ resizeCropSquare()

void resizeCropSquare ( const cv::Mat &  input,
const cv::Mat &  output,
const cv::Size &  dstSize,
int  interpolation = INTER_LINEAR 
)

Resize an image and crop if necessary in order to keep a rectangle area in the middle of the image.

Parameters
[in]inputA pointer to the cv::Mat input image
[out]outputA pointer to the cv::Mat output image
[in]SizeA pointer to the cv::Size of the output image (width, height)
[in]interpolationEnumerator for interpolation algorithm (imgproc.hpp)
Returns
Nothing.

Definition at line 82 of file sobel_host.cpp.

83 {
84  int h = input.rows;
85  int w = input.cols;
86  int min_size = min(h, w);
87  int x = w/2-min_size/2;
88  int y = h/2-min_size/2;
89  // printf("w=%d, h=%d, min_size=%d, x=%d, y=%d, width=%d, height=%d\n", w, h, min_size, x, y, width, height);
90  cv::Mat crop_img = input(Rect(x, y, min_size, min_size));
91  resize(crop_img, output, Size(dstSize.width, dstSize.height), 0, 0, interpolation);
92 }
string input
Definition: test.py:9
string output
Definition: test.py:10

◆ sobel_accel()

void sobel_accel ( xf::cv::Mat< XF_8UC1, 1024, 1024, XF_NPPC1 > &  _src,
xf::cv::Mat< XF_8UC1, 1024, 1024, XF_NPPC1 > &  _dst 
)
Here is the caller graph for this function: