Blame view

src/ai_engine_module/VidClothes.cpp 1.81 KB
15756629   Hu Chunming   添加clothes算法
1
2
3
4
5
6
7
8
9
10
11
  #include "VidClothes.h"
  
  VidClothes::VidClothes(/* args */)
  {
  }
  
  VidClothes::~VidClothes()
  {
      release();
  }
  
581a68a4   Hu Chunming   修正parse_road无返回值导...
12
  int VidClothes::init(int devId, std::string sdk_root){
15756629   Hu Chunming   添加clothes算法
13
14
      ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
  
581a68a4   Hu Chunming   修正parse_road无返回值导...
15
16
      std::string model_path = sdk_root + "/models/vid_clothes/vidClothes0325_310P.om";
  
15756629   Hu Chunming   添加clothes算法
17
      vidclothes_param param;
581a68a4   Hu Chunming   修正parse_road无返回值导...
18
      param.modelNames = (char*)model_path.data();
15756629   Hu Chunming   添加clothes算法
19
      param.thresld = 0.0;
4a273a4a   Hu Chunming   添加hcp和hp
20
      param.devId = devId;
15756629   Hu Chunming   添加clothes算法
21
  
e3062370   Hu Chunming   优化日志
22
      LOG_INFO("vidclothes_init start");
15756629   Hu Chunming   添加clothes算法
23
24
25
26
27
      int ret = vidclothes_init(&m_handle, param);
      if (ret != 0) {
          return -1;
  	}
  
e3062370   Hu Chunming   优化日志
28
      LOG_INFO("vidclothes_init success");
15756629   Hu Chunming   添加clothes算法
29
30
31
32
  
      return SY_SUCCESS;
  }
  
427201b2   Hu Chunming   完善结果返回
33
  vector<int> VidClothes::detect(vector<sy_img> vec_img){
15756629   Hu Chunming   添加clothes算法
34
  
427201b2   Hu Chunming   完善结果返回
35
      vector<int> vec_color;
15756629   Hu Chunming   添加clothes算法
36
37
38
39
40
41
42
43
  
      const int batchsize = vec_img.size();
      vidclothes_result * results = new vidclothes_result[batchsize];
  
      int ret = SY_FAILED;
  
      do
      {
427201b2   Hu Chunming   完善结果返回
44
45
46
47
48
49
          ret = aclrtSetCurrentContext(ctx);
          if (SY_SUCCESS != ret) {
              printf("aclrtSetCurrentContext failed!");
              break;
          }
  
15756629   Hu Chunming   添加clothes算法
50
51
52
53
54
55
56
          ret = vidclothes_batch(m_handle, vec_img.data(), batchsize, results);
          if (SY_SUCCESS != ret) {
              printf("vidclothesClassification process failed!");
              break;
          }
          
          for(int batchIdx = 0;batchIdx<batchsize;batchIdx++) {    
427201b2   Hu Chunming   完善结果返回
57
58
              // printf("index:%d,confidence:%f\n",results[batchIdx].index,results[batchIdx].score);
              vec_color.push_back(results[batchIdx].index);
15756629   Hu Chunming   添加clothes算法
59
60
61
62
63
64
65
          }
      } while (0);
  
      if (results) {
          delete [] results;
      }
  
427201b2   Hu Chunming   完善结果返回
66
      return vec_color;
15756629   Hu Chunming   添加clothes算法
67
68
  }
  
4a273a4a   Hu Chunming   添加hcp和hp
69
70
71
  int VidClothes::release() {
  
      ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);	
15756629   Hu Chunming   添加clothes算法
72
73
74
75
  
      if (m_handle) {
          vidclothes_release(&m_handle);
      }
4a273a4a   Hu Chunming   添加hcp和hp
76
77
78
79
80
81
82
  
      if(ctx){
          aclrtDestroyContext(ctx);
          ctx = nullptr;
      }
  
      return SY_SUCCESS;
15756629   Hu Chunming   添加clothes算法
83
  }