cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
warp_transform_host.cpp
Go to the documentation of this file.
1 
17 
33 #include <stdio.h>
34 #include <iostream> // For cout and cerr
35 #include <cstdlib> // For atoi()
36 #include <assert.h> // For assert()
37 #include <string> // For to_string
38 #include <string.h> // For memcpy()
39 #include "PracticalSockets.h" // For UDPSocket and SocketException
40 #include "config.h"
41 #include "util.hpp"
42 
43 #if TRANSFORM_TYPE == 1
44 #define TRMAT_DIM2 3
45 #define TRMAT_DIM1 3
46 #else
47 #define TRMAT_DIM2 3
48 #define TRMAT_DIM1 2
49 #endif
50 
51 
52 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_NUMPI)
53 #include "opencv2/opencv.hpp"
54 #include "../../../../../../ROLE/vision/hls/warp_transform/include/xf_ocv_ref.hpp" // For SW reference WarpTransform from OpenCV
55 using namespace cv;
56 #endif
57 
58 using namespace std;
59 
60 void delay(unsigned int mseconds)
61 {
62  clock_t goal = mseconds + clock();
63  while (goal > clock());
64 }
65 
66 void print_cFpZoo(void)
67 {
68  cout << " " << endl;
69  cout << "...build with: " << endl;
70  cout << " ██████╗███████╗██████╗ ███████╗ ██████╗ ██████╗ " << endl;
71  cout << "██╔════╝██╔════╝██╔══██╗ ╚══███╔╝██╔═══██╗██╔═══██╗ " << endl;
72  cout << "██║ █████╗ ██████╔╝ ███╔╝ ██║ ██║██║ ██║ " << endl;
73  cout << "██║ ██╔══╝ ██╔═══╝ ███╔╝ ██║ ██║██║ ██║ " << endl;
74  cout << "╚██████╗██║ ██║███████╗███████╗╚██████╔╝╚██████╔╝ " << endl;
75  cout << " ╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═════╝ ╚═════╝ " << endl;
76  cout << "A cloudFPGA project from IBM ZRL v1.0 " << endl;
77  cout << "Quantitative Finance Monte-Carlo European Pricing Engine " << endl;
78 }
79 
80 
91 void resizeCropSquare(const cv::Mat &input, const cv::Mat &output, const cv::Size &dstSize, int interpolation = INTER_LINEAR)
92 {
93  int h = input.rows;
94  int w = input.cols;
95  int min_size = min(h, w);
96  int x = w/2-min_size/2;
97  int y = h/2-min_size/2;
98  // 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);
99  cv::Mat crop_img = input(Rect(x, y, min_size, min_size));
100  resize(crop_img, output, Size(dstSize.width, dstSize.height), 0, 0, interpolation);
101 }
102 
103 string prepareWarpTransformCommand(unsigned int rows, unsigned int cols, unsigned int channels,float * transform_matrix){
104  string out;
105  unsigned int bytes_per_line = 8;
106  char tx_cmd [bytes_per_line];
107  char img_cmd [bytes_per_line];
108  char value_cmd[bytes_per_line];
109 
110  //init tx and img cmd
111  for (unsigned int k = 0; k < bytes_per_line; k++) {
112  value_cmd[k] = (char)0;
113  if (k != 0) {
114  tx_cmd[k] = (char)0;
115  img_cmd[k] = (char)0;
116  }
117  else {
118  tx_cmd[k] = (char)1;
119  img_cmd[k] = (char)2;
120  }
121  }
122  out = out.append(tx_cmd,bytes_per_line);
123 
124  //dump the even elements of the tx matrix
125  int off = 4;
126  for (int i = 0; i < 8; i++)
127  {
128  memcpy(value_cmd+off, (float*)transform_matrix+i, 4);
129  off += 4;
130  off = off % bytes_per_line;
131  if (i%2 && i!=0)
132  {
133  //dump matrix
134  out = out.append(value_cmd,bytes_per_line);
135  }
136  }
137  //dump last value
138  unsigned int zero_constant = 0;
139  memcpy(value_cmd, (char*)transform_matrix+8, 4);
140  memcpy(value_cmd, (char*)&zero_constant, 4);
141  out = out.append(value_cmd,bytes_per_line);
142  //creating img mat cmd
143  memcpy(img_cmd+6, (char*)&rows, 2);
144  memcpy(img_cmd+4, (char*)&cols, 2);
145  img_cmd[1]=channels;
146  out = out.append(img_cmd,bytes_per_line);
147  return string(out);
148 }
149 
150 
151 
152 #ifdef PY_WRAP
153 #if PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME
154 void warp_transform(char *s_servAddress, char *s_servPort, char *input_str, char *output_img_str, char *output_points_str)
155 #elif PY_WRAP == PY_WRAP_WARPTRANSFORM_NUMPI
156 void warp_transform(int total_size, unsigned char *input_img, int total_size2, unsigned char *output_img, char *s_servAddress, char *s_servPort)
157 #endif // PY_WRAP value
158 {
159 #else // !PY_WRAP
164 int main(int argc, char * argv[]) {
165  if ((argc < 3) || (argc > 4)) { // Test for correct number of arguments
166  cerr << "Usage: " << argv[0] << " <Server> <Server Port> <optional input image>\n";
167  exit(1);
168  }
169 #endif // PY_WRAP
170 
171  //------------------------------------------------------
172  //-- STEP-1 : Socket and variables definition
173  //------------------------------------------------------
174 
175  #ifndef PY_WRAP
176  assert ((argc == 3) || (argc == 4));
177  string s_servAddress = argv[1]; // First arg: server address
178  char *s_servPort = argv[2];
179  #endif
180 
181  string servAddress = s_servAddress;
182  unsigned short servPort;
183  bool net_type = NET_TYPE;
184  if (net_type == udp) {
185  servPort = Socket::resolveService(s_servPort, "udp");
186  }
187  else if (net_type == tcp) {
188  servPort = atoi(s_servPort);
189  }
190  else {
191  cout << "ERROR: Invalid type of socket type provided: " << net_type << " Choosed one of (tcp=0 or udp=1)" << endl;
192  }
193 
194  unsigned char buffer[BUF_LEN]; // Buffer for echo string
195  unsigned int recvMsgSize; // Size of received message
196  string input_string;
197 #ifdef INPUT_FROM_CAMERA
198  int input_num;
199 #ifdef PY_WRAP
200 #if PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME
201  input_num = atoi(input_str);
202  input_string = "./cam"+to_string(input_num);
203 #endif // PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME
204 #else // !PY_WRAP
205  if (argc == 3) {
206  input_num = 0;
207  }
208  else if (argc == 4) {
209  input_num = atoi(argv[3]);
210  }
211  input_string = "./cam"+to_string(input_num);
212 #endif // PY_WRAP
213 #else // !INPUT_FROM_CAMERA
214 #ifdef PY_WRAP
215 #if PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME
216  input_string.assign(input_str);
217 #endif // PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME
218 #else // !PY_WRAP
219  if (argc == 3) {
220  // Give a default image
221  input_string.assign("../../../../../../ROLE/vision/hls/warp_transform/test/8x8.png");
222  }
223  else if (argc == 4) {
224  input_string.assign(argv[3]);
225  }
226 #endif // PY_WRAP
227 #endif // INPUT_FROM_CAMERA
228 
229 
230 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
231 
232  // ksize: aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
233  // int ksize = WINDOW_SIZE ;
235  // float identity_tx_mat [9] = {1,0,0,0,1,0,0,0,0};
236  // float xtranslation_tx_mat [9] = {1,0,2,0,1,0,0,0,0};// 1 0 vx 0 1 vy 000
237  // float ytranslation_tx_mat [9] = {1,0,0,0,1,2,0,0,0};
238  // float reflection_tx_mat [9] = {-1,0,0,0,1,0,0,0,0};
239  // float yscale_tx_mat [9] = {2,0,0,0,1,0,0,0,0}; //cx 0 0 0 cy 0 000
240  // float xscale_tx_mat [9] = {1,0,0,0,2,0,0,0,0};
241  // float rotation_30degree_tx_mat [9] = {0.87,-0.5,0,0.5,0.87,0,0,0,0}; //cos -sin 0 sin cos 0 000
242  // float shearing_tx_mat [9] = {1,0.5,0,0,1,0,0,0,0}; //1 cx 0 cy 1 0 000
243  float transformation_matrix_float [9] = {1.5,0,0,0,1.8,0,0,0,0};
244  cv::Mat transformation_matrix(TRMAT_DIM1, TRMAT_DIM2, CV_32FC1, transformation_matrix_float);
246  string out_img_file;
247  string out_video_file;
248  // Define the codec and create VideoWriter object.The output is stored in 'outcpp.avi' file.
249  //#ifdef PY_WRAP
250  //out_video_file.assign(output_str);
251  //#else // !PY_WRAP
252  out_video_file.assign(input_string);
253  out_video_file += "_fpga_video_out.avi";
254  //#endif // PY_WRAP
255 #if CV_MAJOR_VERSION < 4
256  VideoWriter video(out_video_file,CV_FOURCC('M','J','P','G'),10, Size(FRAME_WIDTH,FRAME_HEIGHT));
257 #else
258  VideoWriter video(out_video_file,cv::VideoWriter::fourcc('M','J','P','G'),10, Size(FRAME_WIDTH,FRAME_HEIGHT));
259 #endif
260 
261 #endif // #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
262 
263  print_cFpZoo();
264 
265  try {
266 
267  //------------------------------------------------------
268  //-- STEP-2 : Initialize socket connection
269  //------------------------------------------------------
270 #if NET_TYPE == udp
271 #ifndef TB_SIM_CFP_VITIS
272  UDPSocket sock(servPort); // NOTE: It is very important to set port here in order to call
273  // bind() in the UDPSocket constructor
274 #else // TB_SIM_CFP_VITIS
275  UDPSocket sock; // NOTE: In HOST TB the port is already binded by warp_transform_host_fwd_tb.cpp
276 #endif // TB_SIM_CFP_VITIS
277 #else // tcp
278  TCPSocket sock(servAddress, servPort);
279 #endif // udp/tcp
280 
281 
282 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
283 
284 
285  //------------------------------------------------------------------------------------
286  //-- STEP-3 : Initialize a Greyscale OpenCV Mat either from image or from video/camera
287  //------------------------------------------------------------------------------------
288  Mat frame, send(FRAME_WIDTH, FRAME_HEIGHT, INPUT_TYPE_HOST, Scalar(0)), ocv_out_img;
289  vector < uchar > encoded;
290 
291 #ifdef INPUT_FROM_CAMERA
292 
293  VideoCapture cap(input_num); // Grab the camera
294  if (!cap.isOpened()) {
295  cerr << "OpenCV Failed to open camera " + input_num << endl;
296  exit(1);
297  }
298 
299 #else // INPUT_FROM_CAMERA
300 
301  VideoCapture cap(input_string); // Grab the image
302  if (!cap.isOpened()) {
303  cerr << "OpenCV Failed to open file " + input_string << endl;
304  exit(1);
305  }
306 
307 #endif // INPUT_FROM_CAMERA
308  std::string warptx_cmd = prepareWarpTransformCommand(FRAME_WIDTH, FRAME_HEIGHT, send.channels(), transformation_matrix_float);
309 
310  //frame = cv::imread(argv[3], cv::IMREAD_GRAYSCALE); // reading in the image in grey scale
311  unsigned int num_frame = 0;
312 
313  while (1) {
314  clock_t start_cycle_main = clock();
315  cap >> frame;
316  if (frame.empty()) break; // if input is an image, the loop will be executed once
317  if(frame.size().width==0) continue; //simple integrity check; skip erroneous data...
318  cout << " ___________________________________________________________________ " << endl;
319  cout << "/ \\" << endl;
320  cout << "INFO: Frame # " << ++num_frame << endl;
321 #if CV_MAJOR_VERSION < 4
322  cv::cvtColor(frame,frame,CV_BGR2GRAY);
323 #else
324  cv::cvtColor(frame,frame,cv::COLOR_BGR2GRAY);
325 #endif
326  resizeCropSquare(frame, send, Size(FRAME_WIDTH, FRAME_HEIGHT), INTER_LINEAR);
327  if ((frame.cols != FRAME_WIDTH) || (frame.rows != FRAME_HEIGHT)) {
328  cout << "WARNING: Input frame was resized from " << frame.cols << "x"
329  << frame.rows << " to " << send.cols << "x" << send.rows << endl;
330  }
331  imwrite("testimg.png", frame);
332 
333  assert(send.total() == FRAME_WIDTH * FRAME_HEIGHT);
334  // Ensure that the selection of MTU is a multiple of 8 (Bytes per transaction)
335  assert(PACK_SIZE % 8 == 0);
336 
337 #ifdef SHOW_WINDOWS
338  namedWindow("host_send", CV_WINDOW_NORMAL);
339  imshow("host_send", send);
340 
341 #endif // SHOW_WINDOWS
342 
343  // Ensure that the send Mat is in continuous memory space. Typically, imread or resize
344  // will return such a continuous Mat, but we should check it.
345  assert(send.isContinuous());
346 
347  unsigned int send_total = send.total();
348  unsigned int send_channels = send.channels();
349  unsigned int warptx_cmd_size = warptx_cmd.length();
350 #else // PY_WRAP == PY_WRAP_WARPTRANSFORM_NUMPI
352  unsigned int send_total = (unsigned int)total_size + warptx_cmd_size; //TBC!!!!!!!!!!!!!!!!!
353  unsigned int send_channels = 1; // FIXME: It is ok only for 1-d array, i.e. CV_8UC1
354  unsigned char * sendarr = input_img;
355 #endif // #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
356 
357  unsigned int total_pack = 1 + (send_total * send_channels - 1 + warptx_cmd_size) / PACK_SIZE;
358  unsigned int total_bytes = total_pack * PACK_SIZE;
359  unsigned int bytes_in_last_pack = send_total * send_channels + warptx_cmd_size - (total_pack - 1) * PACK_SIZE;
360  assert(total_pack == TOT_TRANSFERS);
361 
362  unsigned int total_pack_rx = 1 + (send_total * send_channels - 1) / PACK_SIZE;
363  unsigned int total_bytes_rx = total_pack_rx * PACK_SIZE;
364  unsigned int bytes_in_last_pack_rx = send_total * send_channels - (total_pack_rx- 1) * PACK_SIZE;
365 
366  //unsigned char * longbuf = new unsigned char[PACK_SIZE * total_pack];
367  unsigned char * longbuf = (unsigned char *) malloc (PACK_SIZE * total_pack_rx * sizeof (unsigned char));
368 
369  cout << "INFO: FPGA destination : " << servAddress << ":" << servPort << endl;
370  cout << "INFO: Network socket : " << ((NET_TYPE == tcp) ? "TCP" : "UDP") << endl;
371  cout << "INFO: Total packets to send= " << total_pack << endl;
372  cout << "INFO: Total packets to receive = " << total_pack_rx << endl;
373  cout << "INFO: Total bytes to send = " << send_total * send_channels + warptx_cmd_size << endl;
374  cout << "INFO: Total bytes to receive = " << send_total * send_channels << endl;
375  cout << "INFO: Total bytes in " << total_pack << " packets = " << total_bytes << endl;
376  cout << "INFO: Total bytes in " << total_pack_rx << " packets = " << total_bytes_rx << endl;
377  cout << "INFO: Bytes in last packet = " << bytes_in_last_pack << endl;
378  cout << "INFO: Bytes in last packet to receive = " << bytes_in_last_pack_rx << endl;
379  cout << "INFO: Packet size (custom MTU) = " << PACK_SIZE << endl;
380 
381 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
382 
383  //--------------------------------------------------------
384  //-- STEP-4 : RUN WARPTRANSFORM DETECTOR FROM OpenCV LIBRARY (SW)
385  //--------------------------------------------------------
386  clock_t start_cycle_warp_transform_sw = clock();
387  ocv_out_img.create(send.rows, send.cols, INPUT_TYPE_HOST); // create memory for opencv output image
388  ocv_ref(send, ocv_out_img, transformation_matrix);
389  clock_t end_cycle_warp_transform_sw = clock();
390  double duration_warp_transform_sw = (end_cycle_warp_transform_sw - start_cycle_warp_transform_sw) /
391  (double) CLOCKS_PER_SEC;
392  cout << "INFO: SW exec. time:" << duration_warp_transform_sw << " seconds" << endl;
393  cout << "INFO: Effective FPS SW:" << (1 / duration_warp_transform_sw) << " \tkbps:" <<
394  (PACK_SIZE * total_pack / duration_warp_transform_sw / 1024 * 8) << endl;
395 
396  //------------------------------------------------------
397  //-- STEP-5 : RUN WARPTRANSFORM DETECTOR FROM cF (HW)
398  //------------------------------------------------------
399 
400  //------------------------------------------------------
401  //-- STEP-5.1 : Preparation
402  //------------------------------------------------------
403 
404  // Anchor a pointer on cvMat raw data
405  unsigned char * sendarr_img = send.isContinuous()? send.data: send.clone().data;
406  // unsigned char * sendarr = send.isContinuous()? send.data: send.clone().data;
407  // warptx_cmd = warptx_cmd.append(sendarr_img, send_total * send_channels);
408  unsigned char * sendarr = (unsigned char *) malloc (send_total * send_channels + warptx_cmd_size);
409  memcpy(sendarr,warptx_cmd.c_str(), warptx_cmd_size);
410  memcpy(sendarr+warptx_cmd_size,sendarr_img, send_total * send_channels);
411 
412 #endif // !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
413 
414  clock_t start_cycle_warp_transform_hw = clock();
415 
416  //------------------------------------------------------
417  //-- STEP-5.2 : TX Loop
418  //------------------------------------------------------
419  clock_t last_cycle_tx = clock();
420  unsigned int sending_now = PACK_SIZE;
421  for (unsigned int i = 0; i < total_pack; i++) {
422  if ( i == total_pack - 1 ) {
423  sending_now = bytes_in_last_pack;
424  }
425  #if NET_TYPE == udp
426  sock.sendTo( & sendarr[i * PACK_SIZE], sending_now, servAddress, servPort);
427  #else
428  sock.send( & sendarr[i * PACK_SIZE], sending_now);
429  #endif
430  //delay(500);
431  }
432 
433  clock_t next_cycle_tx = clock();
434  double duration_tx = (next_cycle_tx - last_cycle_tx) / (double) CLOCKS_PER_SEC;
435  cout << "INFO: Effective FPS TX:" << (1 / duration_tx) << " \tkbps:" << (PACK_SIZE *
436  total_pack / duration_tx / 1024 * 8) << endl;
437  last_cycle_tx = next_cycle_tx;
438 
439 
440  //------------------------------------------------------
441  //-- STEP-5.3 : RX Loop
442  //------------------------------------------------------
443  clock_t last_cycle_rx = clock();
444  unsigned int receiving_now = PACK_SIZE;
445  cout << "INFO: Expecting length of packs:" << total_pack_rx << " from " << servAddress << ":" << servPort << endl;
446  //unsigned char * longbuf = new unsigned char[PACK_SIZE * total_pack];
447  unsigned int loopi=0;
448  for (unsigned int i = 0; i < send_total; ) {
449  //cout << "DEBUG: i=" << i << ", loopi=" << loopi++ << endl;
450  //if ( i == total_pack - 1 ) {
451  // receiving_now = bytes_in_last_pack;
452  //}
453  #if NET_TYPE == udp
454  recvMsgSize = sock.recvFrom(buffer, BUF_LEN, servAddress, servPort);
455  #else
456  recvMsgSize = sock.recv(buffer, BUF_LEN);
457  #endif
458  if (recvMsgSize != receiving_now) {
459  cerr << "WARNING: at i=" << i << " received unexpected size pack:" << recvMsgSize << ". Expected: " <<
460  receiving_now << endl;
461  //continue;
462  }
463  memcpy( & longbuf[i], buffer, recvMsgSize);
464  //cout << "DEBUG: i=" << i << " recvMsgSize=" << recvMsgSize << endl;
465  i += recvMsgSize;
466  //delay(500);
467  }
468  cout << "INFO: Received packet from " << servAddress << ":" << servPort << endl;
469 
470  clock_t next_cycle_rx = clock();
471  double duration_rx = (next_cycle_rx - last_cycle_rx) / (double) CLOCKS_PER_SEC;
472  cout << "INFO: Effective FPS RX:" << (1 / duration_rx) << " \tkbps:" << (PACK_SIZE *
473  total_pack_rx / duration_rx / 1024 * 8) << endl;
474  last_cycle_rx = next_cycle_rx;
475 
476  clock_t end_cycle_warp_transform_hw = next_cycle_rx;
477 
478  double duration_warp_transform_hw = (end_cycle_warp_transform_hw - start_cycle_warp_transform_hw) /
479  (double) CLOCKS_PER_SEC;
480  cout << "INFO: HW exec. time:" << duration_warp_transform_hw << " seconds" << endl;
481  cout << "INFO: Effective FPS HW:" << (1 / duration_warp_transform_hw) << " \tkbps:" <<
482  (PACK_SIZE * total_pack / duration_warp_transform_hw / 1024 * 8) << endl;
484 
485 #if !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
486 
487  frame = cv::Mat(FRAME_HEIGHT, FRAME_WIDTH, INPUT_TYPE_HOST, longbuf); // OR vec.data() instead of ptr
488  if (frame.size().width == 0) {
489  cerr << "receive failure!" << endl;
490  continue;
491  }
492 #ifdef SHOW_WINDOWS
493  namedWindow("host_recv", CV_WINDOW_NORMAL);
494  imshow("host_recv", frame);
495 #endif
496 
497  //------------------------------------------------------
498  //-- STEP-6 : Write output files and show in windows
499  //------------------------------------------------------
500 
501  ostringstream oss;
502 // oss << "cFp_Vitis E2E:" << "INFO: Effective FPS HW:" << (1 / duration_warp_transform_hw) <<
503 // " \tkbps:" << (PACK_SIZE * total_pack / duration_warp_transform_hw / 1024 * 8);
504  string windowName = "cFp_Vitis End2End"; //oss.str();
505 
506  //moveWindow(windowName, 0, 0);
507 #ifdef WRITE_OUTPUT_FILE
508  if (num_frame == 1) {
509  out_img_file.assign(input_string);
510  out_img_file += "_fpga_image_out_frame_" + to_string(num_frame) + ".png";
511 #if defined(PY_WRAP) && (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
512 
513  if (!strcpy(output_img_str, &out_img_file[0])) {
514  cerr << "ERROR: Cannot write to output image string." << endl;
515  }
516 #endif // defined(PY_WRAP) && (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
517  cout << "INFO: The output image file is stored at : " << out_img_file << endl;
518  // We save the image received from network after being processed by WarpTransform HW or HOST TB
519  imwrite(out_img_file, frame);
520  }
521  else if (num_frame > 1) {
522  // If the frame is empty, break immediately
523  if (frame.empty()) {
524  break;
525  }
526  cout << "INFO: The output video file is stored at : " << out_video_file << endl;
527  Mat tovideo;
528  if (frame.channels() != 1) {
529  tovideo = frame;
530  }
531  else {
532  cvtColor(frame, tovideo, COLOR_GRAY2BGR);
533  }
534  video.write(tovideo);
535  }
536 #endif // WRITE_OUTPUT_FILE
537  waitKey(FRAME_INTERVAL);
538  double duration_main = (clock() - start_cycle_main) / (double) CLOCKS_PER_SEC;
539  cout << "INFO: Effective FPS E2E:" << (1 / duration_main) << endl;
540  cout << "\\___________________________________________________________________/" << endl
541  << endl;
542  //delete(longbuf);
543  free (longbuf);
544  } // while loop
545 
546  // When everything done, release the video capture and write object
547  cap.release();
548  video.release();
549 
550  // Closes all the windows
551  destroyAllWindows();
552 
553 #else // !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
554  //output_img = longbuf;
555  memcpy( output_img, longbuf, total_size);
556  free(longbuf);
557 #endif // !defined(PY_WRAP) || (PY_WRAP == PY_WRAP_WARPTRANSFORM_FILENAME)
558 
559  // Destructor closes the socket
560  } catch (SocketException & e) {
561  cerr << e.what() << endl;
562  exit(1);
563  }
564 
565 #ifndef PY_WRAP
566  return 0;
567 #endif
568 }
569 
570 
571 
572 
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 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 warp_transform(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, stream< DmCmd > &soMemWrCmdP0, stream< DmSts > &siMemWrStsP0, stream< Axis< 512 > > &soMemWriteP0, membus_t *lcl_mem0, membus_t *lcl_mem1)
#define TRMAT_DIM2
void print_cFpZoo(void)
string prepareWarpTransformCommand(unsigned int rows, unsigned int cols, unsigned int channels, float *transform_matrix)
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.
#define TRMAT_DIM1
void delay(unsigned int mseconds)
def send(cFcluster cluster, node_id, data_obj, proto='udp', port=CF_DEFAULT_PORT)
Definition: comm.py:41
string input
Definition: test.py:9
string output
Definition: test.py:10
out
Definition: test.py:12
def clock()
Definition: common.py:174
Common utility functions headers, i.e. timing, printing wrappers.