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

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

Collaboration diagram for Harris:

Modules

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

Files

file  config.h
 The configuration of a Harris Example application (UDP or TCP)
 
file  harris_host.cpp
 Harris userspace application for cF (x86, ppc64).
 
file  xf_harris_config.h
 The Harris configuration header.
 
file  xf_harris_config.h
 The Harris configuration header.
 

Macros

#define CEIL(a, b)   (((a) + (b-1)) / (b))
 
#define FRAME_HEIGHT   16
 
#define FRAME_WIDTH   16
 
#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 FRAME_TOTAL   FRAME_HEIGHT * FRAME_WIDTH
 
#define TOT_TRANSFERS   CEIL(FRAME_TOTAL, PACK_SIZE)
 
#define tcp   0
 
#define udp   1
 
#define PY_WRAP_HARRIS_NUMPI   0
 
#define PY_WRAP_HARRIS_FILENAME   1
 
#define WIDTH   FRAME_WIDTH
 
#define HEIGHT   FRAME_HEIGHT
 
#define IMGSIZE   WIDTH * HEIGHT
 
#define IMG_PACKETS   IMGSIZE/(INPUT_PTR_WIDTH/8)
 
#define NPC1   XF_NPPC1
 
#define IN_TYPE   ap_uint<8>
 
#define NPC1   XF_NPPC1
 
#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 IN_TYPE   XF_8UC1
 
#define OUT_TYPE   XF_8UC1
 

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...
 
void markPointsOnImage (Mat &imgOutput, Mat &in_img, Mat &out_img, vector< Point > &hw_points)
 Mark the points found by Harris into the image. More...
 
int main (int argc, char *argv[])
 
void gammacorrection_accel (xf::cv::Mat< ap_uint< 8 >, FRAME_HEIGHT, FRAME_WIDTH, XF_NPPC1 > &imgInput1, xf::cv::Mat< OUT_TYPE, FRAME_HEIGHT, FRAME_WIDTH, XF_NPPC1 > &imgOutput, float gammaval)
 
void cornerGammacorrectionAccelStream (hls::stream< ap_axiu< INPUT_PTR_WIDTH, 0, 0, 0 > > &img_in_axi_stream, hls::stream< ap_axiu< INPUT_PTR_WIDTH, 0, 0, 0 > > &img_out_axi_stream, float gammaval)
 
void harris_accel (xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &_src, xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &_dst, unsigned short Thresh, unsigned short k)
 Top-level accelerated function of the Harris Application with xf::cv I/F. More...
 
void cornerHarrisAccelArray (ap_uint< 8 > *img_inp, ap_uint< 64 > *img_out, int rows, int cols, int threshold, int k)
 Top-level accelerated function of the Harris Application with array I/F. More...
 
void cornerHarrisAccelStream (hls::stream< ap_uint< 8 >> &img_in_axi_stream, hls::stream< ap_uint< 64 >> &img_out_axi_stream, int rows, int cols, int threshold, int k)
 Top-level accelerated function of the Harris Application with array I/F. More...
 
void fakeCornerHarrisAccelStream (hls::stream< ap_axiu< 8, 0, 0, 0 > > &img_in_axi_stream, hls::stream< ap_axiu< 64, 0, 0, 0 > > &img_out_axi_stream, unsigned int min_rx_loops, unsigned int min_tx_loops)
 
void cornerHarrisAccelMem (membus_t *img_inp, membus_t *img_out, int rows, int cols, int threshold, int k)
 Top-level accelerated function of the Harris Application with array I/F. More...
 
void gammacorrection_accel (xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &imgInput1, xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &imgOutput, float gammaval)
 

Detailed Description

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

cFDK / cFp / cFp_Zoo / VitisVision : Submodules

Macro Definition Documentation

◆ BITS_PER_10GBITETHRNET_AXI_PACKET

#define BITS_PER_10GBITETHRNET_AXI_PACKET   64

Definition at line 102 of file xf_harris_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 103 of file xf_harris_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 83 of file xf_harris_config.h.

◆ FRAME_HEIGHT

#define FRAME_HEIGHT   16

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 77 of file config.h.

◆ FRAME_WIDTH

#define FRAME_WIDTH   16

The maximum height of frame in pixels

Definition at line 46 of file config.h.

◆ HEIGHT [1/2]

#define HEIGHT   FRAME_HEIGHT

Definition at line 69 of file xf_gammacorrection_config.h.

◆ HEIGHT [2/2]

#define HEIGHT   FRAME_HEIGHT

Definition at line 98 of file xf_harris_config.h.

