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

This is a subgroup of Gammacorrection accelerated function with only testbench-related functions/classes/. More...

Collaboration diagram for Gammacorrection Testbench:

Files

file  gammacorrection_host_fwd_tb.cpp
 Testbench for Gammacorrection userspace application for cF (x86, ppc64).
 
file  xf_ocv_ref.hpp
 The Gammacorrection reference functions used in TB.
 
file  test_gammacorrection.cpp
 : Testbench for Gammacorrection.
 

Macros

#define THIS_NAME   "TB"
 
#define TRACE_OFF   0x0000
 
#define TRACE_URIF   1 << 1
 
#define TRACE_UAF   1 << 2
 
#define TRACE_MMIO   1 << 3
 
#define TRACE_ALL   0xFFFF
 
#define DEBUG_LEVEL   (TRACE_ALL)
 
#define OK   true
 
#define KO   false
 
#define VALID   true
 
#define UNVALID   false
 
#define DEBUG_TRACE   true
 
#define ENABLED   (ap_uint<1>)1
 
#define DISABLED   (ap_uint<1>)0
 

Typedefs

typedef float NMSTYPE
 

Functions

int main (int argc, char *argv[])
 
bool OCVFindMaximum2 (NMSTYPE *t1, NMSTYPE *t2, NMSTYPE *m1, NMSTYPE *b1, NMSTYPE *b2)
 
void OCVMaxSuppression2 (cv::Mat &src, cv::Mat &dst)
 
bool OCVFindMaximum1 (NMSTYPE t0, NMSTYPE t1, NMSTYPE t2, NMSTYPE m0, NMSTYPE m1, NMSTYPE m2, NMSTYPE b0, NMSTYPE b1, NMSTYPE b2)
 
void OCVMaxSuppression1 (cv::Mat &src, cv::Mat &dst)
 
void ocv_ref (cv::Mat img_gray, cv::Mat &ocv_out_img, float Th)
 
stream< UdpWordsSHL_Uaf_Data ("sSHL_Uaf_Data")
 
stream< UdpWordsUAF_Shl_Data ("sUAF_Shl_Data")
 
stream< UdpWordimage_stream_from_gammacorrection ("image_stream_from_gammacorrection")
 
stream< NetworkMetaStreamsiUdp_meta ("siUdp_meta")
 
stream< NetworkMetaStreamsoUdp_meta ("soUdp_meta")
 
void stepDut ()
 Run a single iteration of the DUT model. More...
 
int main (int argc, char **argv)
 Main testbench of Hrris. More...
 

Variables

ap_uint< 1 > piSHL_This_MmioPostPktEn
 
ap_uint< 1 > piSHL_This_MmioCaptPktEn
 
ap_uint< 32 > s_udp_rx_ports = 0x0
 
ap_uint< 32 > node_rank
 
ap_uint< 32 > cluster_size
 
int simCnt
 

Detailed Description

This is a subgroup of Gammacorrection accelerated function with only testbench-related functions/classes/.

This is a subgroup of Gammacorrection accelerated function with only testbench-related functions/classes.

Macro Definition Documentation

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   (TRACE_ALL)

Definition at line 36 of file test_gammacorrection.cpp.

◆ DEBUG_TRACE

#define DEBUG_TRACE   true

Definition at line 46 of file test_gammacorrection.cpp.

◆ DISABLED

#define DISABLED   (ap_uint<1>)0

Definition at line 49 of file test_gammacorrection.cpp.

◆ ENABLED

#define ENABLED   (ap_uint<1>)1

Definition at line 48 of file test_gammacorrection.cpp.

◆ KO

#define KO   false

Definition at line 43 of file test_gammacorrection.cpp.

◆ OK

#define OK   true

Definition at line 42 of file test_gammacorrection.cpp.

◆ THIS_NAME

#define THIS_NAME   "TB"

Definition at line 28 of file test_gammacorrection.cpp.

◆ TRACE_ALL

#define TRACE_ALL   0xFFFF

Definition at line 34 of file test_gammacorrection.cpp.

◆ TRACE_MMIO

#define TRACE_MMIO   1 << 3

Definition at line 33 of file test_gammacorrection.cpp.

◆ TRACE_OFF

#define TRACE_OFF   0x0000

Definition at line 30 of file test_gammacorrection.cpp.

◆ TRACE_UAF

#define TRACE_UAF   1 << 2

Definition at line 32 of file test_gammacorrection.cpp.

◆ TRACE_URIF

#define TRACE_URIF   1 << 1

Definition at line 31 of file test_gammacorrection.cpp.

◆ UNVALID

#define UNVALID   false

Definition at line 45 of file test_gammacorrection.cpp.

◆ VALID

#define VALID   true

Definition at line 44 of file test_gammacorrection.cpp.

Typedef Documentation

◆ NMSTYPE

typedef float NMSTYPE

Definition at line 36 of file xf_ocv_ref.hpp.

Function Documentation

◆ image_stream_from_gammacorrection()

stream<UdpWord> image_stream_from_gammacorrection ( "image_stream_from_gammacorrection"  )

◆ main() [1/2]

int main ( int  argc,
char **  argv 
)

Main testbench of Hrris.

Returns
0 upon success, nrErr else.

hls_out_img.data = (unsigned char *)imgOutput.copyFrom();

Definition at line 100 of file test_gammacorrection.cpp.

