Blame view

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