◆ IMG_PACKETS [1/2]

#define IMG_PACKETS   IMGSIZE/(INPUT_PTR_WIDTH/8)

Definition at line 72 of file xf_gammacorrection_config.h.

◆ IMG_PACKETS [2/2]

#define IMG_PACKETS   IMGSIZE/(BYTES_PER_10GBITETHRNET_AXI_PACKET)

Definition at line 105 of file xf_harris_config.h.

◆ IMGSIZE [1/2]

#define IMGSIZE   WIDTH * HEIGHT

Definition at line 71 of file xf_gammacorrection_config.h.

◆ IMGSIZE [2/2]

#define IMGSIZE   FRAME_TOTAL

Definition at line 100 of file xf_harris_config.h.

◆ IN_TYPE [1/2]

#define IN_TYPE   ap_uint<8>

Definition at line 89 of file xf_gammacorrection_config.h.

◆ IN_TYPE [2/2]

#define IN_TYPE   XF_8UC1

Definition at line 110 of file xf_harris_config.h.

◆ INPUT_PTR_WIDTH

#define INPUT_PTR_WIDTH   8

Definition at line 84 of file xf_harris_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 107 of file xf_harris_config.h.

◆ MIN_TX_LOOPS

Definition at line 108 of file xf_harris_config.h.

◆ NET_TYPE

#define NET_TYPE   udp

The network socket type: tcp or udp

Definition at line 73 of file config.h.

◆ NPC1 [1/2]

#define NPC1   XF_NPPC1

Definition at line 75 of file xf_gammacorrection_config.h.

◆ NPC1 [2/2]

#define NPC1   XF_NPPC1

Definition at line 76 of file xf_harris_config.h.

◆ NPIX

#define NPIX   XF_NPPC1

Definition at line 94 of file xf_harris_config.h.

◆ OUT_TYPE

#define OUT_TYPE   XF_8UC1

Definition at line 111 of file xf_harris_config.h.

◆ OUTPUT_PTR_WIDTH

#define OUTPUT_PTR_WIDTH   64

Definition at line 85 of file xf_harris_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.

◆ PY_WRAP_HARRIS_FILENAME

#define PY_WRAP_HARRIS_FILENAME   1

Definition at line 86 of file config.h.

◆ PY_WRAP_HARRIS_NUMPI

#define PY_WRAP_HARRIS_NUMPI   0

Definition at line 85 of file config.h.

◆ tcp

#define tcp   0

Definition at line 82 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 80 of file config.h.

◆ udp

#define udp   1

Definition at line 83 of file config.h.

◆ WIDTH [1/2]

#define WIDTH   FRAME_WIDTH

Definition at line 68 of file xf_gammacorrection_config.h.

◆ WIDTH [2/2]

#define WIDTH   FRAME_WIDTH

Definition at line 97 of file xf_harris_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

◆ cornerGammacorrectionAccelStream()

void cornerGammacorrectionAccelStream ( hls::stream< ap_axiu< INPUT_PTR_WIDTH, 0, 0, 0 > > &  img_in_axi_stream,
hls::stream< ap_axiu< INPUT_PTR_WIDTH, 0, 0, 0 > > &  img_out_axi_stream,
float  gammaval 
)

◆ cornerHarrisAccelArray()

void cornerHarrisAccelArray ( ap_uint< 8 > *  img_inp,
ap_uint< 64 > *  img_out,
int  rows,
int  cols,
int  threshold,
int  k 
)

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

Returns
Nothing.

Definition at line 58 of file xf_harris_accel.cpp.

59  {
60 // clang-format off
61 /* #pragma HLS INTERFACE m_axi port=img_inp offset=slave bundle=gmem1
62  #pragma HLS INTERFACE m_axi port=img_out offset=slave bundle=gmem2
63 
64  #pragma HLS INTERFACE s_axilite port=rows bundle=control
65  #pragma HLS INTERFACE s_axilite port=cols bundle=control
66  #pragma HLS INTERFACE s_axilite port=threshold bundle=control
67  #pragma HLS INTERFACE s_axilite port=k bundle=control
68  #pragma HLS INTERFACE s_axilite port=return bundle=control
69  // clang-format on
70 */
71  const int pROWS = HEIGHT;
72  const int pCOLS = WIDTH;
73  const int pNPC1 = NPIX;
74 
75  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX> in_mat(rows, cols);
76 // clang-format off
77  #pragma HLS stream variable=in_mat.data depth=2
78  // clang-format on
79 
80  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX> out_mat(rows, cols);
81 // clang-format off
82  #pragma HLS stream variable=out_mat.data depth=2
83 // clang-format on
84 
85 // clang-format off
86  #pragma HLS DATAFLOW
87  // clang-format on
88  xf::cv::Array2xfMat<INPUT_PTR_WIDTH, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_inp, in_mat);
89  xf::cv::cornerHarris<FILTER_WIDTH, BLOCK_WIDTH, NMS_RADIUS, XF_8UC1, HEIGHT, WIDTH, NPIX, XF_USE_URAM>(
90  in_mat, out_mat, threshold, k);
91  xf::cv::xfMat2Array<OUTPUT_PTR_WIDTH, XF_8UC1, HEIGHT, WIDTH, NPIX>(out_mat, img_out);
92 }
#define WIDTH
#define NPIX
#define HEIGHT
Here is the caller graph for this function:

