Blame view

src/PicAnalysis.cpp 2.61 KB
20396d5c   Hu Chunming   添加车头车尾算法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  #include "PicAnalysis.h"
  #include "./utils/logger.hpp"
  
  
  PicAnalysis::PicAnalysis(/* args */)
  {
      aclInit(nullptr);
  }
  
  PicAnalysis::~PicAnalysis()
  {
      aclFinalize();
  }
  
  int PicAnalysis::init(int dev_id) {
  
      int ret = m_vehicle_analysis.init(dev_id, 16);
      if(0 != ret){
          return -1;
      }
  
      head_tail_param ht_param;
      ht_param.devId = dev_id;
      ht_param.max_batch = 16;
      ret = m_head_tail_algorithm.init(ht_param);
      if(0 != ret){
          return -1;
      }
  
15756629   Hu Chunming   添加clothes算法
30
31
32
33
      ret = m_clothes_algorithm.init(dev_id);
      if(0 != ret){
          return -1;
      }
20396d5c   Hu Chunming   添加车头车尾算法
34
  
15756629   Hu Chunming   添加clothes算法
35
36
      ACL_CALL(aclrtCreateContext(&m_ctx, 0), ACL_ERROR_NONE, SY_FAILED);
  	ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
20396d5c   Hu Chunming   添加车头车尾算法
37
38
39
40
41
42
43
44
45
  	ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED);
      m_dvpp = new DvppProcess();
  	m_dvpp->InitResource(stream);
  
      return 0;
  }
  
  int PicAnalysis::analysis_sync(vector<string> vec_file_path){
  
15756629   Hu Chunming   添加clothes算法
46
47
      ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
  
20396d5c   Hu Chunming   添加车头车尾算法
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
      const int batch_size = vec_file_path.size();
  
      vector<sy_img> vec_img;
  
      int ret = SY_FAILED;
  
      // ImageData 内部是智能指针,分析未处理完成前不得释放
      ImageData dvpp_data[batch_size];
      for (size_t i = 0; i < vec_file_path.size(); i++)
      {
          string file_path = vec_file_path[i];
          ImageData src;
          ret = Utils::ReadImageFile(src, file_path); //将二进制图像读入内存,并读取宽高信息
          if(ret != SY_SUCCESS){
              LOG_ERROR("ReadImageFile failed!");
              return -1;
          }
  
          ret = m_dvpp->CvtJpegToYuv420sp(dvpp_data[i], src); //解码
          if(ret != SY_SUCCESS){
              LOG_ERROR("CvtJpegToYuv420sp failed!");
              return -1;
          }
          
          sy_img img;
          img.w_ = dvpp_data[i].width;
          img.h_ = dvpp_data[i].height;
          img.data_ = dvpp_data[i].data.get();
  
          vec_img.push_back(img);
      }
      
15756629   Hu Chunming   添加clothes算法
80
      m_vehicle_analysis.detect(vec_img);
20396d5c   Hu Chunming   添加车头车尾算法
81
82
83
84
85
86
87
  
      vector<HeadTailResult> head_tail_result;
      ret = m_head_tail_algorithm.detect(vec_img, head_tail_result);
      if (0 != ret) {
          LOG_ERROR("m_head_tail_algorithm failed!");
          head_tail_result.clear();
      }
15756629   Hu Chunming   添加clothes算法
88
89
  
      m_clothes_algorithm.detect(vec_img);
20396d5c   Hu Chunming   添加车头车尾算法
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
      
      
      return 0;
  }
  
  int PicAnalysis::release() {
      ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
  
      delete m_dvpp;
      m_dvpp = nullptr;
  
      if (stream != nullptr) {
          int ret = aclrtDestroyStream(stream);
          if (ret != ACL_SUCCESS) {
              LOG_ERROR("destroy stream failed");
          }
          stream = nullptr;
      }
  
      aclrtDestroyContext(m_ctx);
  
      return 0;
  }