Commit d7bafd6794e7caa1a693a52606a404db1c2b4850
1 parent
e109b001
添加最优快照截取模式
Showing
17 changed files
with
431 additions
and
615 deletions
.gitignore
src/ai_platform/MultiSourceProcess.cpp
@@ -9,7 +9,6 @@ | @@ -9,7 +9,6 @@ | ||
9 | 9 | ||
10 | #include "../decoder/interface/DecoderManager.h" | 10 | #include "../decoder/interface/DecoderManager.h" |
11 | #include "../decoder/interface/utiltools.hpp" | 11 | #include "../decoder/interface/utiltools.hpp" |
12 | -#include "../util/crop_process.h" | ||
13 | #include "../helpers/time_helper.hpp" | 12 | #include "../helpers/time_helper.hpp" |
14 | #include "../helpers/os_helper.hpp" | 13 | #include "../helpers/os_helper.hpp" |
15 | #include "../helpers/gen_json.hpp" | 14 | #include "../helpers/gen_json.hpp" |
@@ -18,10 +17,21 @@ | @@ -18,10 +17,21 @@ | ||
18 | #include "macro_definition.h" | 17 | #include "macro_definition.h" |
19 | #include "SourceSingleton.hpp" | 18 | #include "SourceSingleton.hpp" |
20 | 19 | ||
21 | -#define VEHICLE_MULTI_BOXES | 20 | +// #define VEHICLE_MULTI_BOXES |
22 | 21 | ||
23 | using namespace std; | 22 | using namespace std; |
24 | 23 | ||
24 | +map<int, algo_type> index_to_algo_type = {{0, algorithm_type_t::HUMAN_SNAPSHOT}, | ||
25 | + {1, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, | ||
26 | + {2, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, | ||
27 | + {3, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, | ||
28 | + {4, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
29 | + {5, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
30 | + {6, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
31 | + {7, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
32 | + {8, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
33 | + {9, algorithm_type_t::FACE_SNAPSHOT}}; | ||
34 | + | ||
25 | 35 | ||
26 | struct decode_cbk_userdata{ | 36 | struct decode_cbk_userdata{ |
27 | string task_id; | 37 | string task_id; |
@@ -30,7 +40,6 @@ struct decode_cbk_userdata{ | @@ -30,7 +40,6 @@ struct decode_cbk_userdata{ | ||
30 | }; | 40 | }; |
31 | 41 | ||
32 | 42 | ||
33 | - | ||
34 | /** | 43 | /** |
35 | * 注意: gpuFrame 在解码器设置的显卡上,后续操作要十分注意这一点,尤其是多线程情况 | 44 | * 注意: gpuFrame 在解码器设置的显卡上,后续操作要十分注意这一点,尤其是多线程情况 |
36 | * */ | 45 | * */ |
@@ -62,7 +71,7 @@ CMultiSourceProcess::CMultiSourceProcess(){ | @@ -62,7 +71,7 @@ CMultiSourceProcess::CMultiSourceProcess(){ | ||
62 | } | 71 | } |
63 | 72 | ||
64 | CMultiSourceProcess::~CMultiSourceProcess(){ | 73 | CMultiSourceProcess::~CMultiSourceProcess(){ |
65 | - vpc_util.vpc_crop_release(); | 74 | + vpc_util.release(); |
66 | } | 75 | } |
67 | 76 | ||
68 | int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ | 77 | int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ |
@@ -90,10 +99,10 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ | @@ -90,10 +99,10 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ | ||
90 | } | 99 | } |
91 | 100 | ||
92 | m_task_param_manager = task_param_manager::getInstance(); | 101 | m_task_param_manager = task_param_manager::getInstance(); |
93 | - m_snapshot_reprocessing = snapshot_reprocessing::getInstance(); | 102 | + m_snapshot_reprocessing = new snapshot_reprocessing(m_devId); |
94 | m_save_snapshot_reprocessing = new save_snapshot_reprocessing(m_devId); | 103 | m_save_snapshot_reprocessing = new save_snapshot_reprocessing(m_devId); |
95 | 104 | ||
96 | - vpc_util.vpc_crop_init(m_devId); | 105 | + vpc_util.init(m_devId); |
97 | 106 | ||
98 | m_pAlgorthimThread = new thread([](void* arg) { | 107 | m_pAlgorthimThread = new thread([](void* arg) { |
99 | CMultiSourceProcess* process = (CMultiSourceProcess*)arg ; | 108 | CMultiSourceProcess* process = (CMultiSourceProcess*)arg ; |
@@ -391,7 +400,7 @@ int CMultiSourceProcess::algorthim_process_thread(){ | @@ -391,7 +400,7 @@ int CMultiSourceProcess::algorthim_process_thread(){ | ||
391 | continue; | 400 | continue; |
392 | } | 401 | } |
393 | 402 | ||
394 | - ACL_CALL(aclrtSetCurrentContext(ctx), ACL_ERROR_NONE, 1); | 403 | + aclrtSetCurrentContext(ctx); |
395 | algorthim_vpt(vec_gpuMem); | 404 | algorthim_vpt(vec_gpuMem); |
396 | 405 | ||
397 | for(int i=0;i < vec_gpuMem.size(); i++){ | 406 | for(int i=0;i < vec_gpuMem.size(); i++){ |
@@ -406,6 +415,8 @@ int CMultiSourceProcess::algorthim_process_thread(){ | @@ -406,6 +415,8 @@ int CMultiSourceProcess::algorthim_process_thread(){ | ||
406 | 415 | ||
407 | } | 416 | } |
408 | 417 | ||
418 | + aclrtDestroyContext(ctx); | ||
419 | + | ||
409 | LOG_INFO("algorthim_process_thread exit."); | 420 | LOG_INFO("algorthim_process_thread exit."); |
410 | 421 | ||
411 | return 0; | 422 | return 0; |
@@ -445,7 +456,10 @@ int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){ | @@ -445,7 +456,10 @@ int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){ | ||
445 | 456 | ||
446 | #ifndef VEHICLE_MULTI_BOXES | 457 | #ifndef VEHICLE_MULTI_BOXES |
447 | /* 快照优选(内部可实现不同的快照优选策略) */ | 458 | /* 快照优选(内部可实现不同的快照优选策略) */ |
448 | - m_snapshot_reprocessing->update_bestsnapshot(vpt_interest_task_id, vpt_interest_imgs.data(), vptResult, deleteObjectID); | 459 | + m_snapshot_reprocessing->update_bestsnapshot(vec_vptMem, vptResult, deleteObjectID); |
460 | + | ||
461 | + /* for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径)*/ | ||
462 | + vehicle_snapshot(vpt_interest_task_id, deleteObjectID); | ||
449 | #else | 463 | #else |
450 | algorithm_vehicle_relult(vec_vptMem, vptResult, deleteObjectID); | 464 | algorithm_vehicle_relult(vec_vptMem, vptResult, deleteObjectID); |
451 | 465 | ||
@@ -486,7 +500,7 @@ int CMultiSourceProcess::algorithm_vehicle_relult(vector<DeviceMemory*> vec_devM | @@ -486,7 +500,7 @@ int CMultiSourceProcess::algorithm_vehicle_relult(vector<DeviceMemory*> vec_devM | ||
486 | saveInfo.img_info = vpc_util.vpc_devMem2vpcImg(result.memPtr); | 500 | saveInfo.img_info = vpc_util.vpc_devMem2vpcImg(result.memPtr); |
487 | m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(saveInfo); | 501 | m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(saveInfo); |
488 | 502 | ||
489 | - vector<vpc_img_info> vec_obj_info_list = vpc_util.vpc_crop_batch(result.memPtr, result.objs); | 503 | + vector<vpc_img_info> vec_obj_info_list = vpc_util.crop_batch(result.memPtr, result.objs); |
490 | if(vec_obj_info_list.size() != result.objs.size()){ | 504 | if(vec_obj_info_list.size() != result.objs.size()){ |
491 | LOG_ERROR("vpc_crop size error !"); | 505 | LOG_ERROR("vpc_crop size error !"); |
492 | vpc_util.vpc_imgList_release(vec_obj_info_list); | 506 | vpc_util.vpc_imgList_release(vec_obj_info_list); |
@@ -560,4 +574,99 @@ void CMultiSourceProcess::send_locus_finished_msg(vector<string>& vpt_interest_t | @@ -560,4 +574,99 @@ void CMultiSourceProcess::send_locus_finished_msg(vector<string>& vpt_interest_t | ||
560 | } | 574 | } |
561 | } | 575 | } |
562 | } | 576 | } |
577 | +} | ||
578 | + | ||
579 | +// for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径) | ||
580 | +void CMultiSourceProcess::vehicle_snapshot(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID) { | ||
581 | + auto task_iter = vpt_interest_task_id.begin(); | ||
582 | + | ||
583 | + for (int i = 0; i < deleteObjectID.size(); i++, ++task_iter) // loop taskId. | ||
584 | + { | ||
585 | + for (int &j : deleteObjectID[i]) // loop algor type. | ||
586 | + { | ||
587 | + OBJ_KEY obj_key = {*task_iter, j}; | ||
588 | + endframe_obj_process(obj_key, algorithm_type_t::PLACEHOLDER); | ||
589 | + } | ||
590 | + } | ||
591 | +} | ||
592 | + | ||
593 | +/* 轨迹结束帧需要做的算法模块 */ | ||
594 | +/* 轨迹结束帧需要做的算法模块 */ | ||
595 | +int CMultiSourceProcess::endframe_obj_process(const OBJ_KEY &obj_key, algorithm_type_t algor_type) { | ||
596 | + auto task_param_ptr = m_task_param_manager->get_task_algor_param(obj_key.video_id); | ||
597 | + auto task_other_param_ptr = m_task_param_manager->get_task_other_param(obj_key.video_id); | ||
598 | + | ||
599 | + // 该路任务开启了抓拍功能 开始抓拍保存;若未开启抓拍,清空显存资源 | ||
600 | + if ((task_param_ptr->human_algors.find(algorithm_type_t::HUMAN_SNAPSHOT) != task_param_ptr->human_algors.end() || | ||
601 | + task_param_ptr->vehicle_algors.find(algorithm_type_t::VEHICLE_SNAPSHOT) != task_param_ptr->vehicle_algors.end() || | ||
602 | + task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT) != task_param_ptr->nonmotor_vehicle_algors.end())) { | ||
603 | + | ||
604 | + vehicle_locus_finished(obj_key); | ||
605 | + | ||
606 | + } | ||
607 | +} | ||
608 | + | ||
609 | +void CMultiSourceProcess::vehicle_locus_finished(const OBJ_KEY obj_key){ | ||
610 | + map<OBJ_KEY, OBJ_VALUE> _total_snapshot_info = m_snapshot_reprocessing->get_total_snapshot_info(); | ||
611 | + | ||
612 | + if (_total_snapshot_info.find(obj_key) == _total_snapshot_info.end()) { | ||
613 | + return; | ||
614 | + } | ||
615 | + | ||
616 | + const OBJ_VALUE obj_value = _total_snapshot_info[obj_key]; | ||
617 | + auto task_other_param = m_task_param_manager->get_task_other_params()[obj_key.video_id]; | ||
618 | + | ||
619 | + auto algor_type = index_to_algo_type[obj_value.index.index]; | ||
620 | + | ||
621 | + auto algor_param = (algor_config_param_snapshot *)task_other_param[algor_type]->algor_param; | ||
622 | + if (obj_value.confidence <= algor_param->threshold) { | ||
623 | + LOG_DEBUG("Snapshot conf filter ({} vs {})", obj_value.confidence, algor_param->threshold); | ||
624 | + // 删除记录,同时释放显存 | ||
625 | + m_snapshot_reprocessing->release_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, true); | ||
626 | + return; | ||
627 | + } | ||
628 | + | ||
629 | + const algor_basic_config_param_t *cur_param = task_other_param[algor_type]->basic_param; | ||
630 | + | ||
631 | + // 原图 | ||
632 | + std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms()); | ||
633 | + std::string fpath_origin = std::string(cur_param->result_folder) + helpers::os::sep + obj_key.video_id + "_" + | ||
634 | + std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".jpg"; | ||
635 | + | ||
636 | + ImgSaveInfo origin_save_info; | ||
637 | + origin_save_info.file_path = fpath_origin; | ||
638 | + origin_save_info.img_info = obj_value.snapShot; | ||
639 | + origin_save_info.obj_rect = obj_value.obj_pos; | ||
640 | + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(origin_save_info); | ||
641 | + | ||
642 | + { | ||
643 | + // 抠图 | ||
644 | + string json_str = ""; | ||
645 | + std::string cur_timestamp_ms = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>()); | ||
646 | + string object_file_name = std::string(cur_param->result_folder_little) + helpers::os::sep + obj_key.video_id + "_" + | ||
647 | + std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".jpg"; | ||
648 | + | ||
649 | +#ifdef POST_USE_RABBITMQ | ||
650 | + video_object_snapshot new_obj_ss_info; | ||
651 | + new_obj_ss_info.analysisRes = nullptr; | ||
652 | + new_obj_ss_info.object_id = obj_key.obj_id; | ||
653 | + new_obj_ss_info.obj_info.set_data(obj_value.index.index, obj_value.confidence, obj_value.obj_pos.left_, | ||
654 | + obj_value.obj_pos.top_, obj_value.obj_pos.left_ + obj_value.obj_pos.width_, | ||
655 | + obj_value.obj_pos.top_ + obj_value.obj_pos.height_); | ||
656 | + strcpy(new_obj_ss_info.task_id, obj_key.video_id.c_str()); | ||
657 | + strcpy(new_obj_ss_info.video_image_path, fpath_origin.c_str()); | ||
658 | + strcpy(new_obj_ss_info.snapshot_image_path, object_file_name.c_str()); | ||
659 | + json_str = helpers::gen_json::gen_snapshot_json(algor_type, new_obj_ss_info); | ||
660 | +#endif | ||
661 | + | ||
662 | + ImgSaveInfo obj_save_info; | ||
663 | + obj_save_info.file_path = object_file_name; | ||
664 | + obj_save_info.img_info = obj_value.snapShotLittle; | ||
665 | + obj_save_info.json_str = json_str; | ||
666 | + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(obj_save_info); | ||
667 | + } | ||
668 | + | ||
669 | + // 仅删除记录,显存会在保存线程中删除 | ||
670 | + m_snapshot_reprocessing->release_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, false); | ||
671 | + | ||
563 | } | 672 | } |
564 | \ No newline at end of file | 673 | \ No newline at end of file |
src/ai_platform/MultiSourceProcess.h
@@ -54,6 +54,10 @@ private: | @@ -54,6 +54,10 @@ private: | ||
54 | bool finish_task(const string taskID, const bool delete_snapshot); | 54 | bool finish_task(const string taskID, const bool delete_snapshot); |
55 | int algorithm_vehicle_relult(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& vptResult, vector<vector<int>>& delete_object_id); | 55 | int algorithm_vehicle_relult(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& vptResult, vector<vector<int>>& delete_object_id); |
56 | void send_locus_finished_msg(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID); | 56 | void send_locus_finished_msg(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID); |
57 | + void vehicle_snapshot(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID); | ||
58 | + void vehicle_locus_finished(const OBJ_KEY obj_key); | ||
59 | + | ||
60 | + int endframe_obj_process(const OBJ_KEY &obj_key, algorithm_type_t algor_type); | ||
57 | 61 | ||
58 | private: | 62 | private: |
59 | int m_devId; | 63 | int m_devId; |
src/ai_platform/header.h
@@ -231,7 +231,7 @@ typedef struct video_object_snapshot { | @@ -231,7 +231,7 @@ typedef struct video_object_snapshot { | ||
231 | #ifndef __VIDEO_OBJECT_INFO__ | 231 | #ifndef __VIDEO_OBJECT_INFO__ |
232 | #define __VIDEO_OBJECT_INFO__ | 232 | #define __VIDEO_OBJECT_INFO__ |
233 | typedef struct video_object_info { | 233 | typedef struct video_object_info { |
234 | - int task_id; //该物体属于的任务ID号 | 234 | + char task_id[128]; //该物体属于的任务ID号 |
235 | int task_frame_count; //该物体当前出现的帧号 | 235 | int task_frame_count; //该物体当前出现的帧号 |
236 | int object_id; //该物体的ID号 | 236 | int object_id; //该物体的ID号 |
237 | int left; //该物体位置的左坐标 | 237 | int left; //该物体位置的左坐标 |
src/ai_platform/mvpt_process_assist.cpp
@@ -183,16 +183,6 @@ void CreateResultFolder(char* resultFolder, const char* jointFolder) | @@ -183,16 +183,6 @@ void CreateResultFolder(char* resultFolder, const char* jointFolder) | ||
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | - | ||
187 | -bool best_snapshot_judge_algor(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height) | ||
188 | -{ | ||
189 | - return snapshot_legal_pos(obj_value.flags, left, top, left + width, top + height, image_width, image_height) | ||
190 | - && snapshot_legal_minarea(obj_value.index.index, width, height) | ||
191 | - && snapshot_legal_inarea(width, height) | ||
192 | - && snapshot_legal_area(obj_value.max_area, obj_value.last_area, left, top, left + width, top + height); | ||
193 | - return true; | ||
194 | -} | ||
195 | - | ||
196 | bool snapshot_judge_algor(int index, int width, int height) | 186 | bool snapshot_judge_algor(int index, int width, int height) |
197 | { | 187 | { |
198 | return snapshot_legal_minarea(index, width, height) //判断最小面积 | 188 | return snapshot_legal_minarea(index, width, height) //判断最小面积 |
src/ai_platform/mvpt_process_assist.h
@@ -22,39 +22,6 @@ | @@ -22,39 +22,6 @@ | ||
22 | 22 | ||
23 | using namespace std; | 23 | using namespace std; |
24 | 24 | ||
25 | -typedef struct DxGPUFrame | ||
26 | -{ | ||
27 | - void * frame; | ||
28 | - unsigned int size; | ||
29 | - unsigned int width; | ||
30 | - unsigned int height; | ||
31 | - unsigned long long timestamp; | ||
32 | -}DxGPUFrame; | ||
33 | - | ||
34 | -struct OBJ_VALUE { | ||
35 | - bool finishTracker; //轨迹结束可以保存了 | ||
36 | - int frameCount; | ||
37 | - bool isupdate; | ||
38 | - int lost; | ||
39 | - DxGPUFrame snapShot; | ||
40 | - DxGPUFrame snapShotLittle; | ||
41 | - sy_rect obj_pos; | ||
42 | - double confidence; // 置信度 | ||
43 | - float last_area; | ||
44 | - float max_area; | ||
45 | - OBJ_INDEX index; | ||
46 | - | ||
47 | - bitset< EDGESIZE > flags; //标志位,标记快照框应该如何判断,left:0 top:1 right:2 bottom:3 | ||
48 | - sy_point landmark_point[25];//人脸关键点位置信息 | ||
49 | - sy_rect position; //检测实际目标框 | ||
50 | - //-added by zsh 220719 人脸姿态角- | ||
51 | - float roll = 0.0; | ||
52 | - float yaw = 0.0; | ||
53 | - float pitch = 0.0; | ||
54 | - //------------------------------- | ||
55 | - | ||
56 | -}; | ||
57 | - | ||
58 | 25 | ||
59 | int CreateDir(char *pszDir); | 26 | int CreateDir(char *pszDir); |
60 | void CreateResultFolder(char* resultFolder, const char* jointFolder); | 27 | void CreateResultFolder(char* resultFolder, const char* jointFolder); |
@@ -68,7 +35,7 @@ void CreateResultFolder(char* resultFolder, const char* jointFolder); | @@ -68,7 +35,7 @@ void CreateResultFolder(char* resultFolder, const char* jointFolder); | ||
68 | bool snapshot_legal_inarea(int width, int height); | 35 | bool snapshot_legal_inarea(int width, int height); |
69 | bool snapshot_legal_inarea(sy_rect algor_area, int left, int top, int right, int bottom); | 36 | bool snapshot_legal_inarea(sy_rect algor_area, int left, int top, int right, int bottom); |
70 | bool snapshot_legal_minarea(int index, int width, int height); | 37 | bool snapshot_legal_minarea(int index, int width, int height); |
71 | -bool snapshot_algor_open_config(const OBJ_KEY& obj_key); | 38 | +// bool snapshot_algor_open_config(const OBJ_KEY& obj_key); |
72 | bool snapshot_legal_pos(bitset<EDGESIZE> flags, int left, int top, int right, int bottom, int image_width, int image_height); | 39 | bool snapshot_legal_pos(bitset<EDGESIZE> flags, int left, int top, int right, int bottom, int image_width, int image_height); |
73 | bool snapshot_legal_area(int max_area, int last_area, int left, int top, int right, int bottom); | 40 | bool snapshot_legal_area(int max_area, int last_area, int left, int top, int right, int bottom); |
74 | bool snapshot_legal_pose(float last_roll, float last_yaw, float last_pitch, float roll, float yaw, float pitch); // added by zsh 220719 判断人脸姿态角 | 41 | bool snapshot_legal_pose(float last_roll, float last_yaw, float last_pitch, float roll, float yaw, float pitch); // added by zsh 220719 判断人脸姿态角 |
src/decoder/dvpp/CircularQueue.hpp
@@ -77,7 +77,7 @@ template <typename T> | @@ -77,7 +77,7 @@ template <typename T> | ||
77 | void CircularQueue<T>::addTail() | 77 | void CircularQueue<T>::addTail() |
78 | { | 78 | { |
79 | std::lock_guard<std::mutex> l(m_mutex); | 79 | std::lock_guard<std::mutex> l(m_mutex); |
80 | - rear = (rear + 1) % max_size;//队尾指针加1 | 80 | + rear = (rear + 1) % max_size;//队尾指针加1 |
81 | } | 81 | } |
82 | 82 | ||
83 | //循环队列的出队 | 83 | //循环队列的出队 |
src/decoder/dvpp/DvppDec.cpp
@@ -446,8 +446,10 @@ int DvppDec::sentFrame(aclvdecChannelDesc *vdecChannelDesc, uint64_t frame_count | @@ -446,8 +446,10 @@ int DvppDec::sentFrame(aclvdecChannelDesc *vdecChannelDesc, uint64_t frame_count | ||
446 | CHECK_NOT_RETURN(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed"); | 446 | CHECK_NOT_RETURN(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed"); |
447 | } | 447 | } |
448 | 448 | ||
449 | - acldvppFree(vdecOutputBuf); | ||
450 | - vdecOutputBuf = nullptr; | 449 | + if (vdecOutputBuf){ |
450 | + acldvppFree(vdecOutputBuf); | ||
451 | + vdecOutputBuf = nullptr; | ||
452 | + } | ||
451 | 453 | ||
452 | return 1; | 454 | return 1; |
453 | } | 455 | } |
src/decoder/dvpp/FFReceiver.cpp
@@ -160,12 +160,10 @@ void FFReceiver::read_thread(){ | @@ -160,12 +160,10 @@ void FFReceiver::read_thread(){ | ||
160 | 160 | ||
161 | int frame_count = 0; | 161 | int frame_count = 0; |
162 | int ret = -1; | 162 | int ret = -1; |
163 | - while (m_bRunning) | ||
164 | - { | ||
165 | - if (!m_bReal) | ||
166 | - { | ||
167 | - if (m_bPause) | ||
168 | - { | 163 | + while (m_bRunning){ |
164 | + | ||
165 | + if (!m_bReal){ | ||
166 | + if (m_bPause){ | ||
169 | std::this_thread::sleep_for(std::chrono::milliseconds(3)); | 167 | std::this_thread::sleep_for(std::chrono::milliseconds(3)); |
170 | continue; | 168 | continue; |
171 | } | 169 | } |
@@ -178,8 +176,8 @@ void FFReceiver::read_thread(){ | @@ -178,8 +176,8 @@ void FFReceiver::read_thread(){ | ||
178 | } | 176 | } |
179 | 177 | ||
180 | int result = av_read_frame(fmt_ctx, pkt); | 178 | int result = av_read_frame(fmt_ctx, pkt); |
181 | - if (result == AVERROR_EOF || result < 0) | ||
182 | - { | 179 | + if (result == AVERROR_EOF || result < 0){ |
180 | + av_packet_unref(pkt); | ||
183 | LOG_ERROR("[{}]- Failed to read frame!", m_dec_name); | 181 | LOG_ERROR("[{}]- Failed to read frame!", m_dec_name); |
184 | break; | 182 | break; |
185 | } | 183 | } |
@@ -210,6 +208,9 @@ void FFReceiver::read_thread(){ | @@ -210,6 +208,9 @@ void FFReceiver::read_thread(){ | ||
210 | 208 | ||
211 | frame_count++; | 209 | frame_count++; |
212 | } | 210 | } |
211 | + } else { | ||
212 | + // 音频等其他分量的情形 | ||
213 | + av_packet_unref(pkt); | ||
213 | } | 214 | } |
214 | } | 215 | } |
215 | 216 |
src/demo/demo.cpp
@@ -478,8 +478,8 @@ static long long get_cur_time(){ | @@ -478,8 +478,8 @@ static long long get_cur_time(){ | ||
478 | string createTask(void *handle, std::vector<algorithm_type_t> algor_vec, int gi){ | 478 | string createTask(void *handle, std::vector<algorithm_type_t> algor_vec, int gi){ |
479 | task_param tparam; | 479 | task_param tparam; |
480 | // tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.108:554/cam/realmonitor?channel=1&subtype=0"; | 480 | // tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.108:554/cam/realmonitor?channel=1&subtype=0"; |
481 | - // tparam.ipc_url = "/home/huchunming/data/caishenkezhan.mp4"; | ||
482 | - tparam.ipc_url = "/home/cmhu/data/Street.uvf"; | 481 | + tparam.ipc_url = "/home/cmhu/data/bayue.mp4"; |
482 | + // tparam.ipc_url = "/home/cmhu/data/Street.uvf"; | ||
483 | // tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/V5nXRHa?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiMTBjZjM4N2JjY2Y5NDg3YzhjNWYzNjE2M2ViMWUyNTJ8MXwwfDEiLCJ0IjoxfQ=="; | 483 | // tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/V5nXRHa?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiMTBjZjM4N2JjY2Y5NDg3YzhjNWYzNjE2M2ViMWUyNTJ8MXwwfDEiLCJ0IjoxfQ=="; |
484 | tparam.algor_counts = algor_vec.size(); | 484 | tparam.algor_counts = algor_vec.size(); |
485 | tparam.dec_type = 2; | 485 | tparam.dec_type = 2; |
@@ -525,8 +525,8 @@ void test_gpu(int gpuID){ | @@ -525,8 +525,8 @@ void test_gpu(int gpuID){ | ||
525 | algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT}; | 525 | algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT}; |
526 | 526 | ||
527 | string task_id = createTask(handle, algor_vec, 0 + gpuID * 10); | 527 | string task_id = createTask(handle, algor_vec, 0 + gpuID * 10); |
528 | - string task_id1 = createTask(handle, algor_vec, 1 + gpuID * 10); | ||
529 | - string task_id2 = createTask(handle, algor_vec, 2 + gpuID * 10); | 528 | + // string task_id1 = createTask(handle, algor_vec, 1 + gpuID * 10); |
529 | + // string task_id2 = createTask(handle, algor_vec, 2 + gpuID * 10); | ||
530 | 530 | ||
531 | 531 | ||
532 | // finish_task(handle, (char*)task_id.data(), 0); | 532 | // finish_task(handle, (char*)task_id.data(), 0); |
@@ -549,7 +549,9 @@ int main(int argc, char *argv[]) { | @@ -549,7 +549,9 @@ int main(int argc, char *argv[]) { | ||
549 | int gpuID = atoi(argv[4]); | 549 | int gpuID = atoi(argv[4]); |
550 | 550 | ||
551 | test_gpu(0); | 551 | test_gpu(0); |
552 | - test_gpu(1); | 552 | + // test_gpu(1); |
553 | + // test_gpu(2); | ||
554 | + // test_gpu(3); | ||
553 | 555 | ||
554 | while (getchar() != 'q'); | 556 | while (getchar() != 'q'); |
555 | 557 |
src/reprocessing_module/save_snapshot_reprocessing.h
@@ -31,6 +31,7 @@ struct ImgSaveInfo{ | @@ -31,6 +31,7 @@ struct ImgSaveInfo{ | ||
31 | string file_path {""}; | 31 | string file_path {""}; |
32 | vpc_img_info img_info; | 32 | vpc_img_info img_info; |
33 | string json_str {""}; | 33 | string json_str {""}; |
34 | + sy_rect obj_rect; | ||
34 | }; | 35 | }; |
35 | 36 | ||
36 | class save_snapshot_reprocessing | 37 | class save_snapshot_reprocessing |
src/reprocessing_module/snapshot_reprocessing.cpp
@@ -5,13 +5,20 @@ | @@ -5,13 +5,20 @@ | ||
5 | #include "../decoder/interface/DeviceMemory.hpp" | 5 | #include "../decoder/interface/DeviceMemory.hpp" |
6 | 6 | ||
7 | 7 | ||
8 | -snapshot_reprocessing::snapshot_reprocessing() | 8 | +snapshot_reprocessing::snapshot_reprocessing(int devId) |
9 | { | 9 | { |
10 | m_task_param_manager = task_param_manager::getInstance(); | 10 | m_task_param_manager = task_param_manager::getInstance(); |
11 | 11 | ||
12 | algor_index_table["human"] = { (int)det_class_label_t::HUMAN }; | 12 | algor_index_table["human"] = { (int)det_class_label_t::HUMAN }; |
13 | algor_index_table["nonmotor_vehicle"] = { (int)det_class_label_t::BICYCLE, (int)det_class_label_t::MOTOCYCLE, (int)det_class_label_t::TRICYCLE }; | 13 | algor_index_table["nonmotor_vehicle"] = { (int)det_class_label_t::BICYCLE, (int)det_class_label_t::MOTOCYCLE, (int)det_class_label_t::TRICYCLE }; |
14 | algor_index_table["vehicle"] = { (int)det_class_label_t::SMALL_CAR, (int)det_class_label_t::LARGE_CAR, (int)det_class_label_t::TRUCK, (int)det_class_label_t::TRACTOR, (int)det_class_label_t::MEDIUM_BUS }; | 14 | algor_index_table["vehicle"] = { (int)det_class_label_t::SMALL_CAR, (int)det_class_label_t::LARGE_CAR, (int)det_class_label_t::TRUCK, (int)det_class_label_t::TRACTOR, (int)det_class_label_t::MEDIUM_BUS }; |
15 | + | ||
16 | + vpcUtil.init(devId); | ||
17 | +} | ||
18 | + | ||
19 | +snapshot_reprocessing::~snapshot_reprocessing() | ||
20 | +{ | ||
21 | + vpcUtil.release(); | ||
15 | } | 22 | } |
16 | 23 | ||
17 | static void box_expansion(video_object_info& obj_info, float expand_ratio, int frame_width, int frame_height){ | 24 | static void box_expansion(video_object_info& obj_info, float expand_ratio, int frame_width, int frame_height){ |
@@ -170,4 +177,216 @@ void snapshot_reprocessing::filter_vehicle(vector<DeviceMemory*> vec_devMem, vec | @@ -170,4 +177,216 @@ void snapshot_reprocessing::filter_vehicle(vector<DeviceMemory*> vec_devMem, vec | ||
170 | _onelevel_det_result[task_idx].obj_count = effective_count; | 177 | _onelevel_det_result[task_idx].obj_count = effective_count; |
171 | task_idx++; | 178 | task_idx++; |
172 | } | 179 | } |
180 | +} | ||
181 | + | ||
182 | +/* 获取人车物目标快照图 */ | ||
183 | +void snapshot_reprocessing::update_bestsnapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id){ | ||
184 | + map<string, algor_open_config_param> && algor_config_param = m_task_param_manager->get_task_algor_params(); | ||
185 | + map<string, map<algo_type, task_param_manager::algo_param_type_t_*>> && algor_param = m_task_param_manager->get_task_other_params(); | ||
186 | + | ||
187 | + for (size_t i = 0; i < vec_devMem.size(); i++){ | ||
188 | + DeviceMemory* memPtr = vec_devMem[i]; | ||
189 | + | ||
190 | + onelevel_det_result det_result = ol_det_result[i]; | ||
191 | + | ||
192 | + if (0 == det_result.obj_count){ | ||
193 | + ++i; | ||
194 | + continue; | ||
195 | + } | ||
196 | + | ||
197 | + string task_id = memPtr->getId(); | ||
198 | + int frame_height = memPtr->getHeight(); | ||
199 | + int frame_width = memPtr->getWidth(); | ||
200 | + | ||
201 | + vector<video_object_info> vec_obj_info; | ||
202 | + for (int c = 0; c < det_result.obj_count; c++){ | ||
203 | + | ||
204 | + det_objinfo obj_info = det_result.obj[c]; | ||
205 | + OBJ_KEY new_obj = { task_id, obj_info.id }; | ||
206 | + | ||
207 | + int index = 0; | ||
208 | + | ||
209 | + /* 投票确定目标index */ | ||
210 | + if (total_snapshot_info.find(new_obj) == total_snapshot_info.end()){ | ||
211 | + index = obj_info.index; | ||
212 | + } else { | ||
213 | + index = total_snapshot_info[new_obj].index.index; | ||
214 | + } | ||
215 | + | ||
216 | + int cur_real_width = (obj_info.right - obj_info.left); | ||
217 | + int cur_real_height = (obj_info.bottom - obj_info.top); | ||
218 | + int cur_real_index = obj_info.index; | ||
219 | + | ||
220 | + int expansion_width = cur_real_width * EXPANSION_PROPORTION; | ||
221 | + int expansion_height = cur_real_height * EXPANSION_PROPORTION; | ||
222 | + // DEBUG----------------------------------------------------------------- | ||
223 | + // 0-行人 1-自行车 2-摩托车 3-三轮车 4-小型车 5-大车 6-卡车 7-拖拉机 8-中巴 | ||
224 | + if(index ==0 || index ==1 || index ==2 || index ==3) { //行人和非机动车外扩指定像素即可 | ||
225 | + expansion_width = 10; | ||
226 | + expansion_height = 10; | ||
227 | + } | ||
228 | + | ||
229 | + /* 若该目标第一次出现 */ | ||
230 | + if (total_snapshot_info.find(new_obj) == total_snapshot_info.end()) | ||
231 | + { | ||
232 | + /* manager insert new object. */ | ||
233 | + /* 判断目标合法 */ | ||
234 | + algorithm_type_t algor_type; | ||
235 | + if (index ==0) algor_type = algorithm_type_t::HUMAN_SNAPSHOT; | ||
236 | + if (index ==1 || index ==2 || index ==3) algor_type = algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT; | ||
237 | + if (index ==4 || index ==5 || index ==6 || index ==7 || index ==8) algor_type = algorithm_type_t::VEHICLE_SNAPSHOT; | ||
238 | + if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algor_type))) | ||
239 | + continue; | ||
240 | + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type]; | ||
241 | + if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom)){ | ||
242 | + continue; | ||
243 | + } | ||
244 | + | ||
245 | + if(!snapshot_legal_minarea(index, cur_real_width, cur_real_height)){ | ||
246 | + continue; | ||
247 | + } | ||
248 | + | ||
249 | + /* 存入当前抠图目标参数 flags用于判断目标从画面什么位置出现 方便之后排除出画面边缘的快照图 */ | ||
250 | + total_snapshot_info[new_obj].index.count++; | ||
251 | + total_snapshot_info[new_obj].index.index = cur_real_index; | ||
252 | + total_snapshot_info[new_obj].confidence = obj_info.confidence; | ||
253 | + total_snapshot_info[new_obj].flags[0] = obj_info.left < minDistance[0] + SCALE_OUT ? 0 : 1; //left | ||
254 | + total_snapshot_info[new_obj].flags[1] = obj_info.top < minDistance[1] + SCALE_OUT ? 0 : 1; //top | ||
255 | + total_snapshot_info[new_obj].flags[2] = obj_info.right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right | ||
256 | + total_snapshot_info[new_obj].flags[3] = obj_info.bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom | ||
257 | + | ||
258 | + int cur_left = max(obj_info.left - 10, 0); | ||
259 | + int cur_top = max(obj_info.top - 10, 0); | ||
260 | + int cur_right = min(obj_info.right + 10, frame_width - 1); | ||
261 | + int cur_bottom = min(obj_info.bottom + 10, frame_height - 1); | ||
262 | + total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 | ||
263 | + total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); | ||
264 | + | ||
265 | + video_object_info info; | ||
266 | + info.left = max(obj_info.left - expansion_width, 0); | ||
267 | + info.top = max(obj_info.top - expansion_height, 0); | ||
268 | + info.right = min(obj_info.right + expansion_width, frame_width - 1); | ||
269 | + info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1); | ||
270 | + strcpy(info.task_id, task_id.c_str()); | ||
271 | + info.object_id = obj_info.id; | ||
272 | + info.confidence = obj_info.confidence; | ||
273 | + info.index = index; | ||
274 | + | ||
275 | + vec_obj_info.push_back(info); | ||
276 | + } else { | ||
277 | + total_snapshot_info[new_obj].last_area = (obj_info.right - obj_info.left) * (obj_info.bottom - obj_info.top); | ||
278 | + | ||
279 | + algorithm_type_t algor_type; | ||
280 | + if (index ==0) algor_type = algorithm_type_t::HUMAN_SNAPSHOT; | ||
281 | + if (index ==1 || index ==2 || index ==3) algor_type = algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT; | ||
282 | + if (index ==4 || index ==5 || index ==6 || index ==7 || index ==8) algor_type = algorithm_type_t::VEHICLE_SNAPSHOT; | ||
283 | + if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algor_type))) | ||
284 | + continue; | ||
285 | + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type]; | ||
286 | + if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom)) | ||
287 | + continue; | ||
288 | + //--------------------------------------------------------------- | ||
289 | + if (!best_snapshot_judge_algor(new_obj, total_snapshot_info[new_obj], obj_info.left, obj_info.top, | ||
290 | + cur_real_width, cur_real_height, frame_width, frame_height)) | ||
291 | + { | ||
292 | + continue; | ||
293 | + } | ||
294 | + /* 若更优于之前的快照 做快照的更新 */ | ||
295 | + if (total_snapshot_info[new_obj].index.count == 0) | ||
296 | + { | ||
297 | + total_snapshot_info[new_obj].index.count++; | ||
298 | + total_snapshot_info[new_obj].index.index = cur_real_index; | ||
299 | + } | ||
300 | + else | ||
301 | + { | ||
302 | + if (total_snapshot_info[new_obj].index.index == cur_real_index) | ||
303 | + total_snapshot_info[new_obj].index.count++; | ||
304 | + else | ||
305 | + total_snapshot_info[new_obj].index.count--; | ||
306 | + } | ||
307 | + | ||
308 | + int cur_left = max(obj_info.left - 10, 0); | ||
309 | + int cur_top = max(obj_info.top - 10, 0); | ||
310 | + int cur_right = min(obj_info.right + 10, frame_width - 1); | ||
311 | + int cur_bottom = min(obj_info.bottom + 10, frame_height - 1); | ||
312 | + total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 | ||
313 | + total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); | ||
314 | + | ||
315 | + video_object_info info; | ||
316 | + info.left = max(obj_info.left - expansion_width, 0); | ||
317 | + info.top = max(obj_info.top - expansion_height, 0); | ||
318 | + info.right = min(obj_info.right + expansion_width, frame_width - 1); | ||
319 | + info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1); | ||
320 | + strcpy(info.task_id, task_id.c_str()); | ||
321 | + info.object_id = obj_info.id; | ||
322 | + info.confidence = obj_info.confidence; | ||
323 | + info.index = index; | ||
324 | + | ||
325 | + vec_obj_info.push_back(info); | ||
326 | + } | ||
327 | + } | ||
328 | + | ||
329 | + vector<vpc_img_info> imgList = vpcUtil.crop_batch(memPtr, vec_obj_info); | ||
330 | + | ||
331 | + if(imgList.size() > 0){ | ||
332 | + for (size_t i = 0; i < imgList.size(); i++) { | ||
333 | + vpc_img_info obj_info = imgList[i]; | ||
334 | + OBJ_KEY objKey = { obj_info.task_id, obj_info.object_id }; | ||
335 | + vpcUtil.vpc_img_release(total_snapshot_info[objKey].snapShot); | ||
336 | + total_snapshot_info[objKey].snapShot = vpcUtil.vpc_devMem2vpcImg(memPtr); | ||
337 | + vpcUtil.vpc_img_release(total_snapshot_info[objKey].snapShotLittle); | ||
338 | + total_snapshot_info[objKey].snapShotLittle = obj_info; | ||
339 | + } | ||
340 | + } | ||
341 | + } | ||
342 | +} | ||
343 | + | ||
344 | +map<OBJ_KEY, OBJ_VALUE> snapshot_reprocessing::get_total_snapshot_info(){ | ||
345 | + return total_snapshot_info; | ||
346 | +} | ||
347 | + | ||
348 | +/* 快照判定辅助函数 */ | ||
349 | +bool snapshot_reprocessing::best_snapshot_judge_algor(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height) | ||
350 | +{ | ||
351 | + return snapshot_legal_pos(obj_value.flags, left, top, left + width, top + height, image_width, image_height) | ||
352 | + && snapshot_legal_minarea(obj_value.index.index, width, height) | ||
353 | + && snapshot_legal_inarea(width, height) | ||
354 | + && snapshot_legal_area(obj_value.max_area, obj_value.last_area, left, top, left + width, top + height); | ||
355 | + return true; | ||
356 | +} | ||
357 | + | ||
358 | +/* 删除指定快照 清空资源占用(使用场景:任务结束删除该路任务所有缓存快照;目标轨迹结束,分析保存完,删除该目标快照缓存)*/ | ||
359 | +void snapshot_reprocessing::release_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease) | ||
360 | +{ | ||
361 | + LOG_DEBUG("[info] task_id {} delete obj_id {}", taskid, obj_id); //221026 | ||
362 | + if (obj_id != -1) | ||
363 | + { | ||
364 | + OBJ_KEY cur_key = { taskid , obj_id }; | ||
365 | + auto it = total_snapshot_info.find(cur_key); | ||
366 | + if (it == total_snapshot_info.end()){ | ||
367 | + return; | ||
368 | + } | ||
369 | + | ||
370 | + if (bRelease){ | ||
371 | + OBJ_VALUE ss = total_snapshot_info[cur_key]; | ||
372 | + | ||
373 | + vpcUtil.vpc_img_release(ss.snapShot); | ||
374 | + vpcUtil.vpc_img_release(ss.snapShotLittle); | ||
375 | + } | ||
376 | + | ||
377 | + total_snapshot_info.erase(cur_key); | ||
378 | + return; | ||
379 | + } | ||
380 | + | ||
381 | + for(auto ss = total_snapshot_info.begin(); ss != total_snapshot_info.end(); ss++) | ||
382 | + { | ||
383 | + if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0) | ||
384 | + { | ||
385 | + if (bRelease){ | ||
386 | + vpcUtil.vpc_img_release(ss->second.snapShot); | ||
387 | + vpcUtil.vpc_img_release(ss->second.snapShotLittle); | ||
388 | + } | ||
389 | + total_snapshot_info.erase(ss); | ||
390 | + } | ||
391 | + } | ||
173 | } | 392 | } |
174 | \ No newline at end of file | 393 | \ No newline at end of file |
src/reprocessing_module/snapshot_reprocessing.h
@@ -9,22 +9,19 @@ | @@ -9,22 +9,19 @@ | ||
9 | 9 | ||
10 | #include "../ai_platform/det_obj_header.h" | 10 | #include "../ai_platform/det_obj_header.h" |
11 | #include <vector> | 11 | #include <vector> |
12 | -#include <set> | ||
13 | #include <string> | 12 | #include <string> |
14 | #include <map> | 13 | #include <map> |
15 | #include <bitset> | 14 | #include <bitset> |
16 | #include "../ai_platform/task_param_manager.h" | 15 | #include "../ai_platform/task_param_manager.h" |
17 | #include "../ai_platform/header.h" | 16 | #include "../ai_platform/header.h" |
17 | +#include "../util/vpc_util.h" | ||
18 | 18 | ||
19 | // #define EXPANSION_PROPORTION 0.1 | 19 | // #define EXPANSION_PROPORTION 0.1 |
20 | #define EXPANSION_PROPORTION 0.25 | 20 | #define EXPANSION_PROPORTION 0.25 |
21 | #define FACE_EXPANSION_PROPORTION 0.5 | 21 | #define FACE_EXPANSION_PROPORTION 0.5 |
22 | #define IMG_CHANNELS 3 | 22 | #define IMG_CHANNELS 3 |
23 | 23 | ||
24 | -// using namespace std; | ||
25 | -using std::vector; | ||
26 | -using std::map; | ||
27 | -using std::set; | 24 | +using namespace std; |
28 | 25 | ||
29 | class DeviceMemory; | 26 | class DeviceMemory; |
30 | 27 | ||
@@ -35,27 +32,56 @@ typedef struct multi_obj_data_t{ | @@ -35,27 +32,56 @@ typedef struct multi_obj_data_t{ | ||
35 | string task_id; | 32 | string task_id; |
36 | } multi_obj_data_t; | 33 | } multi_obj_data_t; |
37 | 34 | ||
35 | + | ||
36 | +struct OBJ_VALUE { | ||
37 | + bool finishTracker; //轨迹结束可以保存了 | ||
38 | + int frameCount; | ||
39 | + bool isupdate; | ||
40 | + int lost; | ||
41 | + vpc_img_info snapShot; | ||
42 | + vpc_img_info snapShotLittle; | ||
43 | + sy_rect obj_pos; | ||
44 | + double confidence; // 置信度 | ||
45 | + float last_area; | ||
46 | + float max_area; | ||
47 | + OBJ_INDEX index; | ||
48 | + | ||
49 | + bitset< EDGESIZE > flags; //标志位,标记快照框应该如何判断,left:0 top:1 right:2 bottom:3 | ||
50 | + sy_point landmark_point[25];//人脸关键点位置信息 | ||
51 | + sy_rect position; //检测实际目标框 | ||
52 | + //-added by zsh 220719 人脸姿态角- | ||
53 | + float roll = 0.0; | ||
54 | + float yaw = 0.0; | ||
55 | + float pitch = 0.0; | ||
56 | + //------------------------------- | ||
57 | + | ||
58 | +}; | ||
59 | + | ||
38 | class snapshot_reprocessing | 60 | class snapshot_reprocessing |
39 | { | 61 | { |
40 | public: | 62 | public: |
41 | //更新最优快照 | 63 | //更新最优快照 |
42 | - static snapshot_reprocessing* getInstance() | ||
43 | - { | ||
44 | - static snapshot_reprocessing snapshot_reprocessing_instance; | ||
45 | - return &snapshot_reprocessing_instance; | ||
46 | - } | 64 | + snapshot_reprocessing(int devId); |
65 | + ~snapshot_reprocessing(); | ||
47 | 66 | ||
48 | vector<multi_obj_data_t> get_vehicle_snapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& ol_det_result, int skip_frame); | 67 | vector<multi_obj_data_t> get_vehicle_snapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& ol_det_result, int skip_frame); |
49 | 68 | ||
69 | + void screen_effective_snapshot(const vector<string> &taskid_inplay, vector<onelevel_det_result> &_onelevel_det_result); | ||
70 | + void filter_vehicle(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &_onelevel_det_result); | ||
71 | + | ||
72 | + void update_bestsnapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id); | ||
73 | + map<OBJ_KEY, OBJ_VALUE> get_total_snapshot_info(); | ||
74 | + | ||
75 | + void release_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease); | ||
76 | + | ||
77 | +private: | ||
78 | + bool best_snapshot_judge_algor(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height); | ||
79 | + | ||
50 | private: | 80 | private: |
51 | - snapshot_reprocessing(); | 81 | + map<OBJ_KEY, OBJ_VALUE> total_snapshot_info; |
52 | 82 | ||
53 | map<string, set<int>> algor_index_table; | 83 | map<string, set<int>> algor_index_table; |
54 | task_param_manager *m_task_param_manager; | 84 | task_param_manager *m_task_param_manager; |
55 | 85 | ||
56 | -public: | ||
57 | - | ||
58 | - void screen_effective_snapshot(const vector<string> &taskid_inplay, vector<onelevel_det_result> &_onelevel_det_result); | ||
59 | - void filter_vehicle(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &_onelevel_det_result); | ||
60 | - | 86 | + VPCUtil vpcUtil; |
61 | }; | 87 | }; |
62 | \ No newline at end of file | 88 | \ No newline at end of file |
src/util/crop_process.cpp deleted
1 | -/** | ||
2 | -* @file dvpp_process.cpp | ||
3 | -* | ||
4 | -* Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved. | ||
5 | -* | ||
6 | -* This program is distributed in the hope that it will be useful, | ||
7 | -* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
8 | -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
9 | -*/ | ||
10 | -#include "crop_process.h" | ||
11 | -#include <stdio.h> | ||
12 | -#include <vector> | ||
13 | -#include <string> | ||
14 | -#include <memory> | ||
15 | -#include <stdlib.h> | ||
16 | -#include "utils.h" | ||
17 | -#include "acl/acl_base.h" | ||
18 | -#include "acl/acl_rt.h" | ||
19 | -#include "acl/acl_op.h" | ||
20 | -#include "acl/acl_mdl.h" | ||
21 | -#include "acl/ops/acl_dvpp.h" | ||
22 | -#include "acl/ops/acl_cblas.h" | ||
23 | -#include "../decoder/interface/DeviceMemory.hpp" | ||
24 | - | ||
25 | -using namespace std; | ||
26 | - | ||
27 | -namespace { | ||
28 | - uint32_t AlignSize(uint32_t origSize, uint32_t alignment) | ||
29 | - { | ||
30 | - if (alignment == 0) { | ||
31 | - return 0; | ||
32 | - } | ||
33 | - uint32_t alignmentH = alignment - 1; | ||
34 | - return (origSize + alignmentH) / alignment * alignment; | ||
35 | - } | ||
36 | -} | ||
37 | - | ||
38 | -DvppCropProcess::DvppCropProcess() | ||
39 | - : dvppChannelDesc_(nullptr), inputBatchPicDesc_(nullptr), | ||
40 | - outputBatchPicDesc_(nullptr), inputBatchSize_(0), outputBatchSize_(0) | ||
41 | -{ | ||
42 | -} | ||
43 | - | ||
44 | -DvppCropProcess::~DvppCropProcess() | ||
45 | -{ | ||
46 | - DestroyBatchCropResource(); | ||
47 | -} | ||
48 | - | ||
49 | -Result DvppCropProcess::InitProcess() | ||
50 | -{ | ||
51 | - // create vpc channel description | ||
52 | - dvppChannelDesc_ = acldvppCreateChannelDesc(); | ||
53 | - if (dvppChannelDesc_ == nullptr) { | ||
54 | - ERROR_LOG("acldvppCreateChannelDesc failed"); | ||
55 | - return FAILED; | ||
56 | - } | ||
57 | - | ||
58 | - // create vpc channel | ||
59 | - aclError aclRet = acldvppCreateChannel(dvppChannelDesc_); | ||
60 | - if (aclRet != ACL_SUCCESS) { | ||
61 | - ERROR_LOG("acldvppCreateChannel failed, errorCode = %d", static_cast<int32_t>(aclRet)); | ||
62 | - return FAILED; | ||
63 | - } | ||
64 | - | ||
65 | - // create dvpp resize config | ||
66 | - resizeConfig_ = acldvppCreateResizeConfig(); | ||
67 | - if (resizeConfig_ == nullptr) { | ||
68 | - ERROR_LOG("acldvppCreateResizeConfig failed"); | ||
69 | - return FAILED; | ||
70 | - } | ||
71 | - | ||
72 | - INFO_LOG("dvpp init resource success"); | ||
73 | - return SUCCESS; | ||
74 | -} | ||
75 | - | ||
76 | -Result DvppCropProcess::InitBatchCropInputDesc(DeviceMemory *devMem) | ||
77 | -{ | ||
78 | - inputBatchPicDesc_ = acldvppCreateBatchPicDesc(inputBatchSize_); | ||
79 | - if (inputBatchPicDesc_ == nullptr) { | ||
80 | - ERROR_LOG("InitBatchCropInputDesc inBatchPicDesc failed"); | ||
81 | - return FAILED; | ||
82 | - } | ||
83 | - | ||
84 | - acldvppBatchPicDesc *inputBatchPicDesc_ = acldvppCreateBatchPicDesc(1); | ||
85 | - acldvppPicDesc *vpcInputDesc_ = acldvppGetPicDesc(inputBatchPicDesc_, 0); | ||
86 | - acldvppSetPicDescData(vpcInputDesc_, devMem->getMem()); | ||
87 | - acldvppSetPicDescFormat(vpcInputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420); | ||
88 | - acldvppSetPicDescWidth(vpcInputDesc_, devMem->getWidth()); | ||
89 | - acldvppSetPicDescHeight(vpcInputDesc_, devMem->getHeight()); | ||
90 | - acldvppSetPicDescWidthStride(vpcInputDesc_, devMem->getWidthStride()); | ||
91 | - acldvppSetPicDescHeightStride(vpcInputDesc_, devMem->getHeightStride()); | ||
92 | - acldvppSetPicDescSize(vpcInputDesc_, devMem->getSize()); | ||
93 | - | ||
94 | - // if (inputBatchSize_ > batchInput_.size()) { | ||
95 | - // inputBatchSize_ = batchInput_.size(); | ||
96 | - // } | ||
97 | - // uint32_t inputWidth = devMem->getWidth(); | ||
98 | - // for (uint32_t i = 0; i < inputBatchSize_; i++) { | ||
99 | - // vecInPtr_.push_back(inputBufferDev); | ||
100 | - // acldvppPicDesc *vpcInputDesc = acldvppGetPicDesc(inputBatchPicDesc_, i); | ||
101 | - // (void)acldvppSetPicDescData(vpcInputDesc, devMem->getMem()); | ||
102 | - // (void)acldvppSetPicDescFormat(vpcInputDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420); | ||
103 | - // (void)acldvppSetPicDescWidth(vpcInputDesc, batchInput_[i].inputWidth); | ||
104 | - // (void)acldvppSetPicDescHeight(vpcInputDesc, batchInput_[i].inputHeight); | ||
105 | - // (void)acldvppSetPicDescWidthStride(vpcInputDesc, inputWidthStride_); | ||
106 | - // (void)acldvppSetPicDescHeightStride(vpcInputDesc, inputHeightStride_); | ||
107 | - // (void)acldvppSetPicDescSize(vpcInputDesc, inputBufferSize); | ||
108 | - // INFO_LOG("set inputDesc success."); | ||
109 | - // } | ||
110 | - return SUCCESS; | ||
111 | -} | ||
112 | - | ||
113 | -Result DvppCropProcess::InitBatchCropOutputDesc(vector<video_object_info> objs) | ||
114 | -{ | ||
115 | - const uint32_t widthAlignment = 16; | ||
116 | - const uint32_t heightAlignment = 16; | ||
117 | - const uint32_t sizeAlignment = 3; | ||
118 | - const uint32_t sizeNum = 2; | ||
119 | - | ||
120 | - outputBatchPicDesc_ = acldvppCreateBatchPicDesc(outputBatchSize_); | ||
121 | - if (outputBatchPicDesc_ == nullptr) { | ||
122 | - ERROR_LOG("acldvppCreatePicDesc outBatchPicDesc failed"); | ||
123 | - return FAILED; | ||
124 | - } | ||
125 | - acldvppPicDesc *vpcOutputDesc = nullptr; | ||
126 | - for (uint32_t i = 0; i < outputBatchSize_; i++) { | ||
127 | - video_object_info obj = objs[i]; | ||
128 | - | ||
129 | - int outputWidth_ = obj.right - obj.left; | ||
130 | - int outputHeight_ = obj.bottom - obj.top; | ||
131 | - int modelInputLeft = obj.left; | ||
132 | - int modelInputTop = obj.top; | ||
133 | - | ||
134 | - uint32_t outputWidthStride = AlignSize(outputWidth_, widthAlignment); | ||
135 | - uint32_t outputHeightStride = AlignSize(outputHeight_, heightAlignment); | ||
136 | - uint32_t outputBufferSize = outputWidthStride * outputHeightStride * sizeAlignment / sizeNum; | ||
137 | - | ||
138 | - void *vpcBatchOutputBufferDev = nullptr; | ||
139 | - auto ret = acldvppMalloc(&vpcBatchOutputBufferDev, outputBufferSize); | ||
140 | - if (ret != ACL_SUCCESS) { | ||
141 | - ERROR_LOG("acldvppMalloc failed, size = %u, errorCode = %d.", | ||
142 | - outputBufferSize, static_cast<int32_t>(ret)); | ||
143 | - return FAILED; | ||
144 | - } | ||
145 | - vecOutPtr_.push_back(vpcBatchOutputBufferDev); | ||
146 | - vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i); | ||
147 | - (void)acldvppSetPicDescData(vpcOutputDesc, vpcBatchOutputBufferDev); | ||
148 | - (void)acldvppSetPicDescFormat(vpcOutputDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420); | ||
149 | - (void)acldvppSetPicDescWidth(vpcOutputDesc, outputWidth_); | ||
150 | - (void)acldvppSetPicDescHeight(vpcOutputDesc, outputHeight_); | ||
151 | - (void)acldvppSetPicDescWidthStride(vpcOutputDesc, outputWidthStride); | ||
152 | - (void)acldvppSetPicDescHeightStride(vpcOutputDesc, outputHeightStride); | ||
153 | - (void)acldvppSetPicDescSize(vpcOutputDesc, outputBufferSize); | ||
154 | - } | ||
155 | - return SUCCESS; | ||
156 | -} | ||
157 | - | ||
158 | -static Result dvpp_jpege_save(char* pcData , uint32_t dataLen, string out_file_name) | ||
159 | -{ | ||
160 | - FILE* fd = nullptr; | ||
161 | - fd = fopen(out_file_name.c_str(), "wb"); | ||
162 | - if (fd == nullptr) { | ||
163 | - printf("open output file err\n"); | ||
164 | - return FAILED; | ||
165 | - } | ||
166 | - | ||
167 | - fwrite(pcData, dataLen, 1, fd); | ||
168 | - fflush(fd); | ||
169 | - | ||
170 | - fclose(fd); | ||
171 | - return SUCCESS; | ||
172 | -} | ||
173 | - | ||
174 | -static void dvpp_jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name){ | ||
175 | - | ||
176 | - // 2.运行管理资源申请(依次申请Device、Context、Stream) | ||
177 | - aclrtContext context_; | ||
178 | - aclrtStream stream_; | ||
179 | - aclrtSetDevice(0); | ||
180 | - aclrtCreateContext(&context_, 0); | ||
181 | - aclrtCreateStream(&stream_); | ||
182 | - | ||
183 | - // 3.创建图片数据处理通道时的通道描述信息,dvppChannelDesc_是acldvppChannelDesc类型 | ||
184 | - acldvppChannelDesc *dvppChannelDesc_ = acldvppCreateChannelDesc(); | ||
185 | - | ||
186 | - // 4.创建图片数据处理的通道 | ||
187 | - aclError aclRet = acldvppCreateChannel(dvppChannelDesc_); | ||
188 | - | ||
189 | - // 7. 创建图片编码配置数据,设置编码质量 | ||
190 | - // 编码质量范围[0, 100],其中level 0编码质量与level 100差不多,而在[1, 100]内数值越小输出图片质量越差。 | ||
191 | - acldvppJpegeConfig *jpegeConfig_ = acldvppCreateJpegeConfig(); | ||
192 | - acldvppSetJpegeConfigLevel(jpegeConfig_, 100); | ||
193 | - | ||
194 | - // 8. 申请输出内存,申请Device内存encodeOutBufferDev_,存放编码后的输出数据 | ||
195 | - uint32_t outBufferSize= 0; | ||
196 | - int ret = acldvppJpegPredictEncSize(encodeInputDesc_, jpegeConfig_, &outBufferSize); | ||
197 | - void *encodeOutBufferDev_ = nullptr; | ||
198 | - ret = acldvppMalloc(&encodeOutBufferDev_, outBufferSize); | ||
199 | - | ||
200 | - // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 | ||
201 | - aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, | ||
202 | - &outBufferSize, jpegeConfig_, stream_); | ||
203 | - aclRet = aclrtSynchronizeStream(stream_); | ||
204 | - | ||
205 | - // 该模式下,由于处理结果在Device侧,因此需要调用内存复制接口传输结果数据后,再释放Device侧内存 | ||
206 | - // 申请Host内存outputHostBuffer | ||
207 | - void* outputHostBuffer = malloc(outBufferSize); | ||
208 | - // 通过aclrtMemcpy接口将Device的处理结果数据传输到Host | ||
209 | - aclRet = aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST); | ||
210 | - // 释放掉输入输出的device内存 | ||
211 | - (void)acldvppFree(encodeOutBufferDev_); | ||
212 | - // 数据使用完成后,释放内存 | ||
213 | - dvpp_jpege_save((char*)outputHostBuffer, outBufferSize, out_file_name); | ||
214 | - free(outputHostBuffer); | ||
215 | - | ||
216 | - acldvppDestroyChannel(dvppChannelDesc_); | ||
217 | - (void)acldvppDestroyChannelDesc(dvppChannelDesc_); | ||
218 | - dvppChannelDesc_ = nullptr; | ||
219 | - | ||
220 | - // 11. 释放运行管理资源(依次释放Stream、Context、Device) | ||
221 | - aclrtDestroyStream(stream_); | ||
222 | - aclrtDestroyContext(context_); | ||
223 | - aclrtResetDevice(0); | ||
224 | -} | ||
225 | - | ||
226 | -Result DvppCropProcess::ProcessBatchCrop(DeviceMemory *devMem, vector<video_object_info> objs) | ||
227 | -{ | ||
228 | - inputBatchSize_ = 1; | ||
229 | - outputBatchSize_ = objs.size(); | ||
230 | - | ||
231 | - INFO_LOG("ProcessBatchCrop start."); | ||
232 | - const uint32_t oddNum = 1; | ||
233 | - | ||
234 | - std::unique_ptr<acldvppRoiConfig *[]> | ||
235 | - cropArea(new(std::nothrow) acldvppRoiConfig *[outputBatchSize_ * sizeof(acldvppRoiConfig *)]); | ||
236 | - | ||
237 | - for (uint32_t i = 0; i < outputBatchSize_; i++) { | ||
238 | - video_object_info obj = objs[i]; | ||
239 | - cropArea[i] = acldvppCreateRoiConfig(obj.left, obj.right, obj.top, obj.bottom); | ||
240 | - if (cropArea[i] == nullptr) { | ||
241 | - ERROR_LOG("acldvppCreateRoiConfig cropArea_ failed"); | ||
242 | - return FAILED; | ||
243 | - } | ||
244 | - } | ||
245 | - Result ret = InitBatchCropInputDesc(devMem); | ||
246 | - if (ret != SUCCESS) { | ||
247 | - ERROR_LOG("InitBatchCropInputDesc failed"); | ||
248 | - return FAILED; | ||
249 | - } | ||
250 | - | ||
251 | - ret = InitBatchCropOutputDesc(objs); | ||
252 | - if (ret != SUCCESS) { | ||
253 | - ERROR_LOG("InitBatchCropOutputDesc failed"); | ||
254 | - return FAILED; | ||
255 | - } | ||
256 | - | ||
257 | - // calculate total number of crop image | ||
258 | - uint32_t totalNum = 0; | ||
259 | - std::unique_ptr<uint32_t[]> roiNums(new (std::nothrow) uint32_t[inputBatchSize_]); | ||
260 | - if (roiNums != nullptr){ | ||
261 | - for (int i = 0; i < inputBatchSize_; i++) { | ||
262 | - // crop number of images from one source image is outputBatchSize_ / inputBatchSize_ | ||
263 | - roiNums[i] = outputBatchSize_ / inputBatchSize_; | ||
264 | - totalNum += roiNums[i]; | ||
265 | - } | ||
266 | - } | ||
267 | - // crop number of images from last source image is | ||
268 | - // outputBatchSize_ / inputBatchSize_ + outputBatchSize_ % inputBatchSize_ | ||
269 | - if (outputBatchSize_ % inputBatchSize_ != 0) { | ||
270 | - roiNums[inputBatchSize_ - 1] = (outputBatchSize_ - totalNum) + roiNums[inputBatchSize_ - 1]; | ||
271 | - } | ||
272 | - | ||
273 | - aclError aclRet = acldvppSetResizeConfigInterpolation(resizeConfig_, 0); | ||
274 | - aclRet = acldvppVpcBatchCropResizeAsync(dvppChannelDesc_, inputBatchPicDesc_, | ||
275 | - roiNums.get(), inputBatchSize_, | ||
276 | - outputBatchPicDesc_, cropArea.get(), resizeConfig_, stream_); | ||
277 | - if (aclRet != ACL_SUCCESS) { | ||
278 | - ERROR_LOG("acldvppVpcBatchCropAsync failed, errorCode = %d", static_cast<int32_t>(aclRet)); | ||
279 | - return FAILED; | ||
280 | - } | ||
281 | - | ||
282 | - aclRet = aclrtSynchronizeStream(stream_); | ||
283 | - if (aclRet != ACL_SUCCESS) { | ||
284 | - ERROR_LOG("crop aclrtSynchronizeStream failed, errorCode = %d", static_cast<int32_t>(aclRet)); | ||
285 | - return FAILED; | ||
286 | - } | ||
287 | - | ||
288 | - for (uint32_t i = 0; i < outputBatchSize_; i++) { | ||
289 | - acldvppPicDesc *vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i); | ||
290 | - string file_name = "output"; | ||
291 | - file_name = file_name + to_string(i) + ".jpg"; | ||
292 | - dvpp_jpeg_encode(vpcOutputDesc, file_name); | ||
293 | - } | ||
294 | - | ||
295 | - for (uint32_t i = 0; i < outputBatchSize_; i++) { | ||
296 | - if (cropArea[i] != nullptr) { | ||
297 | - (void)acldvppDestroyRoiConfig(cropArea[i]); | ||
298 | - cropArea[i] = nullptr; | ||
299 | - } | ||
300 | - } | ||
301 | - INFO_LOG("ProcessBatchCrop success."); | ||
302 | - return SUCCESS; | ||
303 | -} | ||
304 | - | ||
305 | -void DvppCropProcess::DestroyBatchCropResource() | ||
306 | -{ | ||
307 | - INFO_LOG("DestroyBatchCropResource start."); | ||
308 | - | ||
309 | - if (inputBatchPicDesc_ != nullptr) { | ||
310 | - (void)acldvppDestroyBatchPicDesc(inputBatchPicDesc_); | ||
311 | - inputBatchPicDesc_ = nullptr; | ||
312 | - } | ||
313 | - for (auto ptr : vecOutPtr_) { | ||
314 | - if (ptr != nullptr) { | ||
315 | - (void)acldvppFree(ptr); | ||
316 | - } | ||
317 | - } | ||
318 | - vecOutPtr_.clear(); | ||
319 | - if (outputBatchPicDesc_ != nullptr) { | ||
320 | - (void)acldvppDestroyBatchPicDesc(outputBatchPicDesc_); | ||
321 | - outputBatchPicDesc_ = nullptr; | ||
322 | - } | ||
323 | - if (dvppChannelDesc_ != nullptr) { | ||
324 | - aclError aclRet = acldvppDestroyChannel(dvppChannelDesc_); | ||
325 | - if (aclRet != ACL_SUCCESS) { | ||
326 | - ERROR_LOG("acldvppDestroyChannel failed, errorCode = %d", static_cast<int32_t>(aclRet)); | ||
327 | - } | ||
328 | - (void)acldvppDestroyChannelDesc(dvppChannelDesc_); | ||
329 | - dvppChannelDesc_ = nullptr; | ||
330 | - } | ||
331 | - | ||
332 | - if (resizeConfig_ != nullptr) { | ||
333 | - (void)acldvppDestroyResizeConfig(resizeConfig_); | ||
334 | - resizeConfig_ = nullptr; | ||
335 | - } | ||
336 | - | ||
337 | - INFO_LOG("DestroyBatchCropResource end."); | ||
338 | - return; | ||
339 | -} | ||
340 | - | ||
341 | -Result DvppCropProcess::init(int deviceId) | ||
342 | -{ | ||
343 | - deviceId_ = deviceId; | ||
344 | - | ||
345 | - aclError ret; | ||
346 | - // ret = aclInit(NULL); | ||
347 | - // if (ret != ACL_SUCCESS) { | ||
348 | - // ERROR_LOG("acl init failed, errorCode = %d", static_cast<int32_t>(ret)); | ||
349 | - // return FAILED; | ||
350 | - // } | ||
351 | - // INFO_LOG("acl init success"); | ||
352 | - | ||
353 | - // set device | ||
354 | - ret = aclrtSetDevice(deviceId_); | ||
355 | - if (ret != ACL_SUCCESS) { | ||
356 | - ERROR_LOG("acl set device %d failed, errorCode = %d", deviceId_, static_cast<int32_t>(ret)); | ||
357 | - return FAILED; | ||
358 | - } | ||
359 | - INFO_LOG("set device %d success", deviceId_); | ||
360 | - | ||
361 | - // create context (set current) | ||
362 | - ret = aclrtCreateContext(&context_, deviceId_); | ||
363 | - if (ret != ACL_SUCCESS) { | ||
364 | - ERROR_LOG("acl create context failed, deviceId = %d, errorCode = %d", | ||
365 | - deviceId_, static_cast<int32_t>(ret)); | ||
366 | - return FAILED; | ||
367 | - } | ||
368 | - INFO_LOG("create context success"); | ||
369 | - | ||
370 | - // create stream | ||
371 | - ret = aclrtCreateStream(&stream_); | ||
372 | - if (ret != ACL_SUCCESS) { | ||
373 | - ERROR_LOG("acl create stream failed, deviceId = %d, errorCode = %d", | ||
374 | - deviceId_, static_cast<int32_t>(ret)); | ||
375 | - return FAILED; | ||
376 | - } | ||
377 | - INFO_LOG("create stream success"); | ||
378 | - | ||
379 | - InitProcess(); | ||
380 | - | ||
381 | - return SUCCESS; | ||
382 | -} | ||
383 | - | ||
384 | -void DvppCropProcess::DestroyResource() | ||
385 | -{ | ||
386 | - aclError ret; | ||
387 | - if (stream_ != nullptr) { | ||
388 | - ret = aclrtDestroyStream(stream_); | ||
389 | - if (ret != ACL_SUCCESS) { | ||
390 | - ERROR_LOG("destroy stream failed, errorCode = %d", static_cast<int32_t>(ret)); | ||
391 | - } | ||
392 | - stream_ = nullptr; | ||
393 | - } | ||
394 | - INFO_LOG("end to destroy stream"); | ||
395 | - | ||
396 | - if (context_ != nullptr) { | ||
397 | - ret = aclrtDestroyContext(context_); | ||
398 | - if (ret != ACL_SUCCESS) { | ||
399 | - ERROR_LOG("destroy context failed, errorCode = %d", static_cast<int32_t>(ret)); | ||
400 | - } | ||
401 | - context_ = nullptr; | ||
402 | - } | ||
403 | - INFO_LOG("end to destroy context"); | ||
404 | - | ||
405 | - ret = aclrtResetDevice(deviceId_); | ||
406 | - if (ret != ACL_SUCCESS) { | ||
407 | - ERROR_LOG("reset device %d failed, errorCode = %d", deviceId_, static_cast<int32_t>(ret)); | ||
408 | - } | ||
409 | - INFO_LOG("end to reset device %d", deviceId_); | ||
410 | - | ||
411 | - ret = aclFinalize(); | ||
412 | - if (ret != ACL_SUCCESS) { | ||
413 | - ERROR_LOG("finalize acl failed, errorCode = %d", static_cast<int32_t>(ret)); | ||
414 | - } | ||
415 | - INFO_LOG("end to finalize acl"); | ||
416 | -} |
src/util/crop_process.h deleted
1 | -#ifndef ___CROP_PROCESS_H__ | ||
2 | -#define ___CROP_PROCESS_H__ | ||
3 | - | ||
4 | -#include <vector> | ||
5 | -#include "acl/ops/acl_dvpp.h" | ||
6 | -#include "../ai_platform/header.h" | ||
7 | - | ||
8 | -using namespace std; | ||
9 | - | ||
10 | -class DeviceMemory; | ||
11 | - | ||
12 | -typedef enum Result { | ||
13 | - SUCCESS = 0, | ||
14 | - FAILED = 1 | ||
15 | -} Result; | ||
16 | - | ||
17 | -class DvppCropProcess { | ||
18 | -public: | ||
19 | - /** | ||
20 | - * @brief Constructor | ||
21 | - * @param [in] stream: stream | ||
22 | - */ | ||
23 | - DvppCropProcess(); | ||
24 | - | ||
25 | - /** | ||
26 | - * @brief Destructor | ||
27 | - */ | ||
28 | - ~DvppCropProcess(); | ||
29 | - | ||
30 | -public: | ||
31 | - /** | ||
32 | - * @brief Process Batch Crop | ||
33 | - * @return result | ||
34 | - */ | ||
35 | - Result ProcessBatchCrop(DeviceMemory *devMem, vector<video_object_info> objs); | ||
36 | - | ||
37 | - /** | ||
38 | - * @brief init reousce | ||
39 | - * @return result | ||
40 | - */ | ||
41 | - Result init(int deviceId); | ||
42 | - | ||
43 | - | ||
44 | -private: | ||
45 | - /** | ||
46 | - * @brief InitBatchCropInputDesc | ||
47 | - * @return Result | ||
48 | - */ | ||
49 | - Result InitBatchCropInputDesc(DeviceMemory *devMem); | ||
50 | - | ||
51 | - /** | ||
52 | - * @brief InitBatchCropOutputDesc | ||
53 | - * @return Result | ||
54 | - */ | ||
55 | - Result InitBatchCropOutputDesc(vector<video_object_info> objs); | ||
56 | - | ||
57 | - /** | ||
58 | - * @brief DestroyBatchCropResource | ||
59 | - */ | ||
60 | - void DestroyBatchCropResource(); | ||
61 | - | ||
62 | - | ||
63 | - void DestroyResource(); | ||
64 | - | ||
65 | - /** | ||
66 | - * @brief init reousce | ||
67 | - * @return result | ||
68 | - */ | ||
69 | - Result InitProcess(); | ||
70 | - | ||
71 | -private: | ||
72 | - int32_t deviceId_; | ||
73 | - aclrtContext context_; | ||
74 | - aclrtStream stream_; | ||
75 | - | ||
76 | - acldvppChannelDesc *dvppChannelDesc_; | ||
77 | - acldvppResizeConfig *resizeConfig_; | ||
78 | - | ||
79 | - std::vector<void *> vecOutPtr_; | ||
80 | - | ||
81 | - acldvppBatchPicDesc *inputBatchPicDesc_; // vpc input desc | ||
82 | - acldvppBatchPicDesc *outputBatchPicDesc_; // vpc output desc | ||
83 | - | ||
84 | - uint32_t inputBatchSize_; | ||
85 | - uint32_t outputBatchSize_; | ||
86 | -}; | ||
87 | - | ||
88 | -#endif // ___CROP_PROCESS_H__ | ||
89 | \ No newline at end of file | 0 | \ No newline at end of file |
src/util/vpc_util.cpp
@@ -16,14 +16,10 @@ | @@ -16,14 +16,10 @@ | ||
16 | #include "vpc_util.h" | 16 | #include "vpc_util.h" |
17 | #include "JpegUtil.h" | 17 | #include "JpegUtil.h" |
18 | #include "../decoder/interface/DeviceMemory.hpp" | 18 | #include "../decoder/interface/DeviceMemory.hpp" |
19 | +#include "../common/logger.hpp" | ||
19 | 20 | ||
20 | -#define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO] " fmt "\n", ##args) | ||
21 | -#define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN] " fmt "\n", ##args) | ||
22 | -#define ERROR_LOG(fmt, args...) fprintf(stderr, "[ERROR] " fmt "\n", ##args) | ||
23 | 21 | ||
24 | - | ||
25 | - | ||
26 | -void VPCUtil::vpc_crop_release() | 22 | +void VPCUtil::release() |
27 | { | 23 | { |
28 | aclError ret; | 24 | aclError ret; |
29 | // ret = aclrtSetDevice(deviceId_); | 25 | // ret = aclrtSetDevice(deviceId_); |
@@ -35,26 +31,26 @@ void VPCUtil::vpc_crop_release() | @@ -35,26 +31,26 @@ void VPCUtil::vpc_crop_release() | ||
35 | if (stream_ != nullptr) { | 31 | if (stream_ != nullptr) { |
36 | ret = aclrtDestroyStream(stream_); | 32 | ret = aclrtDestroyStream(stream_); |
37 | if (ret != ACL_SUCCESS) { | 33 | if (ret != ACL_SUCCESS) { |
38 | - ERROR_LOG("destroy stream failed"); | 34 | + LOG_ERROR("destroy stream failed"); |
39 | } | 35 | } |
40 | stream_ = nullptr; | 36 | stream_ = nullptr; |
41 | } | 37 | } |
42 | - INFO_LOG("end to destroy stream"); | 38 | + LOG_INFO("end to destroy stream"); |
43 | 39 | ||
44 | if (context_ != nullptr) { | 40 | if (context_ != nullptr) { |
45 | ret = aclrtDestroyContext(context_); | 41 | ret = aclrtDestroyContext(context_); |
46 | if (ret != ACL_SUCCESS) { | 42 | if (ret != ACL_SUCCESS) { |
47 | - ERROR_LOG("destroy context failed"); | 43 | + LOG_ERROR("destroy context failed"); |
48 | } | 44 | } |
49 | context_ = nullptr; | 45 | context_ = nullptr; |
50 | } | 46 | } |
51 | - INFO_LOG("end to destroy context"); | 47 | + LOG_INFO("end to destroy context"); |
52 | 48 | ||
53 | ret = aclrtResetDevice(deviceId_); | 49 | ret = aclrtResetDevice(deviceId_); |
54 | if (ret != ACL_SUCCESS) { | 50 | if (ret != ACL_SUCCESS) { |
55 | - ERROR_LOG("reset device failed"); | 51 | + LOG_ERROR("reset device failed"); |
56 | } | 52 | } |
57 | - INFO_LOG("end to reset device is %d", deviceId_); | 53 | + LOG_INFO("end to reset device is %d", deviceId_); |
58 | } | 54 | } |
59 | 55 | ||
60 | 56 | ||
@@ -109,7 +105,7 @@ int VPCUtil::vpc_crop(acldvppPicDesc *input_pic_desc, video_object_info obj) | @@ -109,7 +105,7 @@ int VPCUtil::vpc_crop(acldvppPicDesc *input_pic_desc, video_object_info obj) | ||
109 | return 0; | 105 | return 0; |
110 | } | 106 | } |
111 | 107 | ||
112 | -int VPCUtil::vpc_crop_init(int32_t devId){ | 108 | +int VPCUtil::init(int32_t devId){ |
113 | deviceId_ = devId; | 109 | deviceId_ = devId; |
114 | 110 | ||
115 | aclError ret; | 111 | aclError ret; |
@@ -140,10 +136,15 @@ static void check_coordinate(uint32_t& cropLeftOffset, uint32_t& cropRightOffset | @@ -140,10 +136,15 @@ static void check_coordinate(uint32_t& cropLeftOffset, uint32_t& cropRightOffset | ||
140 | 136 | ||
141 | } | 137 | } |
142 | 138 | ||
143 | -vector<vpc_img_info> VPCUtil::vpc_crop_batch(DeviceMemory *devMem, vector<video_object_info> objs){ | 139 | +vector<vpc_img_info> VPCUtil::crop_batch(DeviceMemory *devMem, vector<video_object_info> objs){ |
144 | 140 | ||
145 | vector<vpc_img_info> vec_img_info; | 141 | vector<vpc_img_info> vec_img_info; |
146 | 142 | ||
143 | + const uint32_t outputBatchSize_ = objs.size(); | ||
144 | + if(outputBatchSize_ <= 0){ | ||
145 | + return vec_img_info; | ||
146 | + } | ||
147 | + | ||
147 | /* 1.ACL initialization */ | 148 | /* 1.ACL initialization */ |
148 | // aclInit(nullptr); | 149 | // aclInit(nullptr); |
149 | aclError ret; | 150 | aclError ret; |
@@ -161,18 +162,14 @@ vector<vpc_img_info> VPCUtil::vpc_crop_batch(DeviceMemory *devMem, vector<video_ | @@ -161,18 +162,14 @@ vector<vpc_img_info> VPCUtil::vpc_crop_batch(DeviceMemory *devMem, vector<video_ | ||
161 | acldvppSetPicDescHeightStride(vpcInputDesc_, devMem->getHeightStride()); | 162 | acldvppSetPicDescHeightStride(vpcInputDesc_, devMem->getHeightStride()); |
162 | acldvppSetPicDescSize(vpcInputDesc_, devMem->getSize()); | 163 | acldvppSetPicDescSize(vpcInputDesc_, devMem->getSize()); |
163 | 164 | ||
164 | - const uint32_t outputBatchSize_ = objs.size(); | ||
165 | // 输出 | 165 | // 输出 |
166 | acldvppBatchPicDesc *outputBatchPicDesc_ = acldvppCreateBatchPicDesc(outputBatchSize_); | 166 | acldvppBatchPicDesc *outputBatchPicDesc_ = acldvppCreateBatchPicDesc(outputBatchSize_); |
167 | if (outputBatchPicDesc_ == nullptr) { | 167 | if (outputBatchPicDesc_ == nullptr) { |
168 | - ERROR_LOG("acldvppCreatePicDesc outBatchPicDesc failed"); | 168 | + LOG_ERROR("acldvppCreatePicDesc outBatchPicDesc failed"); |
169 | return vec_img_info; | 169 | return vec_img_info; |
170 | } | 170 | } |
171 | vector<void *> vecOutPtr_; | 171 | vector<void *> vecOutPtr_; |
172 | acldvppPicDesc *vpcOutputDesc = nullptr; | 172 | acldvppPicDesc *vpcOutputDesc = nullptr; |
173 | - // acldvppRoiConfig cropAreas[outputBatchSize_]; | ||
174 | - // std::unique_ptr<acldvppRoiConfig *[]> | ||
175 | - // cropAreas(new(std::nothrow) acldvppRoiConfig *[outputBatchSize_ * sizeof(acldvppRoiConfig *)]); | ||
176 | acldvppRoiConfig *cropAreas[outputBatchSize_]; | 173 | acldvppRoiConfig *cropAreas[outputBatchSize_]; |
177 | for (uint32_t i = 0; i < outputBatchSize_; i++) { | 174 | for (uint32_t i = 0; i < outputBatchSize_; i++) { |
178 | video_object_info obj = objs[i]; | 175 | video_object_info obj = objs[i]; |
@@ -199,7 +196,7 @@ vector<vpc_img_info> VPCUtil::vpc_crop_batch(DeviceMemory *devMem, vector<video_ | @@ -199,7 +196,7 @@ vector<vpc_img_info> VPCUtil::vpc_crop_batch(DeviceMemory *devMem, vector<video_ | ||
199 | void *vpcBatchOutputBufferDev = nullptr; | 196 | void *vpcBatchOutputBufferDev = nullptr; |
200 | auto ret = acldvppMalloc(&vpcBatchOutputBufferDev, vpcOutBufferSize_); | 197 | auto ret = acldvppMalloc(&vpcBatchOutputBufferDev, vpcOutBufferSize_); |
201 | if (ret != ACL_SUCCESS) { | 198 | if (ret != ACL_SUCCESS) { |
202 | - ERROR_LOG("acldvppMalloc failed, size = %u, errorCode = %d.", vpcOutBufferSize_, static_cast<int32_t>(ret)); | 199 | + LOG_ERROR("acldvppMalloc failed, size = %u, errorCode = %d.", vpcOutBufferSize_, static_cast<int32_t>(ret)); |
203 | // 释放之前成功的部分 再退出 | 200 | // 释放之前成功的部分 再退出 |
204 | for(int i = 0; i < vecOutPtr_.size(); i++){ | 201 | for(int i = 0; i < vecOutPtr_.size(); i++){ |
205 | if (vecOutPtr_[i] != nullptr){ | 202 | if (vecOutPtr_[i] != nullptr){ |
@@ -304,7 +301,7 @@ vpc_img_info VPCUtil::vpc_devMem2vpcImg(DeviceMemory *devMem){ | @@ -304,7 +301,7 @@ vpc_img_info VPCUtil::vpc_devMem2vpcImg(DeviceMemory *devMem){ | ||
304 | void *devBuffer = nullptr; | 301 | void *devBuffer = nullptr; |
305 | auto ret = acldvppMalloc(&devBuffer, nBufferSize); | 302 | auto ret = acldvppMalloc(&devBuffer, nBufferSize); |
306 | if (ret != ACL_SUCCESS) { | 303 | if (ret != ACL_SUCCESS) { |
307 | - ERROR_LOG("acldvppMalloc failed, size = %u, errorCode = %d.", nBufferSize, static_cast<int32_t>(ret)); | 304 | + LOG_ERROR("acldvppMalloc failed, size = %u, errorCode = %d.", nBufferSize, static_cast<int32_t>(ret)); |
308 | // 这里应释放之前成功的部分 再退出 | 305 | // 这里应释放之前成功的部分 再退出 |
309 | return img_info; | 306 | return img_info; |
310 | } | 307 | } |
src/util/vpc_util.h
@@ -27,15 +27,15 @@ class VPCUtil { | @@ -27,15 +27,15 @@ class VPCUtil { | ||
27 | public: | 27 | public: |
28 | int vpc_crop(acldvppPicDesc *input_pic_desc, video_object_info obj); | 28 | int vpc_crop(acldvppPicDesc *input_pic_desc, video_object_info obj); |
29 | 29 | ||
30 | - int vpc_crop_init(int32_t devId); | 30 | + int init(int32_t devId); |
31 | 31 | ||
32 | - vector<vpc_img_info> vpc_crop_batch(DeviceMemory *devMem, vector<video_object_info> objs); | 32 | + vector<vpc_img_info> crop_batch(DeviceMemory *devMem, vector<video_object_info> objs); |
33 | 33 | ||
34 | void vpc_img_release(vpc_img_info ); | 34 | void vpc_img_release(vpc_img_info ); |
35 | 35 | ||
36 | void vpc_imgList_release(vector<vpc_img_info>& ); | 36 | void vpc_imgList_release(vector<vpc_img_info>& ); |
37 | 37 | ||
38 | - void vpc_crop_release(); | 38 | + void release(); |
39 | 39 | ||
40 | vpc_img_info vpc_devMem2vpcImg(DeviceMemory *devMem); | 40 | vpc_img_info vpc_devMem2vpcImg(DeviceMemory *devMem); |
41 | 41 |