◆ cornerHarrisAccelMem()

void cornerHarrisAccelMem ( membus_t img_inp,
membus_t img_out,
int  rows,
int  cols,
int  threshold,
int  k 
)

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

Returns
Nothing.

Definition at line 216 of file xf_harris_accel.cpp.

218  {
219  // clang-format on
220  #pragma HLS INLINE off
221 
222  const int pROWS = HEIGHT;
223  const int pCOLS = WIDTH;
224  const int pNPC1 = NPIX;
225 
226  xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, NPIX> in_mat(rows, cols);
227  // clang-format off
228  #pragma HLS stream variable=in_mat.data depth=2
229  // clang-format on
230 
231  #ifndef FAKE_Harris
232  xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPIX> out_mat(rows, cols);
233  // clang-format off
234  #pragma HLS stream variable=out_mat.data depth=2
235  // clang-format on
236  #endif
237 
238  // clang-format off
239  #pragma HLS DATAFLOW
240  // clang-format on
241 
242  // Feed a cv matrix from ddr memory
243  xf::cv::Array2xfMat<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_inp, in_mat);
244 
245  #ifdef FAKE_Harris
246 
247  // Feed ddr memory from a cv matrix
248  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(in_mat, img_out);
249  #else
250 
251  xf::cv::cornerHarris<FILTER_WIDTH, BLOCK_WIDTH, NMS_RADIUS, IN_TYPE, HEIGHT, WIDTH, NPIX, XF_USE_URAM>(
252  in_mat, out_mat, threshold, k);
253 
254  // Feed ddr memory from a cv matrix
255  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(out_mat, img_out);
256 
257  #endif
258 
259 
260 }
Here is the caller graph for this function:

◆ cornerHarrisAccelStream()

void cornerHarrisAccelStream ( hls::stream< ap_uint< 8 >> &  img_in_axi_stream,
hls::stream< ap_uint< 64 >> &  img_out_axi_stream,
int  rows,
int  cols,
int  threshold,
int  k 
)

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

Returns
Nothing.

Definition at line 106 of file xf_harris_accel.cpp.

