Blame view

src/ai_engine_module/MotorRainshedAnalysis.cpp 1.74 KB
f171c20a   Hu Chunming   添加moter_rainshed ...
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
30
31
  #include "MotorRainshedAnalysis.h"
  #include "motor_rainshed_cls.h"
  
  MotorRainshedAnalysis::MotorRainshedAnalysis(/* args */)
  {
  }
  
  MotorRainshedAnalysis::~MotorRainshedAnalysis()
  {
      release();
  }
  
  int MotorRainshedAnalysis::init(int devId){
      ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
  
      mrc_param param;
      param.modelNames = "./models/rainshed/motor_rainshed_231123_310p.om";
      param.thresld = 0.0;
      param.devId = devId;
  
      cout << "mrc_init start " << endl;
      int ret = mrc_init(&m_handle, param);
      if (ret != 0) {
          return -1;
  	}
  
      cout << "mrc_init success " << endl;
  
      return SY_SUCCESS;
  }
  
667e7a90   Hu Chunming   雨棚和打电话初步代码
32
  vector<int> MotorRainshedAnalysis::detect(vector<sy_img> vec_img){
f171c20a   Hu Chunming   添加moter_rainshed ...
33
  
667e7a90   Hu Chunming   雨棚和打电话初步代码
34
      vector<int> vec_result;
f171c20a   Hu Chunming   添加moter_rainshed ...
35
36
  
      const int batchsize = vec_img.size();
667e7a90   Hu Chunming   雨棚和打电话初步代码
37
38
39
  
      vector<mrc_result> results;
      results.resize(batchsize);
f171c20a   Hu Chunming   添加moter_rainshed ...
40
41
42
43
44
  
      int ret = SY_FAILED;
  
      do
      {
667e7a90   Hu Chunming   雨棚和打电话初步代码
45
46
47
48
49
50
51
          ret = aclrtSetCurrentContext(ctx);
          if (SY_SUCCESS != ret) {
              printf("aclrtSetCurrentContext failed!");
              break;
          }
  
          ret = mrc_batch(m_handle, vec_img.data(), batchsize, results.data());
f171c20a   Hu Chunming   添加moter_rainshed ...
52
53
54
55
56
          if (SY_SUCCESS != ret) {
              printf("mrc_batch failed!");
              break;
          }
          
667e7a90   Hu Chunming   雨棚和打电话初步代码
57
          for(int batchIdx = 0;batchIdx<batchsize;batchIdx++){
f171c20a   Hu Chunming   添加moter_rainshed ...
58
              printf("index:%d,confidence:%f\n",results[batchIdx].index,results[batchIdx].score);
667e7a90   Hu Chunming   雨棚和打电话初步代码
59
              vec_result.push_back(results[batchIdx].index);
f171c20a   Hu Chunming   添加moter_rainshed ...
60
61
62
          }
      } while (0);
  
667e7a90   Hu Chunming   雨棚和打电话初步代码
63
      return vec_result;
f171c20a   Hu Chunming   添加moter_rainshed ...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  }
  
  int MotorRainshedAnalysis::release() {
  
      ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);	
  
      if (m_handle) {
          mrc_release(&m_handle);
      }
  
      if(ctx){
          aclrtDestroyContext(ctx);
          ctx = nullptr;
      }
  
      return SY_SUCCESS;
  }