100  {
101 
102  //------------------------------------------------------
103  //-- TESTBENCH LOCAL VARIABLES
104  //------------------------------------------------------
105  int nrErr = 0;
106 
107  printf("#####################################################\n");
108  printf("## TESTBENCH STARTS HERE ##\n");
109  printf("#####################################################\n");
110 
111  simCnt = 0;
112  nrErr = 0;
113 
114  //------------------------------------------------------
115  //-- TESTBENCH LOCAL VARIABLES FOR GAMMACORRECTION
116  //------------------------------------------------------
117  cv::Mat in_img, img_gray;
118  cv::Mat hls_out_img, ocv_out_img;
119 
120  if (argc != 2) {
121  printf("Usage : %s <input image> \n", argv[0]);
122  return -1;
123  }
124  in_img = cv::imread(argv[1], 0); // reading in the color image
125 
126  if (!in_img.data) {
127  printf("Failed to load the image ... %s\n!", argv[1]);
128  return -1;
129  }
130  else {
131  printf("Succesfully loaded image ... %s\n!", argv[1]);
132  }
133 
134  uint16_t Thresh; // Threshold for HLS
135  float Th;
136  if (FILTER_WIDTH == 3) {
137  Th = 30532960.00;
138  Thresh = 442;
139  } else if (FILTER_WIDTH == 5) {
140  Th = 902753878016.0;
141  Thresh = 3109;
142  } else if (FILTER_WIDTH == 7) {
143  Th = 41151168289701888.000000;
144  Thresh = 566;
145  }
146 
147 
148  //------------------------------------------------------
149  //-- STEP-1.1 : CREATE MEMORY FOR OUTPUT IMAGES
150  //------------------------------------------------------
151  // cvtColor(in_img, img_gray, CV_BGR2GRAY);
152  // Convert rgb into grayscale
153  hls_out_img.create(in_img.rows, in_img.cols, CV_8U); // create memory for hls output image
154  ocv_out_img.create(in_img.rows, in_img.cols, CV_8U); // create memory for opencv output image
155 
156  #if NO
157 
158  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1> imgInput(in_img.rows, in_img.cols);
159  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutput(in_img.rows, in_img.cols);
160  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutputTb(in_img.rows, in_img.cols);
161 
162  imgInput.copyTo(in_img.data);
163  // imgInput = xf::cv::imread<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1>(argv[1], 0);
164 
165  ap_uint<INPUT_PTR_WIDTH> imgInputArray[in_img.rows * in_img.cols];
166  ap_uint<OUTPUT_PTR_WIDTH> imgOutputArrayTb[in_img.rows * in_img.cols];
167  ap_uint<OUTPUT_PTR_WIDTH> imgOutputArray[in_img.rows * in_img.cols];
168 
169  xf::cv::xfMat2Array<OUTPUT_PTR_WIDTH, IN_TYPE, HEIGHT, WIDTH, NPIX>(imgInput, imgInputArray);
170 
171  if (!dumpImgToFile(imgInput, "ifsSHL_Uaf_Data.dat", simCnt)) {
172  nrErr++;
173  }
174 
175  #endif
176 
177  #if RO
178 
179  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC8> imgInput(in_img.rows, in_img.cols);
180  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC8> imgOutput(in_img.rows, in_img.cols);
181  static xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, XF_NPPC1> imgOutputTb(in_img.rows, in_img.cols);
182 
183  // imgInput.copyTo(img_gray.data);
184  imgInput = xf::cv::imread<IN_TYPE, HEIGHT, WIDTH, XF_NPPC8>(argv[1], 0);
185 
186  #endif
187 
188 
189 
190  //------------------------------------------------------
191  //-- STEP-1.2 : RUN GAMMACORRECTION DETECTOR FROM OpenCV LIBRARY
192  //------------------------------------------------------
193  ocv_ref(in_img, ocv_out_img, Th);
194 
195 
196  //------------------------------------------------------
197  //-- STEP-2.1 : CREATE TRAFFIC AS INPUT STREAMS
198  //------------------------------------------------------
199  if (nrErr == 0) {
200  if (!setInputDataStream(sSHL_Uaf_Data, "sSHL_Uaf_Data", "ifsSHL_Uaf_Data.dat", simCnt)) {
201  printf("### ERROR : Failed to set input data stream \"sSHL_Uaf_Data\". \n");
202  nrErr++;
203  }
204 
205  //there are TOT_TRANSFERS streams from the the App to the Role
207  for (int i=0; i<TOT_TRANSFERS; i++) {
208  siUdp_meta.write(NetworkMetaStream(tmp_meta));
209  }
210  //set correct node_rank and cluster_size
211  node_rank = 1;
212  cluster_size = 2;
213  }
214 
215  //------------------------------------------------------
216  //-- STEP-2.2 : SET THE PASS-THROUGH MODE
217  //------------------------------------------------------
218  //piSHL_This_MmioEchoCtrl.write(ECHO_PATH_THRU);
219  //[TODO] piSHL_This_MmioPostPktEn.write(DISABLED);
220  //[TODO] piSHL_This_MmioCaptPktEn.write(DISABLED);
221 
222  //------------------------------------------------------
223  //-- STEP-3 : MAIN TRAFFIC LOOP
224  //------------------------------------------------------
225  while (!nrErr) {
226 
227  if (simCnt < IMG_PACKETS*3+10) // Keep enough simulation time for sequntially executing the
228  // FSMs of the main 3 functions (Rx-Proc-Tx)
229  {
230  stepDut();
231 
232  if(simCnt > 2)
233  {
234  assert(s_udp_rx_ports == 0x1);
235  }
236 
237  //if( !soUdp_meta.empty())
238  //{
239  // NetworkMetaStream tmp_meta = soUdp_meta.read();
240  // printf("NRC received NRCmeta stream from node_rank %d.\n", (int) tmp_meta.tdata.src_rank);
241  //}
242 
243 
244  } else {
245  printf("## End of simulation at cycle=%3d. \n", simCnt);
246  break;
247  }
248 
249  } // End: while()
250 
251  //-------------------------------------------------------
252  //-- STEP-4 : DRAIN AND WRITE OUTPUT FILE STREAMS
253  //-------------------------------------------------------
254  //---- UAF-->SHELL Data ----
255  if (!getOutputDataStream(sUAF_Shl_Data, "sUAF_Shl_Data", "ofsUAF_Shl_Data.dat", simCnt))
256  {
257  nrErr++;
258  }
259  //---- UAF-->SHELL META ----
260  if( !soUdp_meta.empty())
261  {
262  int i = 0;
263  while( !soUdp_meta.empty())
264  {
265  i++;
266  NetworkMetaStream tmp_meta = soUdp_meta.read();
267  printf("NRC received NRCmeta stream from rank %d to rank %d.\n", (int) tmp_meta.tdata.src_rank, (int) tmp_meta.tdata.dst_rank);
268  assert(tmp_meta.tdata.src_rank == node_rank);
269  //ensure forwarding behavior
270  assert(tmp_meta.tdata.dst_rank == ((tmp_meta.tdata.src_rank + 1) % cluster_size));
271  }
272  assert(i == TOT_TRANSFERS);
273  }
274  else {
275  printf("Error No metadata received...\n");
276  nrErr++;
277  }
278 
279  //-------------------------------------------------------
280  //-- STEP-5 : FROM THE OUTPUT FILE CREATE AN ARRAY
281  //-------------------------------------------------------
282  if (!setInputFileToArray("ofsUAF_Shl_Data.dat", imgOutputArray, simCnt)) {
283  printf("### ERROR : Failed to set input array from file \"ofsUAF_Shl_Data.dat\". \n");
284  nrErr++;
285  }
286  xf::cv::Array2xfMat<INPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX>(imgOutputArray, imgOutput);
287 
288 
289  //------------------------------------------------------
290  //-- STEP-6 : COMPARE INPUT AND OUTPUT FILE STREAMS
291  //------------------------------------------------------
292  int rc1 = system("diff --brief -w -i -y ../../../../test/ofsUAF_Shl_Data.dat \
293  ../../../../test/verify_UAF_Shl_Data.dat");
294  if (rc1)
295  {
296  printf("## Error : File \'ofsUAF_Shl_Data.dat\' does not match \'verify_UAF_Shl_Data.dat\'.\n");
297  } else {
298  printf("Output data in file \'ofsUAF_Shl_Data.dat\' verified.\n");
299  }
300 
301  nrErr += rc1;
302 
303  printf("#####################################################\n");
304  if (nrErr)
305  {
306  printf("## ERROR - TESTBENCH FAILED (RC=%d) !!! ##\n", nrErr);
307  } else {
308  printf("## SUCCESSFULL END OF TESTBENCH (RC=0) ##\n");
309  }
310  printf("#####################################################\n");
311 
312 
313 
314 
315 
316 
317 
318 
319 
320 
321 
322 
323 
324 
325  float K = 0.04;
326  uint16_t k = K * (1 << 16); // Convert to Q0.16 format
327 
328  #if NO
329 
330  // L2 Vitis Gammacorrection
331  GammacorrectionAccelArray(imgInputArray, imgOutputArrayTb, in_img.rows, in_img.cols, Thresh, k);
332  xf::cv::Array2xfMat<INPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX>(imgOutputArrayTb, imgOutputTb);
333 
334  // L1 Vitis Gammacorrection
335  //gammacorrection_accel(imgInput, imgOutput, Thresh, k);
336 
337  #endif
338 
339  #if RO
340 
341  gammacorrection_accel(imgInput, imgOutputTb, Thresh, k);
342 
343  #endif
344 
346  xf::cv::imwrite("hls_out_tb.jpg", imgOutputTb);
347  xf::cv::imwrite("hls_out.jpg", imgOutput);
348 
349  unsigned int val;
350  unsigned short int row, col;
351 
352  cv::Mat out_img;
353  out_img = in_img.clone();
354 
355  std::vector<cv::Point> hls_points;
356  std::vector<cv::Point> ocv_points;
357  std::vector<cv::Point> common_pts;
358 
359  xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPIX>* select_imgOutput;
360 
361  // Select which output you want to process for image outputs and corners comparisons:
362  // &imgOutput : The processed image by Gammacorrection IP inside the ROLE (i.e. I/O traffic is passing through SHELL)
363  // &imgOutputTb : The processed image by Gammacorrection IP in this testbench (i.e. I/O traffic is done in testbench)
364  select_imgOutput = &imgOutput;
365 
366  // Mark HLS points on the image
367  markPointsOnImage(*select_imgOutput, in_img, out_img, hls_points);
368 
369  // Write HLS and Opencv corners into a file
370  //nrErr +=
371  writeCornersIntoFile(in_img, ocv_out_img, out_img, hls_points, ocv_points, common_pts);
372 
373  // Gamma Correction TB
374  xf::cv::imwrite("gammacorrection_in_hls.jpg", imgInput);
375  gammacorrection_accel(imgInput, imgOutput, 0.1);
376  xf::cv::imwrite("gammacorrection_out_hls.jpg", imgOutput);
377 
378 
379  return(nrErr);
380 }
#define FILTER_WIDTH
stream< NetworkMetaStream > siUdp_meta("siUdp_meta")
stream< NetworkMetaStream > soUdp_meta("soUdp_meta")
void ocv_ref(cv::Mat img_gray, cv::Mat &ocv_out_img, float Th)
Definition: xf_ocv_ref.hpp:552
int simCnt
stream< UdpWord > sUAF_Shl_Data("sUAF_Shl_Data")
void stepDut()
Run a single iteration of the DUT model.
stream< UdpWord > sSHL_Uaf_Data("sSHL_Uaf_Data")
ap_uint< 32 > cluster_size
ap_uint< 32 > s_udp_rx_ports
ap_uint< 32 > node_rank
void gammacorrection_accel(xf::cv::Mat< XF_8UC1, 256, 256, XF_NPPC1 > &_src, xf::cv::Mat< XF_8UC1, 256, 256, XF_NPPC1 > &_dst, unsigned short Thresh, unsigned short k)
void markPointsOnImage(Mat &imgOutput, Mat &in_img, Mat &out_img, vector< Point > &hw_points)
Mark the points found by Gammacorrection into the image.
#define IMG_PACKETS
void GammacorrectionAccelArray(ap_uint< 64 > *img_inp, ap_uint< 64 > *img_out, int rows, int cols, int threshold, int k)
Top-level accelerated function of the Gammacorrection Application with array I/F.
#define TOT_TRANSFERS
Definition: config.h:70
bool setInputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string inpFileName)
Initialize an input data stream from a file.
Definition: tb_nal.cpp:214
#define DEFAULT_RX_PORT
Definition: nal.hpp:139
bool getOutputDataStream(stream< UdpAppData > &sDataStream, const string dataStreamName, const string outFileName)
Fill an output file with data from an output stream.
Definition: tb_nal.cpp:526
unsigned int writeCornersIntoFile(cv::Mat &in_img, cv::Mat &ocv_out_img, cv::Mat &out_img, std::vector< cv::Point > &hls_points, std::vector< cv::Point > &ocv_points, std::vector< cv::Point > &common_pts)
Write the corners found by Harris into a file.
Definition: common.cpp:437
bool dumpImgToFile(xf::cv::Mat< OUT_TYPE, HEIGHT, WIDTH, NPIX > &_img, const std::string outFileName, int simCnt)
Fill an output file with data from an image.
bool setInputFileToArray(const std::string inpFileName, ap_uint< OUTPUT_PTR_WIDTH > *imgArray, int simCnt)
Initialize an input array from a file with format "tdata tkeep tlast".
NetworkMeta tdata
Definition: network.hpp:109
NodeId dst_rank
Definition: network.hpp:95
NodeId src_rank
Definition: network.hpp:97
Here is the call graph for this function:

◆ main() [2/2]

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

Main testbench for the user-application for Gammacorrection on host. Server

Returns
O on success, 1 on fail

Definition at line 45 of file gammacorrection_host_fwd_tb.cpp.

45  {
46 
47  if ((argc < 2) || (argc > 3)) { // Test for correct number of parameters
48  cerr << "Usage: " << argv[0] << " <Server Port> <optional simulation mode>" << endl;
49  exit(1);
50  }
51 
52  unsigned short servPort = atoi(argv[1]); // First arg: local port
53  unsigned int num_frame = 0;
54  string clean_cmd;
55 
56  namedWindow("tb_recv", WINDOW_AUTOSIZE);
57  try {
58  UDPSocket sock(servPort);
59 
60  char buffer[BUF_LEN]; // Buffer for echo string
61  int recvMsgSize; // Size of received message
62  string sourceAddress; // Address of datagram source
63  unsigned short sourcePort; // Port of datagram source
64 
65  // RX Step
66  clock_t last_cycle_rx = clock();
67  while (1) {
68  // Block until receive message from a client
69 
70  int total_pack = 1 + (FRAME_TOTAL - 1) / PACK_SIZE;
71  int bytes_in_last_pack = (FRAME_TOTAL) - (total_pack - 1) * PACK_SIZE;
72  int receiving_now = PACK_SIZE;
73  cout << " ___________________________________________________________________ " << endl;
74  cout << "/ \\" << endl;
75  cout << "INFO: Proxy tb Frame # " << ++num_frame << endl;
76  cout << "INFO: Expecting length of packs:" << total_pack << endl;
77  char * longbuf = new char[PACK_SIZE * total_pack];
78 
79  // RX Loop
80  for (int i = 0; i < total_pack; i++) {
81  if ( i == total_pack - 1 ) {
82  receiving_now = bytes_in_last_pack;
83  }
84  recvMsgSize = sock.recvFrom(buffer, BUF_LEN, sourceAddress, sourcePort);
85  if (recvMsgSize != receiving_now) {
86  cerr << "ERROR: Received unexpected size pack:" << recvMsgSize << endl;
87  continue;
88  }
89  memcpy( & longbuf[i * PACK_SIZE], buffer, receiving_now);
90  }
91 
92  cout << "INFO: Received packet from " << sourceAddress << ":" << sourcePort << endl;
93 
94  cv::Mat frame = cv::Mat(FRAME_HEIGHT, FRAME_WIDTH, INPUT_TYPE_HOST, longbuf); // OR vec.data() instead of ptr
95  if (frame.size().width == 0) {
96  cerr << "ERROR: receive failure!" << endl;
97  continue;
98  }
99  imshow("tb_recv", frame);
100 
101  // We save the image received from network in order to process it with the gammacorrection HLS TB
102  imwrite("../../../../ROLE/vision/hls/gammacorrection/test/input_from_udp_to_fpga.png", frame);
103 
104  // Select simulation mode, default fcsim
105  string exec_cmd = "make fcsim -j 4";
106  string ouf_file = "../../../../ROLE/vision/hls/gammacorrection/gammacorrection_prj/solution1/fcsim/build/hls_out.jpg";
107  if (argc == 3) {
108  if (atoi(argv[2]) == 2) {
109  exec_cmd = "make csim";
110  ouf_file = "../../../../ROLE/vision/hls/gammacorrection/gammacorrection_prj/solution1/csim/build/hls_out.jpg";
111  }
112  else if (atoi(argv[2]) == 3) {
113  exec_cmd = "make cosim";
114  ouf_file = "../../../../ROLE/vision/hls/gammacorrection/gammacorrection_prj/solution1/cosim/build/hls_out.jpg";
115  }
116  else if (atoi(argv[2]) == 4) {
117  exec_cmd = "make kcachegrind";
118  ouf_file = "../../../../ROLE/vision/hls/gammacorrection/gammacorrection_prj/solution1/fcsim/build/hls_out.jpg";
119  }
120  }
121  // Calling the actual TB over its typical makefile procedure, but passing the save file
122  // Skip the rebuilding phase on the 2nd run. However ensure that it's a clean recompile
123  // the first time.
124  clean_cmd = " ";
125  if (num_frame == 1) {
126  clean_cmd = "make clean && ";
127  }
128  string str_command = "cd ../../../../ROLE/vision/hls/gammacorrection/ && " + clean_cmd + "\
129  INPUT_IMAGE=./test/input_from_udp_to_fpga.png " + exec_cmd + " && \
130  cd ../../../../HOST/vision/gammacorrection/build/ ";
131  const char *command = str_command.c_str();
132  cout << "Calling TB with command:" << command << endl;
133  system(command);
134 
135  free(longbuf);
136 
137  clock_t next_cycle_rx = clock();
138  double duration_rx = (next_cycle_rx - last_cycle_rx) / (double) CLOCKS_PER_SEC;
139  cout << "INFO: Effective FPS RX:" << (1 / duration_rx) << " \tkbps:" << (PACK_SIZE *
140  total_pack / duration_rx / 1024 * 8) << endl;
141  last_cycle_rx = next_cycle_rx;
142 
143 
144  // TX step
145  frame = cv::imread(ouf_file, cv::IMREAD_GRAYSCALE); // reading in the image in grey scale
146  if (!frame.data) {
147  cerr << "ERROR: Failed to load the image " << ouf_file << endl;
148  return -1;
149  }
150  else {
151  cout << "INFO: Succesfully loaded image " << ouf_file << endl;
152  }
153 
154  assert(frame.total() == FRAME_WIDTH * FRAME_HEIGHT);
155 
156  imshow("tb_send", frame);
157 
158  // Ensure that the send Mat is in continuous memory space. Typically, imread or resize
159  // will return such a continuous Mat, but we should check it.
160  assert(frame.isContinuous());
161 
162  // TX Loop
163  unsigned int sending_now = PACK_SIZE;
164  clock_t last_cycle_tx = clock();
165  for (int i = 0; i < total_pack; i++) {
166  if ( i == total_pack - 1 ) {
167  sending_now = bytes_in_last_pack;
168  }
169  sock.sendTo( & frame.data[i * PACK_SIZE], sending_now, sourceAddress, sourcePort);
170  }
171 
172  clock_t next_cycle_tx = clock();
173  double duration_tx = (next_cycle_tx - last_cycle_tx) / (double) CLOCKS_PER_SEC;
174  cout << "INFO: Effective FPS TX:" << (1 / duration_tx) << " \tkbps:" << (PACK_SIZE *
175  total_pack / duration_tx / 1024 * 8) << endl;
176  last_cycle_tx = next_cycle_tx;
177  cout << "\\___________________________________________________________________/" << endl;
178  } // while loop
179 
180  } catch (SocketException & e) {
181  cerr << e.what() << endl;
182  exit(1);
183  }
184  return 0;
185 }
#define FRAME_TOTAL
Definition: config.h:74
#define INPUT_TYPE_HOST
Definition: config.h:68
#define FRAME_HEIGHT
Definition: config.h:43
#define FRAME_WIDTH
Definition: config.h:46
#define BUF_LEN
Definition: config.h:54
#define PACK_SIZE
Definition: config.h:51
def clock()
Definition: common.py:174
Here is the call graph for this function:

