yolo_test.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "yolo.h"
  4. #include "ax_test_utils.h"
  5. #include <vx_log.h>
  6. #include <iostream>
  7. int get_yuv(ezax_img_t &input){
  8. int y_size = 384 * 640;
  9. int uv_size = y_size / 2;
  10. FILE *input_file = NULL;
  11. char *input_file_name = (char *)"images.yuv";
  12. input_file = fopen(input_file_name, "rb");
  13. if (input_file == NULL) {
  14. VX_LOG("%s fopen file %s error\n", __FUNCTION__, input_file_name);
  15. return 1;
  16. }
  17. memset(&input, 0, sizeof(ezax_img_t));
  18. input.img_handle.fmt = EZAX_YUV420_SP;
  19. input.img_handle.w = 640;
  20. input.img_handle.h = 384;
  21. input.img_handle.c = 2;
  22. input.img_handle.stride = 0;
  23. input.roi.x0 = 0;
  24. input.roi.y0 = 0;
  25. input.roi.x1 = 640;
  26. input.roi.y1 = 384;
  27. input.img_handle.pVir = ax_malloc_uncache(&input.img_handle.pPhy, y_size + uv_size);
  28. input.img_handle.pVir_UV = (void *)((char *)input.img_handle.pVir + y_size);
  29. input.img_handle.pPhy_UV = input.img_handle.pPhy + y_size;
  30. VX_LOG("%s y_size %d uv_size %d\n", __FUNCTION__, y_size, uv_size);
  31. VX_LOG("%s input.img_handle.pVir : %p\n", __FUNCTION__, input.img_handle.pVir);
  32. VX_LOG("%s input.img_handle.pPhy : %x\n", __FUNCTION__, input.img_handle.pPhy);
  33. int len;
  34. len = fread(input.img_handle.pVir, 1, y_size + uv_size, input_file);
  35. if (len != (y_size + uv_size)) {
  36. VX_LOG("%s fread error.\n");
  37. return -1;
  38. }
  39. VX_LOG("%s fread success\n", __FUNCTION__);
  40. return 0;
  41. }
  42. int yolo_test(){
  43. int state;
  44. ezax_img_t input;
  45. ezax_boxes_t pOut;
  46. ezax_custom_det_cfg_t cfg;
  47. void *yolo_hdl;
  48. float conf_thresh, iou_thresh;
  49. conf_thresh = 0.35;
  50. iou_thresh = 0.25;
  51. cfg.width = 640;
  52. cfg.height = 384;
  53. VX_LOG("%s begin yolo_test.\n", __FUNCTION__);
  54. yolo_hdl = nna_custom_det_open(&cfg);
  55. if (yolo_hdl == NULL) {
  56. VX_LOG("%s yolov_hdl open error\n", __FUNCTION__);
  57. return 0;
  58. }
  59. VX_LOG("%s nna_custom_det_open success.\n", __FUNCTION__);
  60. state = get_yuv(input);
  61. if (state != VX_SUCCESS) {
  62. VX_LOG("%s get_yuv error\n", __FUNCTION__);
  63. return 0;
  64. }
  65. pOut.pRect = (ezax_rt_t *)ax_malloc_virt(sizeof(ezax_rt_t) * MAX_CLASSIFICATION_DET_NUM);
  66. pOut.num = 0;
  67. state = nna_custom_det_process(yolo_hdl, &input, &pOut, conf_thresh, iou_thresh);
  68. if (state != VX_SUCCESS) {
  69. VX_LOG("%s nna_yolo_det_process error\n", __FUNCTION__);
  70. return 0;
  71. }
  72. std::cout << __LINE__ << std::endl;
  73. state = nna_custom_det_close(yolo_hdl);
  74. if (state != VX_SUCCESS) {
  75. VX_LOG("%s nna_yolo_det_close error\n", __FUNCTION__);
  76. return 0;
  77. }
  78. // free(&input);
  79. // free(pOut.pRect);
  80. std::cout << __LINE__ << std::endl;
  81. while (1)
  82. {
  83. /* code */
  84. }
  85. return 1;
  86. }
  87. int main(int argc, char *argv[]){
  88. yolo_test();
  89. return 0;
  90. }