Blame view

src/util/vpc_util.cpp 17.3 KB
09c2d08c   Hu Chunming   arm交付版
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  
  #include <cstdlib>
  #include <iostream>
  #include <unistd.h>
  #include <dirent.h>
  #include <fstream>
  #include <cstring>
  #include <vector>
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <map>
  #include <cstdint>
  #include "acl/acl.h"
  #include "acl/ops/acl_dvpp.h"
  
  #include "vpc_util.h"
  #include "JpegUtil.h"
  #include "../decoder/interface/DeviceMemory.hpp"
  #include "../common/logger.hpp"
  
80793f7b   Hu Chunming   acl执行错误直接abort
21
22
23
  #define ACL_CHECK_AND_ABORT(ret, message)    \
              if(ret != 0) {LOG_ERROR("{}", message); std::abort();}
  
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
24
25
26
27
28
29
30
31
  static uint32_t AlignSize(uint32_t origSize, uint32_t alignment){
      if (alignment == 0) {
          return 0;
      }
      uint32_t alignmentH = alignment - 1;
      return (origSize + alignmentH) / alignment * alignment;
  }
  
09c2d08c   Hu Chunming   arm交付版
32
33
  void VPCUtil::release()
  {
45e07c6d   Hu Chunming   优化dvppChannelDesc...
34
      if (context_ != nullptr) {
80793f7b   Hu Chunming   acl执行错误直接abort
35
          ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !");
09c2d08c   Hu Chunming   arm交付版
36
  
80793f7b   Hu Chunming   acl执行错误直接abort
37
38
          ACL_CHECK_AND_ABORT(acldvppDestroyChannel(dvppChannelDesc_), "acldvppDestroyChannel failed !");
          ACL_CHECK_AND_ABORT(acldvppDestroyChannelDesc(dvppChannelDesc_), "acldvppDestroyChannelDesc failed !");
09c2d08c   Hu Chunming   arm交付版
39
  
44a5c5b0   Hu Chunming   优化stream_
40
          if (stream_ != nullptr) {
80793f7b   Hu Chunming   acl执行错误直接abort
41
              ACL_CHECK_AND_ABORT(aclrtDestroyStream(stream_), "acldvppDestroyChannelDesc failed !");
44a5c5b0   Hu Chunming   优化stream_
42
43
44
              stream_ = nullptr;
          }
  
80793f7b   Hu Chunming   acl执行错误直接abort
45
46
          ACL_CHECK_AND_ABORT(aclrtDestroyContext(context_), "aclrtDestroyContext failed !");
  
09c2d08c   Hu Chunming   arm交付版
47
48
          context_ = nullptr;
      }
09c2d08c   Hu Chunming   arm交付版
49
  
80793f7b   Hu Chunming   acl执行错误直接abort
50
      LOG_INFO("end to reset device is {}", deviceId_);
09c2d08c   Hu Chunming   arm交付版
51
52
  }
  
44a5c5b0   Hu Chunming   优化stream_
53
54
55
  int VPCUtil::init(int32_t devId){
      deviceId_ = devId;
  
80793f7b   Hu Chunming   acl执行错误直接abort
56
57
      ACL_CHECK_AND_ABORT(aclrtCreateContext(&context_, deviceId_), "aclrtCreateContext failed !");
      ACL_CHECK_AND_ABORT(aclrtCreateStream(&stream_), "aclrtCreateStream failed !");
44a5c5b0   Hu Chunming   优化stream_
58
59
60
  
      // channel  准备
      dvppChannelDesc_ = acldvppCreateChannelDesc();
80793f7b   Hu Chunming   acl执行错误直接abort
61
62
63
64
65
66
67
      if (dvppChannelDesc_ == nullptr)
      {
          LOG_INFO("acldvppCreateChannelDesc failed!");
          std::abort();
      }
      
      ACL_CHECK_AND_ABORT(acldvppCreateChannel(dvppChannelDesc_), "acldvppCreateChannel failed !");
44a5c5b0   Hu Chunming   优化stream_
68
69
  }
  
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  static void adjustCoordinate(uint32_t& left, uint32_t& right, uint32_t& top, uint32_t& bottom, const uint32_t& width, const uint32_t& height) {
      uint32_t cropWidth = right - left;
      uint32_t cropHeight = bottom - top;
  
      if(cropWidth < 16) {
          cropWidth += 16; //小于16的似乎抠不了图
          right += 16;
      }
  
      if (left < 0) {
          left = 0;
          right = cropWidth;
      }
  
      if (right >= width){
          right = width -1;
          left = right - cropWidth;
      }
  
      if (top < 0) {
          top = 0;
          bottom = cropHeight;
      }
  
      if (bottom >= height){
          bottom = height -1;
          top = bottom - cropHeight;
      }
  }
  
