Commit 32f28195f94478b57b8e8dd70d1dd931d40bcfb2

Authored by Hu Chunming
1 parent 43205510

优化vpc图片数据类型转换

.vscode/launch.json
@@ -23,10 +23,10 @@ @@ -23,10 +23,10 @@
23 } 23 }
24 ] 24 ]
25 },{ 25 },{
26 - "name": "test", 26 + "name": "test_face",
27 "type": "cppdbg", 27 "type": "cppdbg",
28 "request": "launch", 28 "request": "launch",
29 - "program": "${workspaceFolder}/bin/test", 29 + "program": "${workspaceFolder}/bin/test_face",
30 "args": ["/opt/cmhu/data/Street.uvf","0", "0", "0"], 30 "args": ["/opt/cmhu/data/Street.uvf","0", "0", "0"],
31 "stopAtEntry": false, 31 "stopAtEntry": false,
32 "cwd": "${workspaceFolder}/bin", 32 "cwd": "${workspaceFolder}/bin",
src/decoder/Makefile
@@ -6,15 +6,16 @@ PROJECT_ROOT= /opt/cmhu/vpt_ascend_arm @@ -6,15 +6,16 @@ PROJECT_ROOT= /opt/cmhu/vpt_ascend_arm
6 DEPEND_DIR = $(PROJECT_ROOT)/bin 6 DEPEND_DIR = $(PROJECT_ROOT)/bin
7 SRC_ROOT = $(PROJECT_ROOT)/src 7 SRC_ROOT = $(PROJECT_ROOT)/src
8 8
9 -TARGET= $(PROJECT_ROOT)/bin/test_recoder 9 +TARGET= $(PROJECT_ROOT)/bin/test_face
10 10
11 THIRDPARTY_ROOT = $(PROJECT_ROOT)/3rdparty 11 THIRDPARTY_ROOT = $(PROJECT_ROOT)/3rdparty
12 SPDLOG_ROOT = $(THIRDPARTY_ROOT)/spdlog-1.9.2/release 12 SPDLOG_ROOT = $(THIRDPARTY_ROOT)/spdlog-1.9.2/release
13 OPENCV_ROOT = $(THIRDPARTY_ROOT)/opencv_4_1 13 OPENCV_ROOT = $(THIRDPARTY_ROOT)/opencv_4_1
14 JSON_ROOT = $(THIRDPARTY_ROOT)/jsoncpp-1.9.5/release 14 JSON_ROOT = $(THIRDPARTY_ROOT)/jsoncpp-1.9.5/release
15 FFMPEG_ROOT = $(THIRDPARTY_ROOT)/ffmpeg-4.4.4/release 15 FFMPEG_ROOT = $(THIRDPARTY_ROOT)/ffmpeg-4.4.4/release
  16 +RABBITMQ_CLIENT_ROOT = $(THIRDPARTY_ROOT)/rabbitmq-c-0.11.0/release
16 17
17 -DEFS = -DENABLE_DVPP_INTERFACE 18 +DEFS = -DENABLE_DVPP_INTERFACE -DWITH_FACE_DET_SS -DPOST_USE_RABBITMQ
18 19
19 include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1/aarch64-linux/include \ 20 include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1/aarch64-linux/include \
20 -I $(SPDLOG_ROOT)/include \ 21 -I $(SPDLOG_ROOT)/include \
@@ -22,6 +23,7 @@ include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1/aarch64-linux/include \ @@ -22,6 +23,7 @@ include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1/aarch64-linux/include \
22 -I $(OPENCV_ROOT)/include \ 23 -I $(OPENCV_ROOT)/include \
23 -I $(JSON_ROOT)/include \ 24 -I $(JSON_ROOT)/include \
24 -I $(FFMPEG_ROOT)/include \ 25 -I $(FFMPEG_ROOT)/include \
  26 + -I $(RABBITMQ_CLIENT_ROOT)/include \
25 27
26 lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \ 28 lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \
27 -L/usr/local/Ascend/ascend-toolkit/latest/lib64 \ 29 -L/usr/local/Ascend/ascend-toolkit/latest/lib64 \
@@ -32,14 +34,25 @@ lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \ @@ -32,14 +34,25 @@ lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \
32 lib=-lacl_dvpp -lascendcl -lacl_dvpp_mpi -lruntime -lascendalog -lc_sec -lmsprofiler -lgert -lmmpa -lascend_hal -lexe_graph -lge_executor -lgraph -lprofapi -lascend_protobuf -lerror_manager -lhybrid_executor -lregister -ldavinci_executor -lge_common -lge_common_base \ 34 lib=-lacl_dvpp -lascendcl -lacl_dvpp_mpi -lruntime -lascendalog -lc_sec -lmsprofiler -lgert -lmmpa -lascend_hal -lexe_graph -lge_executor -lgraph -lprofapi -lascend_protobuf -lerror_manager -lhybrid_executor -lregister -ldavinci_executor -lge_common -lge_common_base \
33 -lplatform -lgraph_base -lqos_manager 35 -lplatform -lgraph_base -lqos_manager
34 36
35 -LIBS= -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ 37 +LIBS= -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \
  38 + -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lhs_motor_process\
  39 + -L $(OPENCV_ROOT)/lib -lopencv_world\
  40 + -L $(JSON_ROOT)/lib -ljsoncpp \
  41 + -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \
  42 + -L $(RABBITMQ_CLIENT_ROOT)/lib/aarch64-linux-gnu -lrabbitmq \
36 43
37 CXXFLAGS= -g -O0 -fPIC $(include_dir) $(lib_dir) $(lib) $(LIBS) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -fvisibility=hidden -Wall -Wno-deprecated -Wdeprecated-declarations -Wl,-Bsymbolic -ldl 44 CXXFLAGS= -g -O0 -fPIC $(include_dir) $(lib_dir) $(lib) $(LIBS) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -fvisibility=hidden -Wall -Wno-deprecated -Wdeprecated-declarations -Wl,-Bsymbolic -ldl
38 45
39 46
40 47
41 -SRCS:=$(wildcard $(SRC_ROOT)/decoder/interface/*.cpp) \ 48 +SRCS:=$(wildcard $(SRC_ROOT)/ai_platform/*.cpp) \
  49 + $(wildcard $(SRC_ROOT)/decoder/interface/*.cpp) \
42 $(wildcard $(SRC_ROOT)/decoder/dvpp/*.cpp) \ 50 $(wildcard $(SRC_ROOT)/decoder/dvpp/*.cpp) \
  51 + $(wildcard $(SRC_ROOT)/ai_engine_module/sort/*.cpp) \
  52 + $(wildcard $(SRC_ROOT)/ai_engine_module/*.cpp) \
  53 + $(wildcard $(SRC_ROOT)/util/*.cpp) \
  54 + $(wildcard $(SRC_ROOT)/reprocessing_module/*.cpp) \
  55 + $(wildcard $(SRC_ROOT)/reprocessing_module/rbmq/*.cpp) \
43 $(wildcard $(SRC_ROOT)/decoder/*.cpp) \ 56 $(wildcard $(SRC_ROOT)/decoder/*.cpp) \
44 57
45 OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) 58 OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS)))
@@ -56,8 +69,26 @@ $(TARGET):$(OBJS) @@ -56,8 +69,26 @@ $(TARGET):$(OBJS)
56 %.o:$(SRC_ROOT)/decoder/interface/%.cpp 69 %.o:$(SRC_ROOT)/decoder/interface/%.cpp
57 $(XX) $(CXXFLAGS) -c $< 70 $(XX) $(CXXFLAGS) -c $<
58 71
  72 +%.o:$(SRC_ROOT)/ai_platform/%.cpp
  73 + $(XX) $(CXXFLAGS) -c $<
  74 +
  75 +%.o:$(SRC_ROOT)/ai_engine_module/sort/%.cpp
  76 + $(XX) $(CXXFLAGS) -c $<
  77 +
  78 +%.o:$(SRC_ROOT)/ai_engine_module/%.cpp
  79 + $(XX) $(CXXFLAGS) -c $<
  80 +
  81 +%.o:$(SRC_ROOT)/util/%.cpp
  82 + $(XX) $(CXXFLAGS) -c $<
  83 +
  84 +%.o:$(SRC_ROOT)/reprocessing_module/%.cpp
  85 + $(XX) $(CXXFLAGS) -c $<
  86 +
  87 +%.o:$(SRC_ROOT)/reprocessing_module/rbmq/%.cpp
  88 + $(XX) $(CXXFLAGS) -c $<
  89 +
59 %.o:$(SRC_ROOT)/decoder/%.cpp 90 %.o:$(SRC_ROOT)/decoder/%.cpp
60 $(XX) $(CXXFLAGS) -c $< 91 $(XX) $(CXXFLAGS) -c $<
61 92
62 clean: 93 clean:
63 - rm -f *.o $(TARGET)  
64 \ No newline at end of file 94 \ No newline at end of file
  95 + rm -f *.o $(TARGET)
src/decoder/Makefile_decoder 0 → 100755
  1 +XX = g++
  2 +
  3 +
  4 +PROJECT_ROOT= /opt/cmhu/vpt_ascend_arm
  5 +
  6 +DEPEND_DIR = $(PROJECT_ROOT)/bin
  7 +SRC_ROOT = $(PROJECT_ROOT)/src
  8 +
  9 +TARGET= $(PROJECT_ROOT)/bin/test_recoder
  10 +
  11 +THIRDPARTY_ROOT = $(PROJECT_ROOT)/3rdparty
  12 +SPDLOG_ROOT = $(THIRDPARTY_ROOT)/spdlog-1.9.2/release
  13 +OPENCV_ROOT = $(THIRDPARTY_ROOT)/opencv_4_1
  14 +JSON_ROOT = $(THIRDPARTY_ROOT)/jsoncpp-1.9.5/release
  15 +FFMPEG_ROOT = $(THIRDPARTY_ROOT)/ffmpeg-4.4.4/release
  16 +
  17 +DEFS = -DENABLE_DVPP_INTERFACE
  18 +
  19 +include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1/aarch64-linux/include \
  20 + -I $(SPDLOG_ROOT)/include \
  21 + -I $(SRC_ROOT)/common \
  22 + -I $(OPENCV_ROOT)/include \
  23 + -I $(JSON_ROOT)/include \
  24 + -I $(FFMPEG_ROOT)/include \
  25 +
  26 +lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \
  27 + -L/usr/local/Ascend/ascend-toolkit/latest/lib64 \
  28 + -L/usr/local/Ascend/ascend-toolkit/latest/runtime/lib64 \
  29 + -L/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64 \
  30 + -L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64/stub \
  31 +
  32 +lib=-lacl_dvpp -lascendcl -lacl_dvpp_mpi -lruntime -lascendalog -lc_sec -lmsprofiler -lgert -lmmpa -lascend_hal -lexe_graph -lge_executor -lgraph -lprofapi -lascend_protobuf -lerror_manager -lhybrid_executor -lregister -ldavinci_executor -lge_common -lge_common_base \
  33 + -lplatform -lgraph_base -lqos_manager
  34 +
  35 +LIBS= -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \
  36 +
  37 +CXXFLAGS= -g -O0 -fPIC $(include_dir) $(lib_dir) $(lib) $(LIBS) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -fvisibility=hidden -Wall -Wno-deprecated -Wdeprecated-declarations -Wl,-Bsymbolic -ldl
  38 +
  39 +
  40 +
  41 +SRCS:=$(wildcard $(SRC_ROOT)/decoder/interface/*.cpp) \
  42 + $(wildcard $(SRC_ROOT)/decoder/dvpp/*.cpp) \
  43 + $(wildcard $(SRC_ROOT)/decoder/*.cpp) \
  44 +
  45 +OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS)))
  46 +
  47 +
  48 +$(TARGET):$(OBJS)
  49 + rm -f $(TARGET)
  50 + $(XX) -o $@ $^ $(CXXFLAGS)
  51 + rm -f *.o
  52 +
  53 +%.o:$(SRC_ROOT)/decoder/dvpp/%.cpp
  54 + $(XX) $(CXXFLAGS) -c $<
  55 +
  56 +%.o:$(SRC_ROOT)/decoder/interface/%.cpp
  57 + $(XX) $(CXXFLAGS) -c $<
  58 +
  59 +%.o:$(SRC_ROOT)/decoder/%.cpp
  60 + $(XX) $(CXXFLAGS) -c $<
  61 +
  62 +clean:
  63 + rm -f *.o $(TARGET)
0 \ No newline at end of file 64 \ No newline at end of file
src/decoder/dvpp/VpcPicConverter.cpp
@@ -13,11 +13,12 @@ VpcPicConverter::~VpcPicConverter(){ @@ -13,11 +13,12 @@ VpcPicConverter::~VpcPicConverter(){
13 } 13 }
14 } 14 }
15 15
16 -int VpcPicConverter::init(aclrtContext context, string dec_name){ 16 +int VpcPicConverter::init(){
17 17
18 - m_dec_name = dec_name; 18 + aclrtSetDevice(m_devId);
  19 + aclrtCreateContext(&context_, m_devId);
19 20
20 - CHECK_AND_RETURN(aclrtSetCurrentContext(context), "aclrtSetCurrentContext failed"); 21 + CHECK_AND_RETURN(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed");
21 CHECK_AND_RETURN(aclrtCreateStream(&stream_), "aclrtCreateStream failed! "); 22 CHECK_AND_RETURN(aclrtCreateStream(&stream_), "aclrtCreateStream failed! ");
22 23
23 dvppChannelDesc_ = acldvppCreateChannelDesc(); 24 dvppChannelDesc_ = acldvppCreateChannelDesc();
@@ -37,6 +38,9 @@ int VpcPicConverter::init(aclrtContext context, string dec_name){ @@ -37,6 +38,9 @@ int VpcPicConverter::init(aclrtContext context, string dec_name){
37 38
38 DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){ 39 DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){
39 40
  41 + aclrtSetDevice(m_devId);
  42 + aclrtSetCurrentContext(context_);
  43 +
40 int out_buf_width = ALIGN_UP(out_width, 16) * 3; 44 int out_buf_width = ALIGN_UP(out_width, 16) * 3;
41 int out_buf_height = ALIGN_UP(out_height, 2); 45 int out_buf_height = ALIGN_UP(out_height, 2);
42 int out_buf_size = out_buf_width * out_buf_height; 46 int out_buf_size = out_buf_width * out_buf_height;
@@ -76,4 +80,64 @@ DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out @@ -76,4 +80,64 @@ DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out
76 } 80 }
77 81
78 return rgbMem; 82 return rgbMem;
  83 +}
  84 +
  85 +DvppDataMemory* VpcPicConverter::convert2bgr(DvppDataMemory* inMem){
  86 +
  87 + aclrtSetDevice(m_devId);
  88 + aclrtSetCurrentContext(context_);
  89 +
  90 + int out_width = inMem->getWidth();
  91 + int out_height = inMem->getHeight();
  92 +
  93 +
  94 + acldvppPicDesc *inputDesc_= acldvppCreatePicDesc();
  95 + acldvppSetPicDescData(inputDesc_, inMem->getMem());
  96 + acldvppSetPicDescFormat(inputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420);
  97 + acldvppSetPicDescWidth(inputDesc_, out_width);
  98 + acldvppSetPicDescHeight(inputDesc_, out_height);
  99 + acldvppSetPicDescWidthStride(inputDesc_, inMem->getWidthStride());
  100 + acldvppSetPicDescHeightStride(inputDesc_, inMem->getHeightStride());
  101 + acldvppSetPicDescSize(inputDesc_, inMem->getSize());
  102 +
  103 + int out_buf_width = ALIGN_UP(out_width, 16) * 3;
  104 + int out_buf_height = ALIGN_UP(out_height, 2);
  105 + int out_buf_size = out_buf_width * out_buf_height;
  106 +
  107 + DvppDataMemory* rgbMem = new DvppDataMemory(3, out_buf_width, out_buf_width, out_buf_height, out_buf_height, out_buf_size, inMem->getId(), inMem->getDeviceId(), false, inMem->getFrameNb());
  108 + void *outBufferDev_ = (void*)rgbMem->getMem();
  109 +
  110 + acldvppPicDesc *outputDesc_= acldvppCreatePicDesc();
  111 + acldvppSetPicDescData(outputDesc_, outBufferDev_);
  112 + acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888);
  113 + acldvppSetPicDescWidth(outputDesc_, out_width);
  114 + acldvppSetPicDescHeight(outputDesc_, out_height);
  115 + acldvppSetPicDescWidthStride(outputDesc_, out_buf_width);
  116 + acldvppSetPicDescHeightStride(outputDesc_, out_buf_height);
  117 + acldvppSetPicDescSize(outputDesc_, out_buf_size);
  118 +
  119 + aclError ret = ACL_ERROR_NONE;
  120 + do{
  121 + // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
  122 + ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
  123 + if(ret != ACL_ERROR_NONE){
  124 + LOG_ERROR("acldvppVpcConvertColorAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
  125 + break;
  126 + }
  127 + ret = aclrtSynchronizeStream(stream_);
  128 + if(ret != ACL_ERROR_NONE){
  129 + LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
  130 + break;
  131 + }
  132 + }while(0);
  133 +
  134 + acldvppDestroyPicDesc(outputDesc_);
  135 + acldvppDestroyPicDesc(inputDesc_);
  136 +
  137 + if(ret != ACL_ERROR_NONE){
  138 + delete rgbMem;
  139 + rgbMem = nullptr;
  140 + }
  141 +
  142 + return rgbMem;
79 } 143 }
80 \ No newline at end of file 144 \ No newline at end of file
src/decoder/dvpp/VpcPicConverter.h
@@ -7,9 +7,10 @@ class VpcPicConverter{ @@ -7,9 +7,10 @@ class VpcPicConverter{
7 public: 7 public:
8 VpcPicConverter(); 8 VpcPicConverter();
9 ~VpcPicConverter(); 9 ~VpcPicConverter();
10 - int init(aclrtContext context, string dec_name); 10 + int init();
11 11
12 DvppDataMemory* convert2bgr(acldvppPicDesc *input, int out_width, int out_height, bool key_frame); 12 DvppDataMemory* convert2bgr(acldvppPicDesc *input, int out_width, int out_height, bool key_frame);
  13 + DvppDataMemory* convert2bgr(DvppDataMemory* inMem);
13 14
14 private: 15 private:
15 aclrtContext context_; 16 aclrtContext context_;
src/decoder/test.cpp1 renamed to src/decoder/test_face.cpp
@@ -2,10 +2,15 @@ @@ -2,10 +2,15 @@
2 #include <mutex> 2 #include <mutex>
3 #include <thread> 3 #include <thread>
4 #include <chrono> 4 #include <chrono>
  5 +#include <string>
5 6
6 #include "acl/acl.h" 7 #include "acl/acl.h"
7 #include "acl/ops/acl_dvpp.h" 8 #include "acl/ops/acl_dvpp.h"
8 9
  10 +#include <opencv2/opencv.hpp>
  11 +
  12 +#include "../ai_engine_module/face_det_ai_engine.h"
  13 +
9 using namespace std; 14 using namespace std;
10 15
11 struct decode_cbk_userdata{ 16 struct decode_cbk_userdata{
@@ -22,12 +27,23 @@ bool m_bfinish{false}; @@ -22,12 +27,23 @@ bool m_bfinish{false};
22 int m_devId = 0; 27 int m_devId = 0;
23 const char* task_id = "test0"; 28 const char* task_id = "test0";
24 int skip_frame_ = 5; 29 int skip_frame_ = 5;
25 -int m_batch_size = 20; 30 +int m_batch_size = 10;
  31 +
  32 +face_det_ai_engine m_face_det_ai_engine;
  33 +
  34 +aclrtContext ctx;
26 35
27 void algorthim_process_thread(); 36 void algorthim_process_thread();
28 void algorthim_face_detect(vector<DeviceMemory*> vec_gpuMem); 37 void algorthim_face_detect(vector<DeviceMemory*> vec_gpuMem);
29 38
30 -void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){ 39 +static long long get_cur_time_ms(){
  40 + chrono::time_point<chrono::system_clock, chrono::milliseconds> tpMicro
  41 + = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now());
  42 +
  43 + return tpMicro.time_since_epoch().count();
  44 +}
  45 +
  46 +static void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){
31 do{ 47 do{
32 if(m_bfinish){ 48 if(m_bfinish){
33 break; 49 break;
@@ -44,7 +60,7 @@ void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){ @@ -44,7 +60,7 @@ void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){
44 }while (true); 60 }while (true);
45 } 61 }
46 62
47 -void decode_finished_cbk(const void * userPtr){ 63 +static void decode_finished_cbk(const void * userPtr){
48 decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr; 64 decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr;
49 if (ptr!= nullptr){ 65 if (ptr!= nullptr){
50 printf("task finished: %s \n", ptr->task_id.c_str()); 66 printf("task finished: %s \n", ptr->task_id.c_str());
@@ -56,13 +72,31 @@ void decode_finished_cbk(const void * userPtr){ @@ -56,13 +72,31 @@ void decode_finished_cbk(const void * userPtr){
56 int main(){ 72 int main(){
57 73
58 // 算法初始化 74 // 算法初始化
  75 + string models_dir = ".";
  76 +
  77 + aclInit(nullptr);
  78 + aclrtSetDevice(m_devId);
  79 +
  80 + // 人脸检测初始化
59 facedet_ai_engine_param fd_param; 81 facedet_ai_engine_param fd_param;
60 - fd_param.sdk_param.det_modelNames = "./models/face_detect/face_det_yolov5s_310p.om";  
61 - fd_param.sdk_param.ldmk_modelNames = "./models/face_detect/face_ldmk_310p.om";  
62 - fd_param.sdk_param.pose_modelNames = "./models/face_detect/face_pose_310p.om";  
63 - fd_param.sdk_param.score_modelNames = "./models/face_detect/face_score_310p.om";  
64 - fd_param.sdk_param.fuzzy_modelNames = "./models/face_detect/face_fuzzy_310p.om";  
65 - fd_param.sdk_param.occlusion_modelNames = "./models/face_detect/face_occlusion_310p.om"; 82 + char model_path_yolov5s[100];
  83 + strcpy(model_path_yolov5s, (models_dir + "/models/face_detect/face_det_yolov5s_310p.om").c_str());
  84 + fd_param.sdk_param.det_modelNames = model_path_yolov5s;
  85 + char model_path_ldmk[100];
  86 + strcpy(model_path_ldmk, (models_dir + "/models/face_detect/face_ldmk_310p.om").c_str());
  87 + fd_param.sdk_param.ldmk_modelNames = model_path_ldmk;
  88 + char model_path_pose[100];
  89 + strcpy(model_path_pose, (models_dir + "/models/face_detect/face_pose_310p.om").c_str());
  90 + fd_param.sdk_param.pose_modelNames = model_path_pose;
  91 + char model_path_score[100];
  92 + strcpy(model_path_score, (models_dir + "/models/face_detect/face_score_310p.om").c_str());
  93 + fd_param.sdk_param.score_modelNames = model_path_score;
  94 + char model_path_fuzzy[100];
  95 + strcpy(model_path_fuzzy, (models_dir + "/models/face_detect/face_fuzzy_310p.om").c_str());
  96 + fd_param.sdk_param.fuzzy_modelNames = model_path_fuzzy;
  97 + char model_path_occlusion[100];
  98 + strcpy(model_path_occlusion, (models_dir + "/models/face_detect/face_occlusion_310p.om").c_str());
  99 + fd_param.sdk_param.occlusion_modelNames = model_path_occlusion;
66 fd_param.sdk_param.thresld = 0.6; 100 fd_param.sdk_param.thresld = 0.6;
67 fd_param.sdk_param.devId = m_devId; 101 fd_param.sdk_param.devId = m_devId;
68 fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023"; 102 fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023";
@@ -71,11 +105,32 @@ int main(){ @@ -71,11 +105,32 @@ int main(){
71 fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测 105 fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测
72 fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE 106 fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE
73 fd_param.sdk_param.max_result_count = 50; 107 fd_param.sdk_param.max_result_count = 50;
74 - ret = m_face_det_ai_engine.init_ai_engine(fd_param); 108 + int ret = m_face_det_ai_engine.init_ai_engine(fd_param);
75 if (ret < 0 ) { 109 if (ret < 0 ) {
76 - printf("Init face detection failed \n");  
77 - return ret; 110 + printf("Init face detection failed");
  111 + return ret;
78 } 112 }
  113 +
  114 + // facedet_ai_engine_param fd_param;
  115 + // fd_param.sdk_param.det_modelNames = "./models/face_detect/face_det_yolov5s_310p.om";
  116 + // fd_param.sdk_param.ldmk_modelNames = "./models/face_detect/face_ldmk_310p.om";
  117 + // fd_param.sdk_param.pose_modelNames = "./models/face_detect/face_pose_310p.om";
  118 + // fd_param.sdk_param.score_modelNames = "./models/face_detect/face_score_310p.om";
  119 + // fd_param.sdk_param.fuzzy_modelNames = "./models/face_detect/face_fuzzy_310p.om";
  120 + // fd_param.sdk_param.occlusion_modelNames = "./models/face_detect/face_occlusion_310p.om";
  121 + // fd_param.sdk_param.thresld = 0.6;
  122 + // fd_param.sdk_param.devId = m_devId;
  123 + // fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023";
  124 + // fd_param.sdk_param.facial_fea_point_config = SY_CONFIG_OPEN; //是否启动关键点检测
  125 + // fd_param.sdk_param.pose_config = SY_CONFIG_OPEN; //是否启动姿态角
  126 + // fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测
  127 + // fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE
  128 + // fd_param.sdk_param.max_result_count = 50;
  129 + // int ret = m_face_det_ai_engine.init_ai_engine(fd_param);
  130 + // if (ret < 0 ) {
  131 + // printf("Init face detection failed \n");
  132 + // return ret;
  133 + // }
79 m_face_det_ai_engine.add_tracker(task_id, skip_frame_); // 跳帧数暂时写死 134 m_face_det_ai_engine.add_tracker(task_id, skip_frame_); // 跳帧数暂时写死
80 135
81 136
@@ -84,7 +139,7 @@ int main(){ @@ -84,7 +139,7 @@ int main(){
84 139
85 MgrDecConfig config; 140 MgrDecConfig config;
86 config.name = task_id; 141 config.name = task_id;
87 - config.cfg.uri = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0"; 142 + config.cfg.uri = "/opt/share/data/caishenkezhan.mp4";
88 config.cfg.post_decoded_cbk = post_decod_cbk; 143 config.cfg.post_decoded_cbk = post_decod_cbk;
89 config.cfg.decode_finished_cbk = decode_finished_cbk; 144 config.cfg.decode_finished_cbk = decode_finished_cbk;
90 config.cfg.force_tcp = true; // rtsp用tcp 145 config.cfg.force_tcp = true; // rtsp用tcp
@@ -112,10 +167,12 @@ int main(){ @@ -112,10 +167,12 @@ int main(){
112 167
113 // 创建算法线程 168 // 创建算法线程
114 m_pAlgorthimThread = new thread([](void* arg) { 169 m_pAlgorthimThread = new thread([](void* arg) {
115 - algorthim_process_thread();  
116 - return (void*)0;  
117 - }  
118 - , nullptr); 170 + algorthim_process_thread();
  171 + return (void*)0;
  172 + }
  173 + , nullptr);
  174 +
  175 + pDecManager->startDecodeByName(config.name);
119 176
120 while (getchar() != 'q'); 177 while (getchar() != 'q');
121 } 178 }
@@ -123,7 +180,6 @@ int main(){ @@ -123,7 +180,6 @@ int main(){
123 void algorthim_process_thread(){ 180 void algorthim_process_thread(){
124 181
125 aclrtSetDevice(m_devId); 182 aclrtSetDevice(m_devId);
126 - aclrtContext ctx;  
127 aclrtCreateContext(&ctx, m_devId); 183 aclrtCreateContext(&ctx, m_devId);
128 184
129 while (true){ 185 while (true){
@@ -155,6 +211,7 @@ void algorthim_process_thread(){ @@ -155,6 +211,7 @@ void algorthim_process_thread(){
155 continue; 211 continue;
156 } 212 }
157 213
  214 + aclrtSetCurrentContext(ctx);
158 algorthim_face_detect(vec_gpuMem); 215 algorthim_face_detect(vec_gpuMem);
159 216
160 for(int i=0;i < vec_gpuMem.size(); i++){ 217 for(int i=0;i < vec_gpuMem.size(); i++){
@@ -172,8 +229,6 @@ void algorthim_process_thread(){ @@ -172,8 +229,6 @@ void algorthim_process_thread(){
172 aclrtDestroyContext(ctx); 229 aclrtDestroyContext(ctx);
173 230
174 printf("algorthim_process_thread exit. \n"); 231 printf("algorthim_process_thread exit. \n");
175 -  
176 - return 0;  
177 } 232 }
178 233
179 void algorthim_face_detect(vector<DeviceMemory*> vec_gpuMem) { 234 void algorthim_face_detect(vector<DeviceMemory*> vec_gpuMem) {
@@ -181,6 +236,7 @@ void algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem) { @@ -181,6 +236,7 @@ void algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem) {
181 vector<string> interest_task_list; 236 vector<string> interest_task_list;
182 vector<sy_img> interest_imgs; 237 vector<sy_img> interest_imgs;
183 vector<DeviceMemory*> vec_vptMem; 238 vector<DeviceMemory*> vec_vptMem;
  239 +
184 for (int i = 0; i < vec_gpuMem.size(); i++) { 240 for (int i = 0; i < vec_gpuMem.size(); i++) {
185 DeviceMemory* mem = vec_gpuMem[i]; 241 DeviceMemory* mem = vec_gpuMem[i];
186 242
@@ -194,6 +250,10 @@ void algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem) { @@ -194,6 +250,10 @@ void algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem) {
194 vec_vptMem.push_back(mem); 250 vec_vptMem.push_back(mem);
195 } 251 }
196 252
  253 + cv::Scalar color;
  254 + color[0]=0;
  255 + color[1]=0;
  256 + color[2]=255;
197 if (!interest_imgs.empty()) { 257 if (!interest_imgs.empty()) {
198 258
199 unsigned image_size = interest_imgs.size(); 259 unsigned image_size = interest_imgs.size();
@@ -204,14 +264,54 @@ void algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem) { @@ -204,14 +264,54 @@ void algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem) {
204 264
205 int ret = m_face_det_ai_engine.ai_engine_process_batch(interest_task_list, interest_imgs.data(), facedet_result, face_deleteObjectID); 265 int ret = m_face_det_ai_engine.ai_engine_process_batch(interest_task_list, interest_imgs.data(), facedet_result, face_deleteObjectID);
206 if(ret <= 0){ 266 if(ret <= 0){
207 - LOG_ERROR("face detect error!!!"); 267 + printf("face detect error!!! \n");
208 return; 268 return;
209 } 269 }
210 270
  271 +
  272 +
  273 + aclrtSetCurrentContext(ctx);
  274 + for(int idx=0; idx < vec_vptMem.size(); idx++){
  275 +
  276 + DeviceMemory* memPtr = vec_vptMem[idx];
  277 + string task_id = memPtr->getId();
  278 + int channel = memPtr->getChannel();
  279 + int height = memPtr->getHeight();
  280 + int width = memPtr->getWidth();
  281 +
  282 + if (0 == facedet_result[idx].obj_count) {
  283 + continue;
  284 + }
  285 +
  286 + int nSize = channel * height * width;
  287 + unsigned char* cpu_data = (unsigned char *)malloc(nSize * sizeof(unsigned char));
  288 + aclError aclRet = aclrtMemcpy(cpu_data, nSize, memPtr->getMem(), nSize, ACL_MEMCPY_DEVICE_TO_HOST);
  289 + cv::Mat img_(height, width, CV_8UC3, cpu_data);
  290 +
  291 + for (int c = 0; c < facedet_result[idx].obj_count; c++) {
  292 +
  293 + det_objinfo obj_info = facedet_result[idx].obj[c];
  294 + string str_obj_id = to_string(obj_info.id);
  295 + cv::rectangle(img_,cv::Point(obj_info.left,obj_info.top),cv::Point(obj_info.right,obj_info.bottom),color,2);
  296 + cv::putText(img_,str_obj_id.c_str(),cv::Point(obj_info.center_x,obj_info.center_y),cv::FONT_HERSHEY_SIMPLEX,2,cv::Scalar(0,0,255),4,8);
  297 + }
  298 +
  299 + string file_name = "./res/recode/" + task_id + "_" + to_string(memPtr->getFrameNb()) + ".jpg";
  300 + bool bWrite = cv::imwrite(file_name, img_);
  301 +
  302 + free(cpu_data);
  303 + }
  304 +
  305 +
  306 +
  307 +
  308 +
211 for (int i = 0; i < face_deleteObjectID.size(); ++i){ 309 for (int i = 0; i < face_deleteObjectID.size(); ++i){
212 std::vector<int>().swap(face_deleteObjectID[i]); 310 std::vector<int>().swap(face_deleteObjectID[i]);
213 } 311 }
214 std::vector<std::vector<int>>().swap(face_deleteObjectID); 312 std::vector<std::vector<int>>().swap(face_deleteObjectID);
215 std::vector<onelevel_det_result>().swap(facedet_result); 313 std::vector<onelevel_det_result>().swap(facedet_result);
216 } 314 }
  315 +
  316 + aclFinalize();
217 } 317 }
218 \ No newline at end of file 318 \ No newline at end of file
src/decoder/test_recoder.cpp renamed to src/decoder/test_recoder.cpp1
src/demo/demo.cpp
@@ -651,7 +651,7 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi) @@ -651,7 +651,7 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi)
651 tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/V5nXRHa?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiMTBjZjM4N2JjY2Y5NDg3YzhjNWYzNjE2M2ViMWUyNTJ8MXwwfDEiLCJ0IjoxfQ=="; 651 tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/V5nXRHa?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiMTBjZjM4N2JjY2Y5NDg3YzhjNWYzNjE2M2ViMWUyNTJ8MXwwfDEiLCJ0IjoxfQ==";
652 break; 652 break;
653 case 4: 653 case 4:
654 - tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0"; 654 + tparam.ipc_url = "rtsp://admin:ad123456@192.168.10.166:554/cam/realmonitor?channel=1&subtype=0";
655 break; 655 break;
656 case 5: 656 case 5:
657 tparam.ipc_url = "/opt/share/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4"; 657 tparam.ipc_url = "/opt/share/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4";
@@ -659,6 +659,9 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi) @@ -659,6 +659,9 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi)
659 case 6: 659 case 6:
660 tparam.ipc_url = "/opt/share/data/不带头盔2.mp4"; 660 tparam.ipc_url = "/opt/share/data/不带头盔2.mp4";
661 break; 661 break;
  662 + case 7:
  663 + tparam.ipc_url = "/opt/share/data/caishenkezhan.mp4";
  664 + break;
662 default: 665 default:
663 tparam.ipc_url = "/opt/share/data/Street.uvf"; 666 tparam.ipc_url = "/opt/share/data/Street.uvf";
664 break; 667 break;
@@ -730,16 +733,18 @@ void test_gpu(int gpuID){ @@ -730,16 +733,18 @@ void test_gpu(int gpuID){
730 #endif // #ifdef POST_USE_RABBITMQ 733 #endif // #ifdef POST_USE_RABBITMQ
731 734
732 std::vector<algorithm_type_t> algor_vec = {algorithm_type_t::FACE_SNAPSHOT, algorithm_type_t::HUMAN_SNAPSHOT,algorithm_type_t::ROAD_WORK_DET, algorithm_type_t::PEDESTRIAN_RETROGRADE, algorithm_type_t::VEHICLE_RETROGRADE, 735 std::vector<algorithm_type_t> algor_vec = {algorithm_type_t::FACE_SNAPSHOT, algorithm_type_t::HUMAN_SNAPSHOT,algorithm_type_t::ROAD_WORK_DET, algorithm_type_t::PEDESTRIAN_RETROGRADE, algorithm_type_t::VEHICLE_RETROGRADE,
733 - algorithm_type_t::PEDESTRIAN_TRESPASS, algorithm_type_t::VEHICLE_TRESPASS, algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT, algorithm_type_t::VIDEO_SNAPSHOT}; 736 + algorithm_type_t::PEDESTRIAN_TRESPASS, algorithm_type_t::VEHICLE_TRESPASS, algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT
  737 + , algorithm_type_t::VIDEO_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED};
734 738
735 739
736 std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED}; 740 std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED};
737 // std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED}; 741 // std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED};
  742 + std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::FACE_SNAPSHOT};
738 743
739 744
740 // string task_id = createTask(handle, algor_vec, 3 + gpuID * 10); 745 // string task_id = createTask(handle, algor_vec, 3 + gpuID * 10);
741 - string task_id1 = createTask(handle, algor_vec2, 5);  
742 - string task_id2 = createTask(handle, algor_vec2, 6); 746 + // string task_id1 = createTask(handle, algor_vec2, 5);
  747 + string task_id2 = createTask(handle, algor_vec, 1);
743 748
744 // test_snapshot(handle); 749 // test_snapshot(handle);
745 750