Blame view

src/ai_engine_module/RoadSegAnalysis.cpp 1.69 KB
2ae58093   Hu Chunming   添加road_seg算法
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
  #include "RoadSegAnalysis.h"
  #include "road_seg.h"
  
  RoadSegAnalysis::RoadSegAnalysis(/* args */)
  {
  }
  
  RoadSegAnalysis::~RoadSegAnalysis()
  {
      release();
  }
  
  int RoadSegAnalysis::init(int devId){
      ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
  
      rs_param param;
      param.modelNames = "./models/road_seg/tzroad_seg240108_310p.om";
      param.thresld = 0.25;
      param.devId = devId;
  
      cout << "rs_init start " << endl;
      int ret = rs_init(&m_handle, param);
      if (ret != 0) {
          return -1;
  	}
  
      cout << "rs_init success " << endl;
  
      return SY_SUCCESS;
  }
  
  int RoadSegAnalysis::detect(vector<sy_img> vec_img){
  
      ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);	
  
      const int batchsize = vec_img.size();
      rs_result results[batchsize];
      const int fea_size = 360*640;
      for (int b = 0; b < batchsize; b++) {
          results[b].seg_array = new unsigned char[fea_size];
          results[b].direct_seg = new unsigned char[fea_size];
      }
  
      int ret = SY_FAILED;
  
      do
      {
          ret = rs_batch(m_handle, vec_img.data(), batchsize, results);
          if (SY_SUCCESS != ret) {
              printf("mrc_batch failed!");
              break;
          }
          
          // todo 结果处理
      } while (0);
  
       for (int b = 0; b < batchsize; b++) {
          delete[] results[b].seg_array; results[b].seg_array = NULL;
          delete[] results[b].direct_seg; results[b].direct_seg = NULL;
      }
  
      return ret;
  }
  
  int RoadSegAnalysis::release() {
  
      ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);	
  
      if (m_handle) {
          rs_release(&m_handle);
      }
  
      if(ctx){
          aclrtDestroyContext(ctx);
          ctx = nullptr;
      }
  
      return SY_SUCCESS;
  }