◆ ocv_ref()

void ocv_ref ( cv::Mat  img_gray,
cv::Mat &  ocv_out_img,
float  Th 
)

Definition at line 552 of file xf_ocv_ref.hpp.

552  {
553  cv::Mat gradx, grady;
554  cv::Mat gradx2, grady2, gradxy;
555  cv::Mat gradx2g, grady2g, gradxyg;
556  cv::Mat x2y2, xy, mtrace;
557  cv::Mat dst, ocvthresh_img;
558 
559 
560  // Step one: Apply gradient
561  cv::Sobel(img_gray, gradx, CV_32FC1, 1, 0, FILTER_WIDTH, 1, 0, cv::BORDER_CONSTANT);
562  cv::Sobel(img_gray, grady, CV_32FC1, 0, 1, FILTER_WIDTH, 1, 0, cv::BORDER_CONSTANT);
563  // Step Two: Calculate gx^2, gy^2, gx*gy
564  pow(gradx, 2.0, gradx2);
565  pow(grady, 2.0, grady2);
566  multiply(gradx, grady, gradxy);
567  // Step Three: Apply boxfilter
568  cv::boxFilter(gradx2, gradx2g, -1, cv::Size(BLOCK_WIDTH, BLOCK_WIDTH));
569  cv::boxFilter(grady2, grady2g, -1, cv::Size(BLOCK_WIDTH, BLOCK_WIDTH));
570  cv::boxFilter(gradxy, gradxyg, -1, cv::Size(BLOCK_WIDTH, BLOCK_WIDTH));
571 
572  multiply(gradx2g, grady2g, x2y2);
573  multiply(gradxyg, gradxyg, xy);
574  pow((gradx2g + grady2g), 2.0, mtrace);
575 
576  // Step Four: Compute score
577  dst.create(img_gray.rows, img_gray.cols, CV_32FC1);
578  ocvthresh_img.create(img_gray.rows, img_gray.cols, dst.depth());
579 
580  float sum = 0;
581  for (int j = 0; j < img_gray.rows; j++) {
582  for (int i = 0; i < img_gray.cols; i++) {
583  float v1 = x2y2.at<float>(j, i);
584  float v2 = xy.at<float>(j, i);
585  float v3 = mtrace.at<float>(j, i);
586  float temp1 = (v1 - v2) - (0.04 * v3);
587  dst.at<float>(j, i) = temp1;
588 
589  if (temp1 > 0.0) sum += temp1;
590  }
591  }
592  //float meanval = sum / (img_gray.rows * img_gray.cols);
593 
594  // Step five: Apply Threshold
595  for (int i = 0; i < img_gray.rows; i++) {
596  for (int j = 0; j < img_gray.cols; j++) {
597  float pix = dst.at<NMSTYPE>(i, j);
598  if (pix > Th) {
599  ocvthresh_img.at<NMSTYPE>(i, j) = pix;
600  } else {
601  ocvthresh_img.at<NMSTYPE>(i, j) = 0;
602  }
603  }
604  }
605 
606  // Step six: Find Non maxima supppression
607  if (NMS_RADIUS == 1) {
608  OCVMaxSuppression1(ocvthresh_img, ocv_out_img);
609  } else if (NMS_RADIUS == 2) {
610  OCVMaxSuppression2(ocvthresh_img, ocv_out_img);
611  }
612 
613  gradx.~Mat();
614  grady.~Mat();
615  gradx2.~Mat();
616  grady2.~Mat();
617  gradxy.~Mat();
618  gradx2g.~Mat();
619  grady2g.~Mat();
620  gradxyg.~Mat();
621  x2y2.~Mat();
622  xy.~Mat();
623  mtrace.~Mat();
624  dst.~Mat();
625  ocvthresh_img.~Mat();
626 
627 }
#define NMS_RADIUS
#define BLOCK_WIDTH
void OCVMaxSuppression2(cv::Mat &src, cv::Mat &dst)
Definition: xf_ocv_ref.hpp:48
float NMSTYPE
Definition: xf_ocv_ref.hpp:36
void OCVMaxSuppression1(cv::Mat &src, cv::Mat &dst)
Definition: xf_ocv_ref.hpp:454
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OCVFindMaximum1()

