Blame view

src/ai_engine_module/MotorPhoneAnalysis.cpp 2.31 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 "MotorPhoneAnalysis.h"
  #include "motor_phone_det.h"
  
  MotorPhoneAnalysis::MotorPhoneAnalysis(/* args */)
  {
  }
  
  MotorPhoneAnalysis::~MotorPhoneAnalysis()
  {
      release();
  }
  
  int MotorPhoneAnalysis::init(int devId){
      ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
  
      motor_phone_param param;
      param.modelNames = "./models/motor_phone/motor_phone1127_310p.om"; 
      param.thresld = 0.25;
      param.devId = devId;
  
      cout << "motor_phone_init start " << endl;
      int ret = motor_phone_init(&m_handle, param);
      if (ret != 0) {
          return -1;
  	}
  
      cout << "motor_phone_init success " << endl;
  
      return SY_SUCCESS;
  }
  
6f9dffde   Hu Chunming   返回prob
32
  vector<MotorPhoneResult> MotorPhoneAnalysis::detect(vector<sy_img> vec_img){
f171c20a   Hu Chunming   添加moter_rainshed ...
33
  
6f9dffde   Hu Chunming   返回prob
34
      vector<MotorPhoneResult> vec_result;
f171c20a   Hu Chunming   添加moter_rainshed ...
35
36
  
      const int batchsize = vec_img.size();
667e7a90   Hu Chunming   雨棚和打电话初步代码
37
38
39
  
      vector<motor_phone_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 = motor_phone_process_batch(m_handle, vec_img.data(), batchsize, results.data());
f171c20a   Hu Chunming   添加moter_rainshed ...
52
53
54
55
56
57
          if (SY_SUCCESS != ret) {
              printf("motor_phone_process_batch failed!");
              break;
          }
          
          for(int batchIdx = 0; batchIdx < batchsize; batchIdx ++){
6f9dffde   Hu Chunming   返回prob
58
59
60
              MotorPhoneResult one_result;
              one_result.phoning = -1;
              one_result.prob = 0;
f171c20a   Hu Chunming   添加moter_rainshed ...
61
62
              for (int i = 0; i < results[batchIdx].objcount; i++) {
                  printf("  %d:%.2f \n", results[batchIdx].objinfo[i].index,results[batchIdx].objinfo[i].confidence);
6f9dffde   Hu Chunming   返回prob
63
64
65
66
67
68
                  if (results[batchIdx].objinfo[i].index == 1) {
                      // 骑车打电话
                      one_result.phoning = results[batchIdx].objinfo[i].index;
                      one_result.prob = results[batchIdx].objinfo[i].confidence;
                      break;
                  }
f171c20a   Hu Chunming   添加moter_rainshed ...
69
              }
6f9dffde   Hu Chunming   返回prob
70
71
  
              vec_result.push_back(one_result);
f171c20a   Hu Chunming   添加moter_rainshed ...
72
73
74
          }
      } while (0);
  
667e7a90   Hu Chunming   雨棚和打电话初步代码
75
      return vec_result;
f171c20a   Hu Chunming   添加moter_rainshed ...
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  }
  
  int MotorPhoneAnalysis::release() {
  
      ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);	
  
      if (m_handle) {
          motor_phone_release(&m_handle);
      }
  
      if(ctx){
          aclrtDestroyContext(ctx);
          ctx = nullptr;
      }
  
      return SY_SUCCESS;
  }