09c2d08c   Hu Chunming   arm交付版
100
101
  vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) {
  
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
102
      vpc_img_info img_info;
09c2d08c   Hu Chunming   arm交付版
103
  
9c03cbe4   Zhao Shuaihua   增加三轮车/货车载人 二轮车超员/...
104
105
106
107
108
      // uint32_t cropSizeWidth = (obj.right - obj.left) / 16 * 16;
      // uint32_t cropSizeHeight = (obj.bottom - obj.top) / 2 * 2;
      uint32_t cropSizeWidth = (obj.right - obj.left + 15) / 16 * 16; //debug by zsh
      uint32_t cropSizeHeight = (obj.bottom - obj.top + 1) / 2 * 2;
  
09c2d08c   Hu Chunming   arm交付版
109
110
111
112
113
114
115
      
      uint32_t oddNum = 1;
      uint32_t cropLeftOffset = (obj.left + 1) / 2 * 2;  // must even
      uint32_t cropRightOffset = cropLeftOffset + cropSizeWidth - oddNum;  // must odd
      uint32_t cropTopOffset = (obj.top + 1) / 2 * 2;  // must even
      uint32_t cropBottomOffset = cropTopOffset + cropSizeHeight - oddNum;  // must odd
  
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
116
117
118
      adjustCoordinate(cropLeftOffset, cropRightOffset, cropTopOffset, cropBottomOffset, devMem->getWidth(), devMem->getHeight());
      cropSizeWidth = cropRightOffset - cropLeftOffset + oddNum; // 宽高要比实际的高才行,否则会抠图失败
      cropSizeHeight = cropBottomOffset - cropTopOffset + oddNum;
02e5e637   Zhao Shuaihua   增加行人/非机动车占机动车道(50...
119
      // LOG_DEBUG("{} ,{} ,{} ,{} ", cropLeftOffset, cropRightOffset, cropTopOffset, cropBottomOffset);
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
120
  
09c2d08c   Hu Chunming   arm交付版
121
      if(cropRightOffset <= cropLeftOffset || cropBottomOffset <= cropTopOffset){
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
122
123
124
125
126
          LOG_ERROR("{} <= {} || {} <= {} ", cropRightOffset, cropLeftOffset, cropBottomOffset, cropTopOffset);
          return img_info;
      }
  
      aclError ret;
80793f7b   Hu Chunming   acl执行错误直接abort
127
      ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !");
09c2d08c   Hu Chunming   arm交付版
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  
      // LOG_INFO("crop src {} ({}, {}, {}, {})", obj.object_id, obj.left, obj.right, obj.top, obj.bottom);
      // LOG_INFO("crop {} ({}, {}, {}, {})", obj.object_id, cropLeftOffset, cropRightOffset, cropTopOffset, cropBottomOffset);
      acldvppRoiConfig *cropArea_ = acldvppCreateRoiConfig(cropLeftOffset, cropRightOffset, cropTopOffset, cropBottomOffset);
  
      acldvppPicDesc *vpcInputDesc_ = acldvppCreatePicDesc();
  	acldvppSetPicDescData(vpcInputDesc_, devMem->getMem()); 
  	acldvppSetPicDescFormat(vpcInputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420);
  	acldvppSetPicDescWidth(vpcInputDesc_, devMem->getWidth());
  	acldvppSetPicDescHeight(vpcInputDesc_, devMem->getHeight());
  	acldvppSetPicDescWidthStride(vpcInputDesc_, devMem->getWidthStride());
  	acldvppSetPicDescHeightStride(vpcInputDesc_, devMem->getHeightStride());
  	acldvppSetPicDescSize(vpcInputDesc_, devMem->getSize());
  
      /* processdecode */
      uint32_t vpcOutBufferSize_ = cropSizeWidth * cropSizeHeight * 3 / 2;
      void *vpcOutBufferDev_ = nullptr;
      acldvppMalloc(&vpcOutBufferDev_, vpcOutBufferSize_);
      acldvppPicDesc *vpcOutputDesc_ = acldvppCreatePicDesc();
      acldvppSetPicDescData(vpcOutputDesc_, vpcOutBufferDev_);
      acldvppSetPicDescFormat(vpcOutputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420);
      acldvppSetPicDescWidth(vpcOutputDesc_, cropSizeWidth);
      acldvppSetPicDescHeight(vpcOutputDesc_, cropSizeHeight);
      acldvppSetPicDescWidthStride(vpcOutputDesc_, cropSizeWidth);
      acldvppSetPicDescHeightStride(vpcOutputDesc_, cropSizeHeight);
      acldvppSetPicDescSize(vpcOutputDesc_, vpcOutBufferSize_);
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
154
  
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
155
156
157
      bool bRet = false;
      do
      {
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
158
          ret = acldvppVpcCropAsync(dvppChannelDesc_, vpcInputDesc_, vpcOutputDesc_, cropArea_, stream_);
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
          if (ret != ACL_SUCCESS) {
              LOG_ERROR("acldvppVpcCropAsync failed, task_id : {}", devMem->getId());
              break;
          }
          ret = aclrtSynchronizeStream(stream_);
          if (ret != ACL_SUCCESS) {
              LOG_ERROR("aclrtSynchronizeStream failed, task_id : {}", devMem->getId());
              break;
          }
  
          img_info.pic_desc = vpcOutputDesc_;
          img_info.object_id = obj.object_id;
          img_info.task_id = obj.task_id;              //该物体属于的任务ID
          img_info.task_frame_count = obj.task_frame_count;     //该物体当前出现的帧号
          img_info.index = obj.index;                //该物体所属类别的编号
          img_info.confidence = obj.confidence;      //该物体的置信度
09c2d08c   Hu Chunming   arm交付版
175
  
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
176
177
          bRet = true;
      } while (0);
09c2d08c   Hu Chunming   arm交付版
178
179
180
181
182
183
184
  
      acldvppDestroyPicDesc(vpcInputDesc_);
  
      /* DestroycropResource */
      (void)acldvppDestroyRoiConfig(cropArea_);
      cropArea_ = nullptr;
  
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
185
186
187
      if (!bRet) {
          (void)acldvppDestroyPicDesc(vpcOutputDesc_);
          vpcOutputDesc_ = nullptr;
09c2d08c   Hu Chunming   arm交付版
188
  
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
189
190
191
192
193
          if (vpcOutBufferDev_ != nullptr) {
              (void)acldvppFree(vpcOutBufferDev_);
              vpcOutBufferDev_ = nullptr;
          }
      }
09c2d08c   Hu Chunming   arm交付版
194
195
196
197
  
      return img_info;
  }
  
09c2d08c   Hu Chunming   arm交付版
198
199
200
201
202
203
204
205
206
207
  vector<vpc_img_info> VPCUtil::crop_batch(DeviceMemory *devMem, vector<video_object_info> objs){
  
      vector<vpc_img_info> vec_img_info;
  
      const uint32_t outputBatchSize_ = objs.size();
      if(outputBatchSize_ <= 0){
          return vec_img_info;
      }
  
      aclError ret;
80793f7b   Hu Chunming   acl执行错误直接abort
208
      ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !");
09c2d08c   Hu Chunming   arm交付版
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  
      // 输入
  	acldvppBatchPicDesc *vpcInputBatchDesc_ = acldvppCreateBatchPicDesc(1);
      if (vpcInputBatchDesc_ == nullptr) {
          LOG_ERROR("acldvppCreatePicDesc outBatchPicDesc failed");
          return vec_img_info;
      }
  	acldvppPicDesc *vpcInputDesc_ = acldvppGetPicDesc(vpcInputBatchDesc_, 0);
  	acldvppSetPicDescData(vpcInputDesc_, devMem->getMem()); 
  	acldvppSetPicDescFormat(vpcInputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420);
  	acldvppSetPicDescWidth(vpcInputDesc_, devMem->getWidth());
  	acldvppSetPicDescHeight(vpcInputDesc_, devMem->getHeight());
  	acldvppSetPicDescWidthStride(vpcInputDesc_, devMem->getWidthStride());
  	acldvppSetPicDescHeightStride(vpcInputDesc_, devMem->getHeightStride());
  	acldvppSetPicDescSize(vpcInputDesc_, devMem->getSize());
  
      // 输出
      acldvppBatchPicDesc *outputBatchPicDesc_ = acldvppCreateBatchPicDesc(outputBatchSize_);
      if (outputBatchPicDesc_ == nullptr) {
          LOG_ERROR("acldvppCreatePicDesc outBatchPicDesc failed");
          (void)acldvppDestroyBatchPicDesc(vpcInputBatchDesc_);
          return vec_img_info;
      }
      vector<void *> vecOutPtr_;
      acldvppPicDesc *vpcOutputDesc = nullptr;
      acldvppRoiConfig *cropAreas[outputBatchSize_];
      for (uint32_t i = 0; i < outputBatchSize_; i++) {
          video_object_info obj = objs[i];
  
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
238
239
240
241
          // uint32_t cropSizeWidth = (obj.right - obj.left) / 16 * 16;
          // uint32_t cropSizeHeight = (obj.bottom - obj.top) / 2 * 2;
          uint32_t cropSizeWidth = (obj.right - obj.left + 15) / 16 * 16; //debug by zsh
          uint32_t cropSizeHeight = (obj.bottom - obj.top + 1) / 2 * 2;
09c2d08c   Hu Chunming   arm交付版
242
243
244
245
246
247
248
          
          uint32_t oddNum = 1;
          uint32_t cropLeftOffset = (obj.left + 1) / 2 * 2;  // must even
          uint32_t cropRightOffset = cropLeftOffset + cropSizeWidth - oddNum;  // must odd
          uint32_t cropTopOffset = (obj.top + 1) / 2 * 2;  // must even
          uint32_t cropBottomOffset = cropTopOffset + cropSizeHeight - oddNum;  // must odd
  
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
249
250
251
          adjustCoordinate(cropLeftOffset, cropRightOffset, cropTopOffset, cropBottomOffset, devMem->getWidth(), devMem->getHeight());
          cropSizeWidth = cropRightOffset - cropLeftOffset + oddNum;
          cropSizeHeight = cropBottomOffset - cropTopOffset + oddNum;
02e5e637   Zhao Shuaihua   增加行人/非机动车占机动车道(50...
252
          // LOG_DEBUG("{} ,{} ,{} ,{} ", cropLeftOffset, cropRightOffset, cropTopOffset, cropBottomOffset);
6eb42f55   Hu Chunming   优化jpeg日志;修复抠图坐标越界问题
253
  
09c2d08c   Hu Chunming   arm交付版
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
          if(cropRightOffset <= cropLeftOffset || cropBottomOffset <= cropTopOffset){
              LOG_ERROR("{} <= {} || {} <= {} ", cropRightOffset, cropLeftOffset, cropBottomOffset, cropTopOffset);
              // 释放之前成功的部分 再退出
              for(int i = 0; i < vecOutPtr_.size(); i++){
                  if (vecOutPtr_[i] != nullptr){
                      acldvppFree(vecOutPtr_[i]);
                  }
                  if (cropAreas[i] != nullptr) {
                      (void)acldvppDestroyRoiConfig(cropAreas[i]);
                      cropAreas[i] = nullptr;
                  }
              }
              return vec_img_info;
          }
          
          cropAreas[i] = acldvppCreateRoiConfig(cropLeftOffset, cropRightOffset, cropTopOffset, cropBottomOffset);
  
          uint32_t vpcOutBufferSize_ = cropSizeWidth * cropSizeHeight * 3 / 2;
          void *vpcBatchOutputBufferDev = nullptr;
          auto ret = acldvppMalloc(&vpcBatchOutputBufferDev, vpcOutBufferSize_);
          if (ret != ACL_SUCCESS) {
              LOG_ERROR("acldvppMalloc failed, size = %u, errorCode = %d.", vpcOutBufferSize_, static_cast<int32_t>(ret));
              // 释放之前成功的部分 再退出
              for(int i = 0; i < vecOutPtr_.size(); i++){
                  if (vecOutPtr_[i] != nullptr){
                      acldvppFree(vecOutPtr_[i]);
                  }
                  if (cropAreas[i] != nullptr) {
                      (void)acldvppDestroyRoiConfig(cropAreas[i]);
                      cropAreas[i] = nullptr;
                  }
              }
              return vec_img_info;
          }
          vecOutPtr_.push_back(vpcBatchOutputBufferDev);
          vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i);
          (void)acldvppSetPicDescData(vpcOutputDesc, vpcBatchOutputBufferDev);
          (void)acldvppSetPicDescFormat(vpcOutputDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420);
          (void)acldvppSetPicDescWidth(vpcOutputDesc, cropSizeWidth);
          (void)acldvppSetPicDescHeight(vpcOutputDesc, cropSizeHeight);
          (void)acldvppSetPicDescWidthStride(vpcOutputDesc, cropSizeWidth);
          (void)acldvppSetPicDescHeightStride(vpcOutputDesc, cropSizeHeight);
          (void)acldvppSetPicDescSize(vpcOutputDesc, vpcOutBufferSize_);
      }
  
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
299
300
301
302
303
304
305
306
307
308
309
310
311
      bool bRet = false;
      do {
          uint32_t roiNums[] = { outputBatchSize_ };
          ret = acldvppVpcBatchCropAsync(dvppChannelDesc_, vpcInputBatchDesc_, roiNums, 1, outputBatchPicDesc_, cropAreas, stream_);
          if (ret != ACL_SUCCESS) {
              LOG_ERROR("acldvppVpcBatchCropAsync failed, task_id : {}", devMem->getId());
              break;
          }
          ret = aclrtSynchronizeStream(stream_);
          if (ret != ACL_SUCCESS) {
              LOG_ERROR("aclrtSynchronizeStream failed, task_id : {}", devMem->getId());
              break;
          }
09c2d08c   Hu Chunming   arm交付版
312
  
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
          for (uint32_t i = 0; i < outputBatchSize_; i++) {
              video_object_info obj = objs[i];
  
              vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i);
              void *outputDataDev = acldvppGetPicDescData(vpcOutputDesc);
              uint32_t outputSize = acldvppGetPicDescSize(vpcOutputDesc);
              uint32_t width = acldvppGetPicDescWidth(vpcOutputDesc);
              uint32_t width_stride = acldvppGetPicDescWidthStride(vpcOutputDesc);
              uint32_t height = acldvppGetPicDescHeight(vpcOutputDesc);
              uint32_t height_stride = acldvppGetPicDescHeightStride(vpcOutputDesc);
              acldvppPixelFormat  fmt = acldvppGetPicDescFormat(vpcOutputDesc);
  
              acldvppPicDesc *vpcInputDesc_= acldvppCreatePicDesc();
              acldvppSetPicDescData(vpcInputDesc_, vecOutPtr_[i]); 
              acldvppSetPicDescFormat(vpcInputDesc_, fmt);
              acldvppSetPicDescWidth(vpcInputDesc_, width);
              acldvppSetPicDescHeight(vpcInputDesc_, height);
              acldvppSetPicDescWidthStride(vpcInputDesc_, width_stride);
              acldvppSetPicDescHeightStride(vpcInputDesc_, height_stride);
              acldvppSetPicDescSize(vpcInputDesc_, outputSize);
  
              vpc_img_info img_info ;
              img_info.pic_desc = vpcInputDesc_;
              img_info.object_id = obj.object_id;
              img_info.task_id = obj.task_id;              //该物体属于的任务ID
              img_info.task_frame_count = obj.task_frame_count;     //该物体当前出现的帧号
              img_info.index = obj.index;                //该物体所属类别的编号
              img_info.confidence = obj.confidence;      //该物体的置信度
              vec_img_info.push_back(img_info);
              // vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i);
              // string file_name = "output";
              // file_name = file_name + to_string(i) + ".jpg";
              // vpc_jpeg_encode(vpcOutputDesc, file_name);
          }
  
          bRet = true;
      } while (0);
09c2d08c   Hu Chunming   arm交付版
350
351
352
353
354
355
  
      if (vpcInputBatchDesc_ != nullptr) {
          (void)acldvppDestroyBatchPicDesc(vpcInputBatchDesc_);
          vpcInputBatchDesc_ = nullptr;
      }
  
607d4be1   Hu Chunming   截图代码优化,避免失败情形显存泄漏
356
357
358
359
360
361
362
      if (!bRet){
          for(int i = 0; i < vecOutPtr_.size(); i++){
              if (vecOutPtr_[i] != nullptr){
                  acldvppFree(vecOutPtr_[i]);
              }
          }
      }
09c2d08c   Hu Chunming   arm交付版
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
  
      if (outputBatchPicDesc_ != nullptr) {
          (void)acldvppDestroyBatchPicDesc(outputBatchPicDesc_);
          outputBatchPicDesc_ = nullptr;
      }
  
      // for (size_t i = 0; i < vec_img_info.size(); i++)
      // {
      //     if(vec_img_info[i].pic_desc != nullptr){
      //         void *outputDataDev = acldvppGetPicDescData(vec_img_info[i].pic_desc);
      //         acldvppFree(outputDataDev);
      //         acldvppDestroyPicDesc(vec_img_info[i].pic_desc);
      //     }
      // }
  
      for (uint32_t i = 0; i < outputBatchSize_; i++) {
          if (cropAreas[i] != nullptr) {
              (void)acldvppDestroyRoiConfig(cropAreas[i]);
              cropAreas[i] = nullptr;
          }
      }
  
      return vec_img_info;
  }
  
  vpc_img_info VPCUtil::vpc_devMem2vpcImg(DeviceMemory *devMem){
      vpc_img_info img_info ;
  
      int nBufferSize = devMem->getSize();
  
      void *devBuffer = nullptr;
      auto ret = acldvppMalloc(&devBuffer, nBufferSize);
      if (ret != ACL_SUCCESS) {
          LOG_ERROR("acldvppMalloc failed, size = %u, errorCode = %d.", nBufferSize, static_cast<int32_t>(ret));
          // 这里应释放之前成功的部分 再退出
          return img_info;
      }
  
      aclrtMemcpy(devBuffer, nBufferSize, devMem->getMem(), nBufferSize, ACL_MEMCPY_DEVICE_TO_DEVICE);
  
      acldvppPicDesc *vpcInputDesc_= acldvppCreatePicDesc();
  	acldvppSetPicDescData(vpcInputDesc_, devBuffer); 
  	acldvppSetPicDescFormat(vpcInputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420);
  	acldvppSetPicDescWidth(vpcInputDesc_, devMem->getWidth());
  	acldvppSetPicDescHeight(vpcInputDesc_, devMem->getHeight());
  	acldvppSetPicDescWidthStride(vpcInputDesc_, devMem->getWidthStride());
  	acldvppSetPicDescHeightStride(vpcInputDesc_, devMem->getHeightStride());
  	acldvppSetPicDescSize(vpcInputDesc_, devMem->getSize());
  
      img_info.pic_desc = vpcInputDesc_;
      img_info.object_id = -1;
      img_info.task_id = devMem->getId();              //该物体属于的任务ID
      img_info.index = -1;                //该物体所属类别的编号
      img_info.confidence = 0.0;      //该物体的置信度
  
      return img_info;
  }
  
  void VPCUtil::vpc_pic_desc_release(acldvppPicDesc* pic_desc){
      void *outputDataDev = acldvppGetPicDescData(pic_desc);
      acldvppFree(outputDataDev);
      acldvppDestroyPicDesc(pic_desc);
  }
  
  void VPCUtil::vpc_img_release(vpc_img_info img_info){
      if(img_info.pic_desc != nullptr){
          void *outputDataDev = acldvppGetPicDescData(img_info.pic_desc);
          acldvppFree(outputDataDev);
          acldvppDestroyPicDesc(img_info.pic_desc);
      }
  }
  
  void VPCUtil::vpc_imgList_release(vector<vpc_img_info>& imgList){
      for(int i=0; i < imgList.size(); i++){
          vpc_img_release(imgList[i]);
      }
      imgList.clear();
  }