bool OCVFindMaximum1 ( NMSTYPE  t0,
NMSTYPE  t1,
NMSTYPE  t2,
NMSTYPE  m0,
NMSTYPE  m1,
NMSTYPE  m2,
NMSTYPE  b0,
NMSTYPE  b1,
NMSTYPE  b2 
)

Definition at line 446 of file xf_ocv_ref.hpp.

447  {
448  bool Max = false;
449  if (m1 > t1 && m1 > m0 && m1 > m2 && m1 > b1) Max = true;
450  return Max;
451 }
Here is the caller graph for this function:

◆ OCVFindMaximum2()

bool OCVFindMaximum2 ( NMSTYPE t1,
NMSTYPE t2,
NMSTYPE m1,
NMSTYPE b1,
NMSTYPE b2 
)

Definition at line 38 of file xf_ocv_ref.hpp.

38  {
39  bool Max = false;
40  NMSTYPE maxval = m1[2];
41  if ((maxval > t1[2]) && (maxval > t2[1]) && (maxval > t2[2]) && (maxval > t2[3]) && (maxval > m1[0]) &&
42  (maxval > m1[1]) && (maxval > m1[3]) && (maxval > m1[4]) && (maxval > b1[1]) && (maxval > b1[2]) &&
43  (maxval > b1[3]) && (maxval > b2[2]))
44  Max = true;
45  return Max;
46 }
Here is the caller graph for this function:

◆ OCVMaxSuppression1()

void OCVMaxSuppression1 ( cv::Mat &  src,
cv::Mat &  dst 
)

Definition at line 454 of file xf_ocv_ref.hpp.

454  {
455  int i, j;
456  NMSTYPE t0, t1, t2;
457  NMSTYPE m0, m1, m2;
458  NMSTYPE b0, b1, b2;
459  bool result;
460 
461  /* First row */
462  i = 0;
463  for (j = 0; j < src.cols; j++) {
464  if (j == 0) {
465  t0 = 0;
466  t1 = 0;
467  t2 = 0;
468  m0 = 0;
469  m1 = src.at<NMSTYPE>(i, j);
470  m2 = src.at<NMSTYPE>(i, j + 1);
471  b0 = 0;
472  b1 = src.at<NMSTYPE>(i + 1, j);
473  b2 = src.at<NMSTYPE>(i + 1, j + 1);
474  } else if ((j > 0) && (j < src.cols - 1)) {
475  t0 = 0;
476  t1 = 0;
477  t2 = 0;
478  m0 = src.at<NMSTYPE>(i, j - 1);
479  m1 = src.at<NMSTYPE>(i, j);
480  m2 = src.at<NMSTYPE>(i, j + 1);
481  b0 = src.at<NMSTYPE>(i + 1, j - 1);
482  b1 = src.at<NMSTYPE>(i + 1, j);
483  b2 = src.at<NMSTYPE>(i + 1, j + 1);
484  } else if (j == src.cols - 1) {
485  t0 = 0;
486  t1 = 0;
487  t2 = 0;
488  m0 = src.at<NMSTYPE>(i, j - 1);
489  m1 = src.at<NMSTYPE>(i, j);
490  m2 = 0;
491  b0 = src.at<NMSTYPE>(i + 1, j - 1);
492  b1 = src.at<NMSTYPE>(i + 1, j);
493  b2 = 0;
494  }
495  result = OCVFindMaximum1(t0, t1, t2, m0, m1, m2, b0, b1, b2);
496  dst.at<uchar>(i, j) = result ? 255 : 0;
497  }
498  for (i = 1; i < src.rows - 1; i++) {
499  for (j = 0; j < src.cols; j++) {
500  if (j == 0) {
501  t0 = 0;
502  t1 = src.at<NMSTYPE>(i - 1, j);
503  t2 = src.at<NMSTYPE>(i - 1, j + 1);
504  m0 = 0;
505  m1 = src.at<NMSTYPE>(i, j);
506  m2 = src.at<NMSTYPE>(i, j + 1);
507  b0 = 0;
508  b1 = src.at<NMSTYPE>(i + 1, j);
509  b2 = src.at<NMSTYPE>(i + 1, j + 1);
510  } else if ((j > 0) && (j < src.cols - 1)) {
511  t0 = src.at<NMSTYPE>(i - 1, j - 1);
512  t1 = src.at<NMSTYPE>(i - 1, j);
513  t2 = src.at<NMSTYPE>(i - 1, j + 1);
514  m0 = src.at<NMSTYPE>(i, j - 1);
515  m1 = src.at<NMSTYPE>(i, j);
516  m2 = src.at<NMSTYPE>(i, j + 1);
517  b0 = src.at<NMSTYPE>(i + 1, j - 1);
518  b1 = src.at<NMSTYPE>(i + 1, j);
519  b2 = src.at<NMSTYPE>(i + 1, j + 1);
520  } else if (j == src.cols - 1) {
521  t0 = src.at<NMSTYPE>(i - 1, j - 1);
522  t1 = src.at<NMSTYPE>(i - 1, j);
523  t2 = 0;
524  m0 = src.at<NMSTYPE>(i, j - 1);
525  m1 = src.at<NMSTYPE>(i, j);
526  m2 = 0;
527  b0 = src.at<NMSTYPE>(i + 1, j - 1);
528  b1 = src.at<NMSTYPE>(i + 1, j);
529  b2 = 0;
530  }
531  result = OCVFindMaximum1(t0, t1, t2, m0, m1, m2, b0, b1, b2);
532  dst.at<uchar>(i, j) = result ? 255 : 0;
533  }
534  }
535  /* Last row */
536  i = src.rows - 1;
537  for (j = 1; j < src.cols - 1; j++) {
538  t0 = src.at<NMSTYPE>(i - 1, j - 1);
539  t1 = src.at<NMSTYPE>(i - 1, j);
540  t2 = src.at<NMSTYPE>(i - 1, j + 1);
541  m0 = src.at<NMSTYPE>(i, j - 1);
542  m1 = src.at<NMSTYPE>(i, j);
543  m2 = src.at<NMSTYPE>(i, j + 1);
544  b0 = 0;
545  b1 = 0;
546  b2 = 0;
547  result = OCVFindMaximum1(t0, t1, t2, m0, m1, m2, b0, b1, b2);
548  dst.at<uchar>(i, j) = result ? 255 : 0;
549  }
550 }
bool OCVFindMaximum1(NMSTYPE t0, NMSTYPE t1, NMSTYPE t2, NMSTYPE m0, NMSTYPE m1, NMSTYPE m2, NMSTYPE b0, NMSTYPE b1, NMSTYPE b2)
Definition: xf_ocv_ref.hpp:446
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OCVMaxSuppression2()

void OCVMaxSuppression2 ( cv::Mat &  src,
cv::Mat &  dst 
)

Definition at line 48 of file xf_ocv_ref.hpp.