111  {
112  // clang-format on
113  #pragma HLS INLINE off
114 
115  const int pROWS = HEIGHT;
116  const int pCOLS = WIDTH;
117  const int pNPC1 = NPIX;
118 
119  xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, NPIX> in_mat(rows, cols);
120  // clang-format off
121  #pragma HLS stream variable=in_mat.data depth=2
122  // clang-format on
123 
124  xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPIX> out_mat(rows, cols);
125  // clang-format off
126  #pragma HLS stream variable=out_mat.data depth=2
127  // clang-format on
128 
129  // clang-format off
130  #pragma HLS DATAFLOW
131  // clang-format on
132 
133  accel_utils accel_utils_obj;
134 
135  int dstMat_cols_align_npc = ((in_mat.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
136 
137  accel_utils_obj.hlsStrm2xfMat<INPUT_PTR_WIDTH, IN_TYPE, HEIGHT, WIDTH, NPIX, (HEIGHT * WIDTH) / NPIX>(img_in_axi_stream, in_mat, dstMat_cols_align_npc);
138 
139  //xf::cv::axiStrm2xfMat<INPUT_PTR_WIDTH, IN_TYPE, HEIGHT, WIDTH, NPIX>(
140  // img_in_axi_stream, in_mat);
141 
142  xf::cv::cornerHarris<FILTER_WIDTH, BLOCK_WIDTH, NMS_RADIUS, IN_TYPE, HEIGHT, WIDTH, NPIX, XF_USE_URAM>(
143  in_mat, out_mat, threshold, k);
144 
145  //xf::cv::xfMat2axiStrm<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX>(
146  // out_mat, img_out_axi_stream);
147 
148  int srcMat_cols_align_npc = ((out_mat.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
149 
150  accel_utils_obj.xfMat2hlsStrm<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX, HEIGHT*((WIDTH + NPIX - 1) / NPIX)>(out_mat, img_out_axi_stream,
151  srcMat_cols_align_npc);
152 
153 
154 }
#define OUT_TYPE
#define IN_TYPE
#define INPUT_PTR_WIDTH
#define OUTPUT_PTR_WIDTH
Here is the caller graph for this function:

◆ delay()

void delay ( unsigned int  mseconds)

Definition at line 51 of file harris_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:

◆ fakeCornerHarrisAccelStream()

void fakeCornerHarrisAccelStream ( hls::stream< ap_axiu< 8, 0, 0, 0 > > &  img_in_axi_stream,
hls::stream< ap_axiu< 64, 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:

◆ gammacorrection_accel() [1/2]

void gammacorrection_accel ( xf::cv::Mat< ap_uint< 8 >, FRAME_HEIGHT, FRAME_WIDTH, XF_NPPC1 > &  imgInput1,
xf::cv::Mat< OUT_TYPE, FRAME_HEIGHT, FRAME_WIDTH, XF_NPPC1 > &  imgOutput,
float  gammaval 
)

◆ gammacorrection_accel() [2/2]

void gammacorrection_accel ( xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &  imgInput1,
xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &  imgOutput,
float  gammaval 
)

◆ harris_accel()

void harris_accel ( xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &  _src,
xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &  _dst,
unsigned short  Thresh,
unsigned short  k 
)

Top-level accelerated function of the Harris Application with xf::cv I/F.

Returns
Nothing.

Definition at line 41 of file xf_harris_accel.cpp.

44  {
45  xf::cv::cornerHarris<FILTER_WIDTH, BLOCK_WIDTH, NMS_RADIUS, XF_8UC1, HEIGHT, WIDTH, NPIX, XF_USE_URAM>(_src, _dst,
46  Thresh, k);
47 }
Here is the caller graph for this function:

◆ main()

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

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

Returns
O on success, 1 on fail

Definition at line 141 of file harris_host.cpp.

141  {
142  if ((argc < 3) || (argc > 4)) { // Test for correct number of arguments
143  cerr << "Usage: " << argv[0] << " <Server> <Server Port> <optional input image>\n";
144  exit(1);
145  }
146 #endif // PY_WRAP
147 
148  //------------------------------------------------------
149  //-- STEP-1 : Socket and variables definition
150  //------------------------------------------------------
151 
152  #ifndef PY_WRAP
153  assert ((argc == 3) || (argc == 4));
154  string s_servAddress = argv[1]; // First arg: server address
155  char *s_servPort = argv[2];
156  #endif
157 
158  string servAddress = s_servAddress;
159  unsigned short servPort;
160  bool net_type = NET_TYPE;
161  if (net_type == udp) {
162  servPort = Socket::resolveService(s_servPort, "udp");
163  }
164  else if (net_type == tcp) {
165  servPort = atoi(s_servPort);
166  }
167  else {
168  cout << "ERROR: Invalid type of socket type provided: " << net_type << " Choosed one of (tcp=0 or udp=1)" << endl;
169  }
170 
171  unsigned char buffer[BUF_LEN]; // Buffer for echo string
172  unsigned int recvMsgSize; // Size of received message
173  string input_string;
174 #ifdef INPUT_FROM_CAMERA
175  int input_num;
176 #ifdef PY_WRAP
177 #if PY_WRAP == PY_WRAP_HARRIS_FILENAME
178  input_num = atoi(input_str);
179  input_string = "./cam"+to_string(input_num);
180 #endif // PY_WRAP == PY_WRAP_HARRIS_FILENAME
181 #else // !PY_WRAP
182  if (argc == 3) {
183  input_num = 0;
184  }
185  else if (argc == 4) {
186  input_num = atoi(argv[3]);
187  }
188  input_string = "./cam"+to_string(input_num);
189 #endif // PY_WRAP
190 #else // !INPUT_FROM_CAMERA
191 #ifdef PY_WRAP
192 #if PY_WRAP == PY_WRAP_HARRIS_FILENAME
193  input_string.assign(input_str);
194 #endif // PY_WRAP == PY_WRAP_HARRIS_FILENAME
195 #else // !PY_WRAP
196  if (argc == 3) {
197  // Give a default image
198  input_string.assign("../../../../../../ROLE/vision/hls/harris/test/8x8.png");
199  }
200  else if (argc == 4) {
201  input_string.assign(argv[3]);
202  }
203 #endif // PY_WRAP
204 #endif // INPUT_FROM_CAMERA
205 
206 
207 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
208 
209 
210  float Th;
211  if (FILTER_WIDTH == 3) {
212  Th = 30532960.00;
213  } else if (FILTER_WIDTH == 5) {
214  Th = 902753878016.0;
215  } else if (FILTER_WIDTH == 7) {
216  Th = 41151168289701888.000000;
217  }
218  string out_img_file, out_points_file;
219  string out_video_file, out_video_points_file;
220  // Define the codec and create VideoWriter object.The output is stored in 'outcpp.avi' file.
221  //#ifdef PY_WRAP
222  //out_video_file.assign(output_str);
223  //#else // !PY_WRAP
224  out_video_file.assign(input_string);
225  out_video_file += "_fpga_video_out.avi";
226  out_video_points_file.assign(input_string);
227  out_video_points_file += "_fpga_video_points_out.avi";
228  //#endif // PY_WRAP
229 #if CV_MAJOR_VERSION < 4
230  VideoWriter video(out_video_file,CV_FOURCC('M','J','P','G'),10, Size(FRAME_WIDTH,FRAME_HEIGHT));
231  VideoWriter videop(out_video_points_file,CV_FOURCC('M','J','P','G'),10, Size(FRAME_WIDTH,FRAME_HEIGHT));
232 #else
233  VideoWriter video(out_video_file,cv::VideoWriter::fourcc('M','J','P','G'),10, Size(FRAME_WIDTH,FRAME_HEIGHT));
234  VideoWriter videop(out_video_points_file,cv::VideoWriter::fourcc('M','J','P','G'),10, Size(FRAME_WIDTH,FRAME_HEIGHT));
235 #endif
236 
237 #endif // #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
238 
239  print_cFpZoo();
240 
241  try {
242 
243  //------------------------------------------------------
244  //-- STEP-2 : Initialize socket connection
245  //------------------------------------------------------
246  #if NET_TYPE == udp
247  #ifndef TB_SIM_CFP_VITIS
248  UDPSocket sock(servPort); // NOTE: It is very important to set port here in order to call
249  // bind() in the UDPSocket constructor
250  #else // TB_SIM_CFP_VITIS
251  UDPSocket sock; // NOTE: In HOST TB the port is already binded by harris_host_fwd_tb.cpp
252  #endif // TB_SIM_CFP_VITIS
253  #else // tcp
254  TCPSocket sock(servAddress, servPort);
255  #endif // udp/tcp
256 
257 
258 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
259 
260 
261  //------------------------------------------------------------------------------------
262  //-- STEP-3 : Initialize a Greyscale OpenCV Mat either from image or from video/camera
263  //------------------------------------------------------------------------------------
264  Mat frame, send(FRAME_WIDTH, FRAME_HEIGHT, INPUT_TYPE_HOST, Scalar(0)), ocv_out_img;
265  vector < uchar > encoded;
266 
267  #ifdef INPUT_FROM_CAMERA
268 
269  VideoCapture cap(input_num); // Grab the camera
270  if (!cap.isOpened()) {
271  cerr << "OpenCV Failed to open camera " + input_num << endl;
272  exit(1);
273  }
274 
275  #else // INPUT_FROM_CAMERA
276 
277  VideoCapture cap(input_string); // Grab the image
278  if (!cap.isOpened()) {
279  cerr << "OpenCV Failed to open file " + input_string << endl;
280  exit(1);
281  }
282 
283  #endif // INPUT_FROM_CAMERA
284 
285  //frame = cv::imread(argv[3], cv::IMREAD_GRAYSCALE); // reading in the image in grey scale
286  unsigned int num_frame = 0;
287 
288  while (1) {
289  clock_t start_cycle_main = clock();
290  cap >> frame;
291  if (frame.empty()) break; // if input is an image, the loop will be executed once
292  if(frame.size().width==0) continue; //simple integrity check; skip erroneous data...
293  cout << " ___________________________________________________________________ " << endl;
294  cout << "/ \\" << endl;
295  cout << "INFO: Frame # " << ++num_frame << endl;
296 #if CV_MAJOR_VERSION < 4
297  cv::cvtColor(frame,frame,CV_BGR2GRAY);
298 #else
299  cv::cvtColor(frame,frame,cv::COLOR_BGR2GRAY);
300 #endif
301  resizeCropSquare(frame, send, Size(FRAME_WIDTH, FRAME_HEIGHT), INTER_LINEAR);
302  if ((frame.cols != FRAME_WIDTH) || (frame.rows != FRAME_HEIGHT)) {
303  cout << "WARNING: Input frame was resized from " << frame.cols << "x"
304  << frame.rows << " to " << send.cols << "x" << send.rows << endl;
305  }
306  assert(send.total() == FRAME_WIDTH * FRAME_HEIGHT);
307  // Ensure that the selection of MTU is a multiple of 8 (Bytes per transaction)
308  assert(PACK_SIZE % 8 == 0);
309 
310 #ifdef SHOW_WINDOWS
311 
312  namedWindow("host_send", CV_WINDOW_NORMAL);
313  imshow("host_send", send);
314 
315 #endif // SHOW_WINDOWS
316 
317  // Ensure that the send Mat is in continuous memory space. Typically, imread or resize
318  // will return such a continuous Mat, but we should check it.
319  assert(send.isContinuous());
320 
321  unsigned int send_total = send.total();
322  unsigned int send_channels = send.channels();
323 
324 #else // PY_WRAP == PY_WRAP_HARRIS_NUMPI
325 
326  unsigned int send_total = (unsigned int)total_size;
327  unsigned int send_channels = 1; // FIXME: It is ok only for 1-d array, i.e. CV_8UC1
328  unsigned char * sendarr = input_img;
329 #endif // #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
330 
331 
332 
333  unsigned int total_pack = 1 + (send_total * send_channels - 1) / PACK_SIZE;
334  unsigned int total_bytes = total_pack * PACK_SIZE;
335  unsigned int bytes_in_last_pack = send_total * send_channels - (total_pack - 1) * PACK_SIZE;
336  assert(total_pack == TOT_TRANSFERS);
337 
338  cout << "INFO: FPGA destination : " << servAddress << ":" << servPort << endl;
339  cout << "INFO: Network socket : " << ((NET_TYPE == tcp) ? "TCP" : "UDP") << endl;
340  cout << "INFO: Total packets to send/receive = " << total_pack << endl;
341  cout << "INFO: Total bytes to send/receive = " << send_total * send_channels << endl;
342  cout << "INFO: Total bytes in " << total_pack << " packets = " << total_bytes << endl;
343  cout << "INFO: Bytes in last packet = " << bytes_in_last_pack << endl;
344  cout << "INFO: Packet size (custom MTU) = " << PACK_SIZE << endl;
345 
346 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
347 
348  //--------------------------------------------------------
349  //-- STEP-4 : RUN HARRIS DETECTOR FROM OpenCV LIBRARY (SW)
350  //--------------------------------------------------------
351  clock_t start_cycle_harris_sw = clock();
352  ocv_out_img.create(send.rows, send.cols, INPUT_TYPE_HOST); // create memory for opencv output image
353  ocv_ref(send, ocv_out_img, Th);
354  clock_t end_cycle_harris_sw = clock();
355  double duration_harris_sw = (end_cycle_harris_sw - start_cycle_harris_sw) /
356  (double) CLOCKS_PER_SEC;
357  cout << "INFO: SW exec. time:" << duration_harris_sw << " seconds" << endl;
358  cout << "INFO: Effective FPS SW:" << (1 / duration_harris_sw) << " \tkbps:" <<
359  (PACK_SIZE * total_pack / duration_harris_sw / 1024 * 8) << endl;
360 
361  //------------------------------------------------------
362  //-- STEP-5 : RUN HARRIS DETECTOR FROM cF (HW)
363  //------------------------------------------------------
364 
365  //------------------------------------------------------
366  //-- STEP-5.1 : Preparation
367  //------------------------------------------------------
368 
369  // Anchor a pointer on cvMat raw data
370  unsigned char * sendarr = send.isContinuous()? send.data: send.clone().data;
371 
372  clock_t start_cycle_harris_hw = clock();
373 
374 #endif // !PY_WRAP_HARRIS_NUMPI
375 
376 
377  //------------------------------------------------------
378  //-- STEP-5.2 : TX Loop
379  //------------------------------------------------------
380  clock_t last_cycle_tx = clock();
381  unsigned int sending_now = PACK_SIZE;
382  for (unsigned int i = 0; i < total_pack; i++) {
383  if ( i == total_pack - 1 ) {
384  sending_now = bytes_in_last_pack;
385  }
386  #if NET_TYPE == udp
387  sock.sendTo( & sendarr[i * PACK_SIZE], sending_now, servAddress, servPort);
388  #else
389  sock.send( & sendarr[i * PACK_SIZE], sending_now);
390  #endif
391  //delay(1);
392  }
393 
394  clock_t next_cycle_tx = clock();
395  double duration_tx = (next_cycle_tx - last_cycle_tx) / (double) CLOCKS_PER_SEC;
396  cout << "INFO: Effective FPS TX:" << (1 / duration_tx) << " \tkbps:" << (PACK_SIZE *
397  total_pack / duration_tx / 1024 * 8) << endl;
398  last_cycle_tx = next_cycle_tx;
399 
400 
401  //------------------------------------------------------
402  //-- STEP-5.3 : RX Loop
403  //------------------------------------------------------
404 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
405  clock_t last_cycle_rx = clock();
406 #endif
407  unsigned int receiving_now = PACK_SIZE;
408  cout << "INFO: Expecting length of packs:" << total_pack << " from " << servAddress << ":" << servPort << endl;
409  unsigned char * longbuf = new unsigned char[PACK_SIZE * total_pack];
410  for (unsigned int i = 0; i < send_total; ) {
411  //cout << "DEBUG: " << i << endl;
412  //if ( i == total_pack - 1 ) {
413  // receiving_now = bytes_in_last_pack;
414  //}
415  #if NET_TYPE == udp
416  recvMsgSize = sock.recvFrom(buffer, BUF_LEN, servAddress, servPort);
417  #else
418  recvMsgSize = sock.recv(buffer, BUF_LEN);
419  #endif
420  if (recvMsgSize != receiving_now) {
421  cerr << "WARNING: at i=" << i << " received unexpected size pack:" << recvMsgSize << ". Expected: " <<
422  receiving_now << endl;
423  //continue;
424  }
425  memcpy( & longbuf[i], buffer, recvMsgSize);
426  //cout << "DEBUG: i=" << i << " recvMsgSize=" << recvMsgSize << endl;
427  i += recvMsgSize;
428  }
429 
430  cout << "INFO: Received packet from " << servAddress << ":" << servPort << endl;
431 
432 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
433 
434  frame = cv::Mat(FRAME_HEIGHT, FRAME_WIDTH, INPUT_TYPE_HOST, longbuf); // OR vec.data() instead of ptr
435  if (frame.size().width == 0) {
436  cerr << "receive failure!" << endl;
437  continue;
438 
439  }
440 #ifdef SHOW_WINDOWS
441  namedWindow("host_recv", CV_WINDOW_NORMAL);
442  imshow("host_recv", frame);
443 #endif
444  clock_t next_cycle_rx = clock();
445  double duration_rx = (next_cycle_rx - last_cycle_rx) / (double) CLOCKS_PER_SEC;
446  cout << "INFO: Effective FPS RX:" << (1 / duration_rx) << " \tkbps:" << (PACK_SIZE *
447  total_pack / duration_rx / 1024 * 8) << endl;
448  last_cycle_rx = next_cycle_rx;
449 
450  clock_t end_cycle_harris_hw = next_cycle_rx;
451 
452  double duration_harris_hw = (end_cycle_harris_hw - start_cycle_harris_hw) /
453  (double) CLOCKS_PER_SEC;
454  cout << "INFO: HW exec. time:" << duration_harris_hw << " seconds" << endl;
455  cout << "INFO: Effective FPS HW:" << (1 / duration_harris_hw) << " \tkbps:" <<
456  (PACK_SIZE * total_pack / duration_harris_hw / 1024 * 8) << endl;
457 
458  //------------------------------------------------------
459  //-- STEP-6 : Write output files and show in windows
460  //------------------------------------------------------
461  Mat out_img;
462  out_img = send.clone();
463  vector<Point> hw_points;
464 
465  /* Mark HLS points on the image */
466  markPointsOnImage(frame, send, out_img, hw_points);
467 
468  ostringstream oss;
469  oss << "cFp_Vitis E2E:" << "INFO: Effective FPS HW:" << (1 / duration_harris_hw) <<
470  " \tkbps:" << (PACK_SIZE * total_pack / duration_harris_hw / 1024 * 8);
471  string windowName = "cFp_Vitis End2End"; //oss.str();
472  /*
473  string msg = "cFp_Vitis";
474  Scalar color(255, 0, 0);
475  int fontFace = FONT_HERSHEY_DUPLEX;
476  double fontScale = 0.5;
477  int thickness = 1;
478  putText(out_img,
479  msg, //text
480  Point(10, out_img.rows / 2), //top-left position
481  fontFace,
482  fontScale,
483  color, //font color
484  thickness);
485  */
486 #ifdef SHOW_WINDOWS
487  namedWindow(windowName, CV_WINDOW_NORMAL);
488  imshow(windowName, out_img);
489 #endif
490  //moveWindow(windowName, 0, 0);
491 #ifdef WRITE_OUTPUT_FILE
492  if (num_frame == 1) {
493  out_img_file.assign(input_string);
494  out_img_file += "_fpga_img_out_frame_" + to_string(num_frame) + ".png";
495  out_points_file.assign(input_string);
496  out_points_file += "_fpga_points_out_frame_" + to_string(num_frame) + ".png";
497 #if defined(PY_WRAP) && (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
498 
499  if (!strcpy(output_img_str, &out_img_file[0])) {
500  cerr << "ERROR: Cannot write to output image string." << endl;
501  }
502  if (!strcpy(output_points_str, &out_points_file[0])) {
503  cerr << "ERROR: Cannot write to output points string." << endl;
504  }
505 #endif // defined(PY_WRAP) && (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
506  cout << "INFO: The output image file is stored at : " << out_img_file << endl;
507  cout << "INFO: The output points file is stored at : " << out_points_file << endl;
508  // We save the image received from network after being processed by Harris HW or HOST TB
509  imwrite(out_img_file, out_img);
510  imwrite(out_points_file, frame);
511  }
512  else if (num_frame > 1) {
513  // If the frame is empty, break immediately
514  if (frame.empty()) {
515  break;
516  }
517  cout << "INFO: The output video file is stored at : " << out_video_file << endl;
518  cout << "INFO: The output video -only points- file is stored at : " << out_video_points_file << endl;
519  Mat tovideo, tovideop;
520  if (frame.channels() != 1) {
521  tovideo = out_img;
522  tovideop = frame;
523  }
524  else {
525  cvtColor(out_img, tovideo, COLOR_GRAY2BGR);
526  cvtColor(frame, tovideop, COLOR_GRAY2BGR);
527  }
528  video.write(tovideo);
529  videop.write(tovideop);
530  }
531 #endif // WRITE_OUTPUT_FILE
532  waitKey(FRAME_INTERVAL);
533  double duration_main = (clock() - start_cycle_main) / (double) CLOCKS_PER_SEC;
534  cout << "INFO: Effective FPS E2E:" << (1 / duration_main) << endl;
535  cout << "\\___________________________________________________________________/" << endl
536  << endl;
537  } // while loop
538 
539  // When everything done, release the video capture and write object
540  cap.release();
541  video.release();
542  videop.release();
543 
544  // Closes all the windows
545  destroyAllWindows();
546 
547 #else
548  //output_img = longbuf;
549  memcpy( output_img, longbuf, total_size);
550  delete(longbuf);
551 #endif // defined(PY_WRAP) && (PY_WRAP == PY_WRAP_HARRIS_FILENAME)
552 
553  // Destructor closes the socket
554  } catch (SocketException & e) {
555  cerr << e.what() << endl;
556  exit(1);
557  }
558 
559 #ifndef PY_WRAP
560  return 0;
561 #endif
562 }
cat GET request dos socat stdio tcp
Definition: commands.txt:1
#define FILTER_WIDTH
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
void print_cFpZoo(void)
Definition: harris_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: harris_host.cpp:82
void markPointsOnImage(Mat &imgOutput, Mat &in_img, Mat &out_img, vector< Point > &hw_points)
Mark the points found by Harris into the image.
#define TOT_TRANSFERS
Definition: config.h:70
#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
def send(cFcluster cluster, node_id, data_obj, proto='udp', port=CF_DEFAULT_PORT)
Definition: comm.py:41

◆ markPointsOnImage()

void markPointsOnImage ( Mat &  imgOutput,
Mat &  in_img,
Mat &  out_img,
vector< Point > &  hw_points 
)

Mark the points found by Harris into the image.

Returns
Nothing

Definition at line 101 of file harris_host.cpp.

105 {
106 
107  for (int j = 0; j < imgOutput.rows; j++) {
108  for (int i = 0; i < (imgOutput.cols); i++) {
109  //for CV_8UC1
110  unsigned char pix = imgOutput.at<unsigned char>(j,i); //.read(j * (imgOutput.cols) + i);
111  if (pix != 0) {
112  Point tmp;
113  tmp.x = i;
114  tmp.y = j;
115  if ((tmp.x < in_img.cols) && (tmp.y < in_img.rows) && (j > 0)) {
116  hw_points.push_back(tmp);
117  }
118  short int y, x;
119  y = j;
120  x = i;
121  if (j > 0) circle(out_img, Point(x, y), 2, Scalar(0, 0, 255, 255), 1, 8, 0);
122  }
123  }
124  }
125 }

◆ print_cFpZoo()

void print_cFpZoo ( void  )

Definition at line 57 of file harris_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 harris_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