48  {
49  int i, j, k;
50  int ii, jj;
51  NMSTYPE t1[5], t2[5];
52  NMSTYPE m1[5];
53  NMSTYPE b1[5], b2[5];
54  bool result;
55 
56  /* Process zeroth row */
57  i = 0;
58  for (j = 0; j < src.cols; j++) {
59  if (j < 2) {
60  for (k = 0; k < 5; k++) {
61  t1[k] = 0;
62  }
63  for (k = 0; k < 5; k++) {
64  t2[k] = 0;
65  }
66  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
67  if (jj >= 0)
68  m1[k] = src.at<NMSTYPE>(ii, jj);
69  else
70  m1[k] = 0;
71  }
72  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
73  if (jj >= 0)
74  b1[k] = src.at<NMSTYPE>(ii, jj);
75  else
76  b1[k] = 0;
77  }
78  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
79  if (jj >= 0)
80  b2[k] = src.at<NMSTYPE>(ii, jj);
81  else
82  b2[k] = 0;
83  }
84  } else if ((j >= 2) && (j < src.cols - 2)) {
85  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
86  t1[k] = 0;
87  }
88  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
89  t2[k] = 0;
90  }
91  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
92  m1[k] = src.at<NMSTYPE>(ii, jj);
93  }
94  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
95  b1[k] = src.at<NMSTYPE>(ii, jj);
96  }
97  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
98  b2[k] = src.at<NMSTYPE>(ii, jj);
99  }
100  } else if (j >= src.cols - 2) {
101  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
102  t1[k] = 0;
103  }
104  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
105  t2[k] = 0;
106  }
107  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
108  if (jj < src.cols)
109  m1[k] = src.at<NMSTYPE>(ii, jj);
110  else
111  m1[k] = 0;
112  }
113  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
114  if (jj < src.cols)
115  b1[k] = src.at<NMSTYPE>(ii, jj);
116  else
117  b1[k] = 0;
118  }
119  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
120  if (jj < src.cols)
121  b2[k] = src.at<NMSTYPE>(ii, jj);
122  else
123  b2[k] = 0;
124  }
125  }
126  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
127  dst.at<uchar>(i, j) = result ? 255 : 0;
128  }
129  /* Process second row */
130  i = 1;
131  for (j = 0; j < src.cols; j++) {
132  if (j < 2) {
133  for (k = 0; k < 5; k++) {
134  t1[k] = 0;
135  }
136  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
137  if (jj >= 0)
138  t2[k] = src.at<NMSTYPE>(ii, jj);
139  else
140  t2[k] = 0;
141  }
142  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
143  if (jj >= 0)
144  m1[k] = src.at<NMSTYPE>(ii, jj);
145  else
146  m1[k] = 0;
147  }
148  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
149  if (jj >= 0)
150  b1[k] = src.at<NMSTYPE>(ii, jj);
151  else
152  b1[k] = 0;
153  }
154  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
155  if (jj >= 0)
156  b2[k] = src.at<NMSTYPE>(ii, jj);
157  else
158  b2[k] = 0;
159  }
160  } else if ((j >= 2) && (j < src.cols - 2)) {
161  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
162  t1[k] = 0;
163  }
164  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
165  t2[k] = src.at<NMSTYPE>(ii, jj);
166  }
167  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
168  m1[k] = src.at<NMSTYPE>(ii, jj);
169  }
170  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
171  b1[k] = src.at<NMSTYPE>(ii, jj);
172  }
173  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
174  b2[k] = src.at<NMSTYPE>(ii, jj);
175  }
176  } else if (j >= src.cols - 2) {
177  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
178  t1[k] = 0;
179  }
180  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
181  t2[k] = 0;
182  }
183  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
184  if (jj < src.cols)
185  m1[k] = src.at<NMSTYPE>(ii, jj);
186  else
187  m1[k] = 0;
188  }
189  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
190  if (jj < src.cols)
191  b1[k] = src.at<NMSTYPE>(ii, jj);
192  else
193  b1[k] = 0;
194  }
195  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
196  if (jj < src.cols)
197  b2[k] = src.at<NMSTYPE>(ii, jj);
198  else
199  b2[k] = 0;
200  }
201  }
202  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
203  dst.at<uchar>(i, j) = result ? 255 : 0;
204  }
205 
206  for (i = 2; i < src.rows - 2; i++) {
207  for (j = 0; j < src.cols; j++) {
208  if (j < 2) {
209  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
210  if (jj >= 0)
211  t1[k] = src.at<NMSTYPE>(ii, jj);
212  else
213  t1[k] = 0;
214  }
215  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
216  if (jj >= 0)
217  t2[k] = src.at<NMSTYPE>(ii, jj);
218  else
219  t2[k] = 0;
220  }
221  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
222  if (jj >= 0)
223  m1[k] = src.at<NMSTYPE>(ii, jj);
224  else
225  m1[k] = 0;
226  }
227  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
228  if (jj >= 0)
229  b1[k] = src.at<NMSTYPE>(ii, jj);
230  else
231  b1[k] = 0;
232  }
233  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
234  if (jj >= 0)
235  b2[k] = src.at<NMSTYPE>(ii, jj);
236  else
237  b2[k] = 0;
238  }
239  } else if ((j >= 2) && (j < src.cols - 2)) {
240  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
241  t1[k] = src.at<NMSTYPE>(ii, jj);
242  }
243  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
244  t2[k] = src.at<NMSTYPE>(ii, jj);
245  }
246  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
247  m1[k] = src.at<NMSTYPE>(ii, jj);
248  }
249  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
250  b1[k] = src.at<NMSTYPE>(ii, jj);
251  }
252  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
253  b2[k] = src.at<NMSTYPE>(ii, jj);
254  }
255  } else if (j >= src.cols - 2) {
256  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
257  if (jj < src.cols)
258  t1[k] = src.at<NMSTYPE>(ii, jj);
259  else
260  t1[k] = 0;
261  }
262  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
263  if (jj < src.cols)
264  t2[k] = src.at<NMSTYPE>(ii, jj);
265  else
266  t2[k] = 0;
267  }
268  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
269  if (jj < src.cols)
270  m1[k] = src.at<NMSTYPE>(ii, jj);
271  else
272  m1[k] = 0;
273  }
274  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
275  if (jj < src.cols)
276  b1[k] = src.at<NMSTYPE>(ii, jj);
277  else
278  b1[k] = 0;
279  }
280  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
281  if (jj < src.cols)
282  b2[k] = src.at<NMSTYPE>(ii, jj);
283  else
284  b2[k] = 0;
285  }
286  }
287 
288  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
289  dst.at<uchar>(i, j) = result ? 255 : 0;
290  }
291  }
292  /* Process zeroth row */
293  i = src.rows - 2;
294  for (j = 0; j < src.cols; j++) {
295  if (j < 2) {
296  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
297  if (jj >= 0)
298  t1[k] = src.at<NMSTYPE>(ii, jj);
299  else
300  t1[k] = 0;
301  }
302  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
303  if (jj >= 0)
304  t2[k] = src.at<NMSTYPE>(ii, jj);
305  else
306  t2[k] = 0;
307  }
308  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
309  if (jj >= 0)
310  m1[k] = src.at<NMSTYPE>(ii, jj);
311  else
312  m1[k] = 0;
313  }
314  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
315  if (jj >= 0)
316  b1[k] = src.at<NMSTYPE>(ii, jj);
317  else
318  b1[k] = 0;
319  }
320  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
321  b2[k] = 0;
322  }
323  } else if ((j >= 2) && (j < src.cols - 2)) {
324  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
325  t1[k] = src.at<NMSTYPE>(ii, jj);
326  }
327  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
328  t2[k] = src.at<NMSTYPE>(ii, jj);
329  }
330  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
331  m1[k] = src.at<NMSTYPE>(ii, jj);
332  }
333  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
334  b1[k] = src.at<NMSTYPE>(ii, jj);
335  }
336  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
337  b2[k] = 0;
338  }
339  } else if (j >= src.cols - 2) {
340  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
341  if (jj < src.cols)
342  t1[k] = src.at<NMSTYPE>(ii, jj);
343  else
344  t1[k] = 0;
345  }
346  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
347  if (jj < src.cols)
348  t2[k] = src.at<NMSTYPE>(ii, jj);
349  else
350  t2[k] = 0;
351  }
352  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
353  if (jj < src.cols)
354  m1[k] = src.at<NMSTYPE>(ii, jj);
355  else
356  m1[k] = 0;
357  }
358  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
359  if (jj < src.cols)
360  b1[k] = src.at<NMSTYPE>(ii, jj);
361  else
362  b1[k] = 0;
363  }
364  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
365  b2[k] = 0;
366  }
367  }
368  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
369  dst.at<uchar>(i, j) = result ? 255 : 0;
370  }
371  /* Process second row */
372  i = src.rows - 1;
373  for (j = 0; j < src.cols; j++) {
374  if (j < 2) {
375  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
376  if (jj >= 0)
377  t1[k] = src.at<NMSTYPE>(ii, jj);
378  else
379  t1[k] = 0;
380  }
381  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
382  if (jj >= 0)
383  t2[k] = src.at<NMSTYPE>(ii, jj);
384  else
385  t2[k] = 0;
386  }
387  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
388  if (jj >= 0)
389  m1[k] = src.at<NMSTYPE>(ii, jj);
390  else
391  m1[k] = 0;
392  }
393  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
394  b1[k] = 0;
395  }
396  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
397  b2[k] = 0;
398  }
399  } else if ((j >= 2) && (j < src.cols - 2)) {
400  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
401  t1[k] = src.at<NMSTYPE>(ii, jj);
402  }
403  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
404  t2[k] = src.at<NMSTYPE>(ii, jj);
405  }
406  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
407  m1[k] = src.at<NMSTYPE>(ii, jj);
408  }
409  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
410  b1[k] = 0;
411  }
412  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
413  b2[k] = 0;
414  }
415  } else if (j >= src.cols - 2) {
416  for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
417  if (jj < src.cols)
418  t1[k] = src.at<NMSTYPE>(ii, jj);
419  else
420  t1[k] = 0;
421  }
422  for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
423  if (jj < src.cols)
424  t2[k] = src.at<NMSTYPE>(ii, jj);
425  else
426  t2[k] = 0;
427  }
428  for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
429  if (jj < src.cols)
430  m1[k] = src.at<NMSTYPE>(ii, jj);
431  else
432  m1[k] = 0;
433  }
434  for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
435  b1[k] = 0;
436  }
437  for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
438  b2[k] = 0;
439  }
440  }
441  result = OCVFindMaximum2(t1, t2, m1, b1, b2);
442  dst.at<uchar>(i, j) = result ? 255 : 0;
443  }
444 }
bool OCVFindMaximum2(NMSTYPE *t1, NMSTYPE *t2, NMSTYPE *m1, NMSTYPE *b1, NMSTYPE *b2)
Definition: xf_ocv_ref.hpp:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ siUdp_meta()

stream<NetworkMetaStream> siUdp_meta ( "siUdp_meta"  )
Here is the caller graph for this function:

◆ soUdp_meta()

stream<NetworkMetaStream> soUdp_meta ( "soUdp_meta"  )
Here is the caller graph for this function:

◆ sSHL_Uaf_Data()

stream<UdpWord> sSHL_Uaf_Data ( "sSHL_Uaf_Data"  )
Here is the caller graph for this function:

◆ stepDut()

void stepDut ( )

Run a single iteration of the DUT model.

Returns
Nothing.

Definition at line 82 of file test_gammacorrection.cpp.

82  {
88  simCnt++;
89  printf("[%4.4d] STEP DUT \n", simCnt);
90 }
void gammacorrection(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siSHL_This_Data, stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports)
Main process of the Gammacorrection Application directives.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sUAF_Shl_Data()

stream<UdpWord> sUAF_Shl_Data ( "sUAF_Shl_Data"  )
Here is the caller graph for this function:

Variable Documentation

◆ cluster_size

ap_uint<32> cluster_size

Definition at line 70 of file test_gammacorrection.cpp.

◆ node_rank

ap_uint<32> node_rank

Definition at line 69 of file test_gammacorrection.cpp.

◆ piSHL_This_MmioCaptPktEn

ap_uint<1> piSHL_This_MmioCaptPktEn

Definition at line 59 of file test_gammacorrection.cpp.

◆ piSHL_This_MmioPostPktEn

ap_uint<1> piSHL_This_MmioPostPktEn

Definition at line 58 of file test_gammacorrection.cpp.

◆ s_udp_rx_ports

ap_uint<32> s_udp_rx_ports = 0x0

Definition at line 66 of file test_gammacorrection.cpp.

◆ simCnt

int simCnt

Definition at line 75 of file test_gammacorrection.cpp.