From 32f28195f94478b57b8e8dd70d1dd931d40bcfb2 Mon Sep 17 00:00:00 2001 From: fiss <2657262686@qq.com> Date: Thu, 17 Aug 2023 17:33:42 +0800 Subject: [PATCH] 优化vpc图片数据类型转换 --- .vscode/launch.json | 4 ++-- src/decoder/Makefile | 41 ++++++++++++++++++++++++++++++++++++----- src/decoder/Makefile_decoder | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/decoder/dvpp/VpcPicConverter.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/decoder/dvpp/VpcPicConverter.h | 3 ++- src/decoder/test.cpp1 | 217 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/decoder/test_face.cpp | 317 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/decoder/test_recoder.cpp | 248 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/decoder/test_recoder.cpp1 | 248 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/demo/demo.cpp | 13 +++++++++---- 10 files changed, 744 insertions(+), 480 deletions(-) create mode 100755 src/decoder/Makefile_decoder delete mode 100644 src/decoder/test.cpp1 create mode 100644 src/decoder/test_face.cpp delete mode 100644 src/decoder/test_recoder.cpp create mode 100644 src/decoder/test_recoder.cpp1 diff --git a/.vscode/launch.json b/.vscode/launch.json index 10cb357..3218e56 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -23,10 +23,10 @@ } ] },{ - "name": "test", + "name": "test_face", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/bin/test", + "program": "${workspaceFolder}/bin/test_face", "args": ["/opt/cmhu/data/Street.uvf","0", "0", "0"], "stopAtEntry": false, "cwd": "${workspaceFolder}/bin", diff --git a/src/decoder/Makefile b/src/decoder/Makefile index adae0ec..c4487de 100755 --- a/src/decoder/Makefile +++ b/src/decoder/Makefile @@ -6,15 +6,16 @@ PROJECT_ROOT= /opt/cmhu/vpt_ascend_arm DEPEND_DIR = $(PROJECT_ROOT)/bin SRC_ROOT = $(PROJECT_ROOT)/src -TARGET= $(PROJECT_ROOT)/bin/test_recoder +TARGET= $(PROJECT_ROOT)/bin/test_face THIRDPARTY_ROOT = $(PROJECT_ROOT)/3rdparty SPDLOG_ROOT = $(THIRDPARTY_ROOT)/spdlog-1.9.2/release OPENCV_ROOT = $(THIRDPARTY_ROOT)/opencv_4_1 JSON_ROOT = $(THIRDPARTY_ROOT)/jsoncpp-1.9.5/release FFMPEG_ROOT = $(THIRDPARTY_ROOT)/ffmpeg-4.4.4/release +RABBITMQ_CLIENT_ROOT = $(THIRDPARTY_ROOT)/rabbitmq-c-0.11.0/release -DEFS = -DENABLE_DVPP_INTERFACE +DEFS = -DENABLE_DVPP_INTERFACE -DWITH_FACE_DET_SS -DPOST_USE_RABBITMQ include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1/aarch64-linux/include \ -I $(SPDLOG_ROOT)/include \ @@ -22,6 +23,7 @@ include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1/aarch64-linux/include \ -I $(OPENCV_ROOT)/include \ -I $(JSON_ROOT)/include \ -I $(FFMPEG_ROOT)/include \ + -I $(RABBITMQ_CLIENT_ROOT)/include \ lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \ -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 \ 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 \ -lplatform -lgraph_base -lqos_manager -LIBS= -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ +LIBS= -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ + -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lhs_motor_process\ + -L $(OPENCV_ROOT)/lib -lopencv_world\ + -L $(JSON_ROOT)/lib -ljsoncpp \ + -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ + -L $(RABBITMQ_CLIENT_ROOT)/lib/aarch64-linux-gnu -lrabbitmq \ 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 -SRCS:=$(wildcard $(SRC_ROOT)/decoder/interface/*.cpp) \ +SRCS:=$(wildcard $(SRC_ROOT)/ai_platform/*.cpp) \ + $(wildcard $(SRC_ROOT)/decoder/interface/*.cpp) \ $(wildcard $(SRC_ROOT)/decoder/dvpp/*.cpp) \ + $(wildcard $(SRC_ROOT)/ai_engine_module/sort/*.cpp) \ + $(wildcard $(SRC_ROOT)/ai_engine_module/*.cpp) \ + $(wildcard $(SRC_ROOT)/util/*.cpp) \ + $(wildcard $(SRC_ROOT)/reprocessing_module/*.cpp) \ + $(wildcard $(SRC_ROOT)/reprocessing_module/rbmq/*.cpp) \ $(wildcard $(SRC_ROOT)/decoder/*.cpp) \ OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) @@ -56,8 +69,26 @@ $(TARGET):$(OBJS) %.o:$(SRC_ROOT)/decoder/interface/%.cpp $(XX) $(CXXFLAGS) -c $< +%.o:$(SRC_ROOT)/ai_platform/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/ai_engine_module/sort/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/ai_engine_module/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/util/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/reprocessing_module/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/reprocessing_module/rbmq/%.cpp + $(XX) $(CXXFLAGS) -c $< + %.o:$(SRC_ROOT)/decoder/%.cpp $(XX) $(CXXFLAGS) -c $< clean: - rm -f *.o $(TARGET) \ No newline at end of file + rm -f *.o $(TARGET) diff --git a/src/decoder/Makefile_decoder b/src/decoder/Makefile_decoder new file mode 100755 index 0000000..adae0ec --- /dev/null +++ b/src/decoder/Makefile_decoder @@ -0,0 +1,63 @@ +XX = g++ + + +PROJECT_ROOT= /opt/cmhu/vpt_ascend_arm + +DEPEND_DIR = $(PROJECT_ROOT)/bin +SRC_ROOT = $(PROJECT_ROOT)/src + +TARGET= $(PROJECT_ROOT)/bin/test_recoder + +THIRDPARTY_ROOT = $(PROJECT_ROOT)/3rdparty +SPDLOG_ROOT = $(THIRDPARTY_ROOT)/spdlog-1.9.2/release +OPENCV_ROOT = $(THIRDPARTY_ROOT)/opencv_4_1 +JSON_ROOT = $(THIRDPARTY_ROOT)/jsoncpp-1.9.5/release +FFMPEG_ROOT = $(THIRDPARTY_ROOT)/ffmpeg-4.4.4/release + +DEFS = -DENABLE_DVPP_INTERFACE + +include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1/aarch64-linux/include \ + -I $(SPDLOG_ROOT)/include \ + -I $(SRC_ROOT)/common \ + -I $(OPENCV_ROOT)/include \ + -I $(JSON_ROOT)/include \ + -I $(FFMPEG_ROOT)/include \ + +lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \ + -L/usr/local/Ascend/ascend-toolkit/latest/lib64 \ + -L/usr/local/Ascend/ascend-toolkit/latest/runtime/lib64 \ + -L/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64 \ + -L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64/stub \ + +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 \ + -lplatform -lgraph_base -lqos_manager + +LIBS= -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ + +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 + + + +SRCS:=$(wildcard $(SRC_ROOT)/decoder/interface/*.cpp) \ + $(wildcard $(SRC_ROOT)/decoder/dvpp/*.cpp) \ + $(wildcard $(SRC_ROOT)/decoder/*.cpp) \ + +OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) + + +$(TARGET):$(OBJS) + rm -f $(TARGET) + $(XX) -o $@ $^ $(CXXFLAGS) + rm -f *.o + +%.o:$(SRC_ROOT)/decoder/dvpp/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/decoder/interface/%.cpp + $(XX) $(CXXFLAGS) -c $< + +%.o:$(SRC_ROOT)/decoder/%.cpp + $(XX) $(CXXFLAGS) -c $< + +clean: + rm -f *.o $(TARGET) \ No newline at end of file diff --git a/src/decoder/dvpp/VpcPicConverter.cpp b/src/decoder/dvpp/VpcPicConverter.cpp index af62ad4..c06c215 100755 --- a/src/decoder/dvpp/VpcPicConverter.cpp +++ b/src/decoder/dvpp/VpcPicConverter.cpp @@ -13,11 +13,12 @@ VpcPicConverter::~VpcPicConverter(){ } } -int VpcPicConverter::init(aclrtContext context, string dec_name){ +int VpcPicConverter::init(){ - m_dec_name = dec_name; + aclrtSetDevice(m_devId); + aclrtCreateContext(&context_, m_devId); - CHECK_AND_RETURN(aclrtSetCurrentContext(context), "aclrtSetCurrentContext failed"); + CHECK_AND_RETURN(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed"); CHECK_AND_RETURN(aclrtCreateStream(&stream_), "aclrtCreateStream failed! "); dvppChannelDesc_ = acldvppCreateChannelDesc(); @@ -37,6 +38,9 @@ int VpcPicConverter::init(aclrtContext context, string dec_name){ DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){ + aclrtSetDevice(m_devId); + aclrtSetCurrentContext(context_); + int out_buf_width = ALIGN_UP(out_width, 16) * 3; int out_buf_height = ALIGN_UP(out_height, 2); int out_buf_size = out_buf_width * out_buf_height; @@ -76,4 +80,64 @@ DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out } return rgbMem; +} + +DvppDataMemory* VpcPicConverter::convert2bgr(DvppDataMemory* inMem){ + + aclrtSetDevice(m_devId); + aclrtSetCurrentContext(context_); + + int out_width = inMem->getWidth(); + int out_height = inMem->getHeight(); + + + acldvppPicDesc *inputDesc_= acldvppCreatePicDesc(); + acldvppSetPicDescData(inputDesc_, inMem->getMem()); + acldvppSetPicDescFormat(inputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420); + acldvppSetPicDescWidth(inputDesc_, out_width); + acldvppSetPicDescHeight(inputDesc_, out_height); + acldvppSetPicDescWidthStride(inputDesc_, inMem->getWidthStride()); + acldvppSetPicDescHeightStride(inputDesc_, inMem->getHeightStride()); + acldvppSetPicDescSize(inputDesc_, inMem->getSize()); + + int out_buf_width = ALIGN_UP(out_width, 16) * 3; + int out_buf_height = ALIGN_UP(out_height, 2); + int out_buf_size = out_buf_width * out_buf_height; + + 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()); + void *outBufferDev_ = (void*)rgbMem->getMem(); + + acldvppPicDesc *outputDesc_= acldvppCreatePicDesc(); + acldvppSetPicDescData(outputDesc_, outBufferDev_); + acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888); + acldvppSetPicDescWidth(outputDesc_, out_width); + acldvppSetPicDescHeight(outputDesc_, out_height); + acldvppSetPicDescWidthStride(outputDesc_, out_buf_width); + acldvppSetPicDescHeightStride(outputDesc_, out_buf_height); + acldvppSetPicDescSize(outputDesc_, out_buf_size); + + aclError ret = ACL_ERROR_NONE; + do{ + // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 + ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_); + if(ret != ACL_ERROR_NONE){ + 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); + break; + } + ret = aclrtSynchronizeStream(stream_); + if(ret != ACL_ERROR_NONE){ + 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); + break; + } + }while(0); + + acldvppDestroyPicDesc(outputDesc_); + acldvppDestroyPicDesc(inputDesc_); + + if(ret != ACL_ERROR_NONE){ + delete rgbMem; + rgbMem = nullptr; + } + + return rgbMem; } \ No newline at end of file diff --git a/src/decoder/dvpp/VpcPicConverter.h b/src/decoder/dvpp/VpcPicConverter.h index 1973949..b9f4f72 100755 --- a/src/decoder/dvpp/VpcPicConverter.h +++ b/src/decoder/dvpp/VpcPicConverter.h @@ -7,9 +7,10 @@ class VpcPicConverter{ public: VpcPicConverter(); ~VpcPicConverter(); - int init(aclrtContext context, string dec_name); + int init(); DvppDataMemory* convert2bgr(acldvppPicDesc *input, int out_width, int out_height, bool key_frame); + DvppDataMemory* convert2bgr(DvppDataMemory* inMem); private: aclrtContext context_; diff --git a/src/decoder/test.cpp1 b/src/decoder/test.cpp1 deleted file mode 100644 index 06af9ce..0000000 --- a/src/decoder/test.cpp1 +++ /dev/null @@ -1,217 +0,0 @@ -#include "./interface/DecoderManager.h" -#include -#include -#include - -#include "acl/acl.h" -#include "acl/ops/acl_dvpp.h" - -using namespace std; - -struct decode_cbk_userdata{ - string task_id; - void* opaque; - void* opaque1; -}; - -deque m_RgbDataList; -mutex m_DataListMtx; - -thread* m_pAlgorthimThread{nullptr}; -bool m_bfinish{false}; -int m_devId = 0; -const char* task_id = "test0"; -int skip_frame_ = 5; -int m_batch_size = 20; - -void algorthim_process_thread(); -void algorthim_face_detect(vector vec_gpuMem); - -void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){ - do{ - if(m_bfinish){ - break; - } - m_DataListMtx.lock(); - if(m_RgbDataList.size() >= 30){ - m_DataListMtx.unlock(); - std::this_thread::sleep_for(std::chrono::milliseconds(3)); - continue; - } - m_RgbDataList.push_back(devFrame); - m_DataListMtx.unlock(); - break; - }while (true); -} - -void decode_finished_cbk(const void * userPtr){ - decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr; - if (ptr!= nullptr){ - printf("task finished: %s \n", ptr->task_id.c_str()); - } - delete ptr; - ptr = nullptr; -} - -int main(){ - - // 算法初始化 - facedet_ai_engine_param fd_param; - fd_param.sdk_param.det_modelNames = "./models/face_detect/face_det_yolov5s_310p.om"; - fd_param.sdk_param.ldmk_modelNames = "./models/face_detect/face_ldmk_310p.om"; - fd_param.sdk_param.pose_modelNames = "./models/face_detect/face_pose_310p.om"; - fd_param.sdk_param.score_modelNames = "./models/face_detect/face_score_310p.om"; - fd_param.sdk_param.fuzzy_modelNames = "./models/face_detect/face_fuzzy_310p.om"; - fd_param.sdk_param.occlusion_modelNames = "./models/face_detect/face_occlusion_310p.om"; - fd_param.sdk_param.thresld = 0.6; - fd_param.sdk_param.devId = m_devId; - fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023"; - fd_param.sdk_param.facial_fea_point_config = SY_CONFIG_OPEN; //是否启动关键点检测 - fd_param.sdk_param.pose_config = SY_CONFIG_OPEN; //是否启动姿态角 - fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测 - fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE - fd_param.sdk_param.max_result_count = 50; - ret = m_face_det_ai_engine.init_ai_engine(fd_param); - if (ret < 0 ) { - printf("Init face detection failed \n"); - return ret; - } - m_face_det_ai_engine.add_tracker(task_id, skip_frame_); // 跳帧数暂时写死 - - - // 创建解码任务 - DecoderManager* pDecManager = DecoderManager::getInstance(); - - MgrDecConfig config; - config.name = task_id; - config.cfg.uri = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0"; - config.cfg.post_decoded_cbk = post_decod_cbk; - config.cfg.decode_finished_cbk = decode_finished_cbk; - config.cfg.force_tcp = true; // rtsp用tcp - config.cfg.gpuid = to_string(m_devId); - config.cfg.skip_frame = skip_frame_; - - config.dec_type = DECODER_TYPE_DVPP; - - AbstractDecoder* dec = pDecManager->createDecoder(config); - if (!dec){ - printf("创建解码器失败 \n"); - return false; - } - - decode_cbk_userdata* userPtr = new decode_cbk_userdata; - userPtr->task_id = string(task_id); - pDecManager->setPostDecArg(config.name, userPtr); - pDecManager->setFinishedDecArg(config.name, userPtr); - - - int input_image_width = 0; - int input_image_height = 0; - pDecManager->getResolution(config.name, input_image_width, input_image_height); - - - // 创建算法线程 - m_pAlgorthimThread = new thread([](void* arg) { - algorthim_process_thread(); - return (void*)0; - } - , nullptr); - - while (getchar() != 'q'); -} - -void algorthim_process_thread(){ - - aclrtSetDevice(m_devId); - aclrtContext ctx; - aclrtCreateContext(&ctx, m_devId); - - while (true){ - if(m_bfinish){ - break; - } - - vector vec_gpuMem; - m_DataListMtx.lock(); - while (!m_RgbDataList.empty()){ - DeviceMemory* gpuMem = m_RgbDataList.front(); - if(gpuMem->getMem() == nullptr){ - // 错误数据,直接删除 - delete gpuMem; - gpuMem = nullptr; - printf("mem is null \n"); - } else { - vec_gpuMem.push_back(gpuMem); - } - m_RgbDataList.pop_front(); - if(vec_gpuMem.size() >= m_batch_size){ - break; - } - } - m_DataListMtx.unlock(); - - if(vec_gpuMem.size() <= 0){ - std::this_thread::sleep_for(std::chrono::milliseconds(3)); - continue; - } - - algorthim_face_detect(vec_gpuMem); - - for(int i=0;i < vec_gpuMem.size(); i++){ - DeviceMemory* mem = vec_gpuMem[i]; - if(mem->getSize() <= 0){ - continue; - } - delete mem; - mem = nullptr; - } - vec_gpuMem.clear(); - - } - - aclrtDestroyContext(ctx); - - printf("algorthim_process_thread exit. \n"); - - return 0; -} - -void algorthim_face_detect(vector vec_gpuMem) { - - vector interest_task_list; - vector interest_imgs; - vector vec_vptMem; - for (int i = 0; i < vec_gpuMem.size(); i++) { - DeviceMemory* mem = vec_gpuMem[i]; - - sy_img img; - img.w_ = mem->getWidth(); - img.h_ = mem->getHeight(); - img.c_ = mem->getChannel(); - img.data_ = mem->getMem(); - interest_imgs.push_back(img); - interest_task_list.push_back(mem->getId()); - vec_vptMem.push_back(mem); - } - - if (!interest_imgs.empty()) { - - unsigned image_size = interest_imgs.size(); - - // 人脸检测、跟踪 - std::vector facedet_result(image_size); - std::vector> face_deleteObjectID(image_size); - - int ret = m_face_det_ai_engine.ai_engine_process_batch(interest_task_list, interest_imgs.data(), facedet_result, face_deleteObjectID); - if(ret <= 0){ - LOG_ERROR("face detect error!!!"); - return; - } - - for (int i = 0; i < face_deleteObjectID.size(); ++i){ - std::vector().swap(face_deleteObjectID[i]); - } - std::vector>().swap(face_deleteObjectID); - std::vector().swap(facedet_result); - } -} \ No newline at end of file diff --git a/src/decoder/test_face.cpp b/src/decoder/test_face.cpp new file mode 100644 index 0000000..1ef3eb2 --- /dev/null +++ b/src/decoder/test_face.cpp @@ -0,0 +1,317 @@ +#include "./interface/DecoderManager.h" +#include +#include +#include +#include + +#include "acl/acl.h" +#include "acl/ops/acl_dvpp.h" + +#include + +#include "../ai_engine_module/face_det_ai_engine.h" + +using namespace std; + +struct decode_cbk_userdata{ + string task_id; + void* opaque; + void* opaque1; +}; + +deque m_RgbDataList; +mutex m_DataListMtx; + +thread* m_pAlgorthimThread{nullptr}; +bool m_bfinish{false}; +int m_devId = 0; +const char* task_id = "test0"; +int skip_frame_ = 5; +int m_batch_size = 10; + +face_det_ai_engine m_face_det_ai_engine; + +aclrtContext ctx; + +void algorthim_process_thread(); +void algorthim_face_detect(vector vec_gpuMem); + +static long long get_cur_time_ms(){ + chrono::time_point tpMicro + = chrono::time_point_cast(chrono::system_clock::now()); + + return tpMicro.time_since_epoch().count(); +} + +static void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){ + do{ + if(m_bfinish){ + break; + } + m_DataListMtx.lock(); + if(m_RgbDataList.size() >= 30){ + m_DataListMtx.unlock(); + std::this_thread::sleep_for(std::chrono::milliseconds(3)); + continue; + } + m_RgbDataList.push_back(devFrame); + m_DataListMtx.unlock(); + break; + }while (true); +} + +static void decode_finished_cbk(const void * userPtr){ + decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr; + if (ptr!= nullptr){ + printf("task finished: %s \n", ptr->task_id.c_str()); + } + delete ptr; + ptr = nullptr; +} + +int main(){ + + // 算法初始化 + string models_dir = "."; + + aclInit(nullptr); + aclrtSetDevice(m_devId); + + // 人脸检测初始化 + facedet_ai_engine_param fd_param; + char model_path_yolov5s[100]; + strcpy(model_path_yolov5s, (models_dir + "/models/face_detect/face_det_yolov5s_310p.om").c_str()); + fd_param.sdk_param.det_modelNames = model_path_yolov5s; + char model_path_ldmk[100]; + strcpy(model_path_ldmk, (models_dir + "/models/face_detect/face_ldmk_310p.om").c_str()); + fd_param.sdk_param.ldmk_modelNames = model_path_ldmk; + char model_path_pose[100]; + strcpy(model_path_pose, (models_dir + "/models/face_detect/face_pose_310p.om").c_str()); + fd_param.sdk_param.pose_modelNames = model_path_pose; + char model_path_score[100]; + strcpy(model_path_score, (models_dir + "/models/face_detect/face_score_310p.om").c_str()); + fd_param.sdk_param.score_modelNames = model_path_score; + char model_path_fuzzy[100]; + strcpy(model_path_fuzzy, (models_dir + "/models/face_detect/face_fuzzy_310p.om").c_str()); + fd_param.sdk_param.fuzzy_modelNames = model_path_fuzzy; + char model_path_occlusion[100]; + strcpy(model_path_occlusion, (models_dir + "/models/face_detect/face_occlusion_310p.om").c_str()); + fd_param.sdk_param.occlusion_modelNames = model_path_occlusion; + fd_param.sdk_param.thresld = 0.6; + fd_param.sdk_param.devId = m_devId; + fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023"; + fd_param.sdk_param.facial_fea_point_config = SY_CONFIG_OPEN; //是否启动关键点检测 + fd_param.sdk_param.pose_config = SY_CONFIG_OPEN; //是否启动姿态角 + fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测 + fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE + fd_param.sdk_param.max_result_count = 50; + int ret = m_face_det_ai_engine.init_ai_engine(fd_param); + if (ret < 0 ) { + printf("Init face detection failed"); + return ret; + } + + // facedet_ai_engine_param fd_param; + // fd_param.sdk_param.det_modelNames = "./models/face_detect/face_det_yolov5s_310p.om"; + // fd_param.sdk_param.ldmk_modelNames = "./models/face_detect/face_ldmk_310p.om"; + // fd_param.sdk_param.pose_modelNames = "./models/face_detect/face_pose_310p.om"; + // fd_param.sdk_param.score_modelNames = "./models/face_detect/face_score_310p.om"; + // fd_param.sdk_param.fuzzy_modelNames = "./models/face_detect/face_fuzzy_310p.om"; + // fd_param.sdk_param.occlusion_modelNames = "./models/face_detect/face_occlusion_310p.om"; + // fd_param.sdk_param.thresld = 0.6; + // fd_param.sdk_param.devId = m_devId; + // fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023"; + // fd_param.sdk_param.facial_fea_point_config = SY_CONFIG_OPEN; //是否启动关键点检测 + // fd_param.sdk_param.pose_config = SY_CONFIG_OPEN; //是否启动姿态角 + // fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测 + // fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE + // fd_param.sdk_param.max_result_count = 50; + // int ret = m_face_det_ai_engine.init_ai_engine(fd_param); + // if (ret < 0 ) { + // printf("Init face detection failed \n"); + // return ret; + // } + m_face_det_ai_engine.add_tracker(task_id, skip_frame_); // 跳帧数暂时写死 + + + // 创建解码任务 + DecoderManager* pDecManager = DecoderManager::getInstance(); + + MgrDecConfig config; + config.name = task_id; + config.cfg.uri = "/opt/share/data/caishenkezhan.mp4"; + config.cfg.post_decoded_cbk = post_decod_cbk; + config.cfg.decode_finished_cbk = decode_finished_cbk; + config.cfg.force_tcp = true; // rtsp用tcp + config.cfg.gpuid = to_string(m_devId); + config.cfg.skip_frame = skip_frame_; + + config.dec_type = DECODER_TYPE_DVPP; + + AbstractDecoder* dec = pDecManager->createDecoder(config); + if (!dec){ + printf("创建解码器失败 \n"); + return false; + } + + decode_cbk_userdata* userPtr = new decode_cbk_userdata; + userPtr->task_id = string(task_id); + pDecManager->setPostDecArg(config.name, userPtr); + pDecManager->setFinishedDecArg(config.name, userPtr); + + + int input_image_width = 0; + int input_image_height = 0; + pDecManager->getResolution(config.name, input_image_width, input_image_height); + + + // 创建算法线程 + m_pAlgorthimThread = new thread([](void* arg) { + algorthim_process_thread(); + return (void*)0; + } + , nullptr); + + pDecManager->startDecodeByName(config.name); + + while (getchar() != 'q'); +} + +void algorthim_process_thread(){ + + aclrtSetDevice(m_devId); + aclrtCreateContext(&ctx, m_devId); + + while (true){ + if(m_bfinish){ + break; + } + + vector vec_gpuMem; + m_DataListMtx.lock(); + while (!m_RgbDataList.empty()){ + DeviceMemory* gpuMem = m_RgbDataList.front(); + if(gpuMem->getMem() == nullptr){ + // 错误数据,直接删除 + delete gpuMem; + gpuMem = nullptr; + printf("mem is null \n"); + } else { + vec_gpuMem.push_back(gpuMem); + } + m_RgbDataList.pop_front(); + if(vec_gpuMem.size() >= m_batch_size){ + break; + } + } + m_DataListMtx.unlock(); + + if(vec_gpuMem.size() <= 0){ + std::this_thread::sleep_for(std::chrono::milliseconds(3)); + continue; + } + + aclrtSetCurrentContext(ctx); + algorthim_face_detect(vec_gpuMem); + + for(int i=0;i < vec_gpuMem.size(); i++){ + DeviceMemory* mem = vec_gpuMem[i]; + if(mem->getSize() <= 0){ + continue; + } + delete mem; + mem = nullptr; + } + vec_gpuMem.clear(); + + } + + aclrtDestroyContext(ctx); + + printf("algorthim_process_thread exit. \n"); +} + +void algorthim_face_detect(vector vec_gpuMem) { + + vector interest_task_list; + vector interest_imgs; + vector vec_vptMem; + + for (int i = 0; i < vec_gpuMem.size(); i++) { + DeviceMemory* mem = vec_gpuMem[i]; + + sy_img img; + img.w_ = mem->getWidth(); + img.h_ = mem->getHeight(); + img.c_ = mem->getChannel(); + img.data_ = mem->getMem(); + interest_imgs.push_back(img); + interest_task_list.push_back(mem->getId()); + vec_vptMem.push_back(mem); + } + + cv::Scalar color; + color[0]=0; + color[1]=0; + color[2]=255; + if (!interest_imgs.empty()) { + + unsigned image_size = interest_imgs.size(); + + // 人脸检测、跟踪 + std::vector facedet_result(image_size); + std::vector> face_deleteObjectID(image_size); + + int ret = m_face_det_ai_engine.ai_engine_process_batch(interest_task_list, interest_imgs.data(), facedet_result, face_deleteObjectID); + if(ret <= 0){ + printf("face detect error!!! \n"); + return; + } + + + + aclrtSetCurrentContext(ctx); + for(int idx=0; idx < vec_vptMem.size(); idx++){ + + DeviceMemory* memPtr = vec_vptMem[idx]; + string task_id = memPtr->getId(); + int channel = memPtr->getChannel(); + int height = memPtr->getHeight(); + int width = memPtr->getWidth(); + + if (0 == facedet_result[idx].obj_count) { + continue; + } + + int nSize = channel * height * width; + unsigned char* cpu_data = (unsigned char *)malloc(nSize * sizeof(unsigned char)); + aclError aclRet = aclrtMemcpy(cpu_data, nSize, memPtr->getMem(), nSize, ACL_MEMCPY_DEVICE_TO_HOST); + cv::Mat img_(height, width, CV_8UC3, cpu_data); + + for (int c = 0; c < facedet_result[idx].obj_count; c++) { + + det_objinfo obj_info = facedet_result[idx].obj[c]; + string str_obj_id = to_string(obj_info.id); + cv::rectangle(img_,cv::Point(obj_info.left,obj_info.top),cv::Point(obj_info.right,obj_info.bottom),color,2); + 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); + } + + string file_name = "./res/recode/" + task_id + "_" + to_string(memPtr->getFrameNb()) + ".jpg"; + bool bWrite = cv::imwrite(file_name, img_); + + free(cpu_data); + } + + + + + + for (int i = 0; i < face_deleteObjectID.size(); ++i){ + std::vector().swap(face_deleteObjectID[i]); + } + std::vector>().swap(face_deleteObjectID); + std::vector().swap(facedet_result); + } + + aclFinalize(); +} \ No newline at end of file diff --git a/src/decoder/test_recoder.cpp b/src/decoder/test_recoder.cpp deleted file mode 100644 index d373aa8..0000000 --- a/src/decoder/test_recoder.cpp +++ /dev/null @@ -1,248 +0,0 @@ -#include "./interface/DecoderManager.h" -#include -#include -#include - -using namespace std; - -struct decode_cbk_userdata{ - string task_id; - void* opaque; - void* opaque1; -}; - -deque m_RgbDataList; -mutex m_DataListMtx; - -thread* m_pAlgorthimThread{nullptr}; -thread* m_recodeThread{nullptr}; -bool m_bfinish{false}; -int m_devId = 0; -const char* task_id = "test0"; -int skip_frame_ = 5; -int m_batch_size = 20; - -deque m_recoderinfo_queue; -mutex m_recoderinfo_queue_mtx; - -void algorthim_process_thread(); -void recode_thread(); -void algorthim_face_detect(vector vec_gpuMem); - -void test_recode_thread(); - -void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){ - do{ - if(m_bfinish){ - break; - } - m_DataListMtx.lock(); - if(m_RgbDataList.size() >= 30){ - m_DataListMtx.unlock(); - std::this_thread::sleep_for(std::chrono::milliseconds(3)); - continue; - } - m_RgbDataList.push_back(devFrame); - m_DataListMtx.unlock(); - break; - }while (true); -} - -void decode_finished_cbk(const void * userPtr){ - decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr; - if (ptr!= nullptr){ - printf("task finished: %s \n", ptr->task_id.c_str()); - } - delete ptr; - ptr = nullptr; -} - -int main(){ - - // 创建解码任务 - DecoderManager* pDecManager = DecoderManager::getInstance(); - - MgrDecConfig config; - config.name = task_id; - config.cfg.uri = "/opt/cmhu/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4"; - config.cfg.post_decoded_cbk = post_decod_cbk; - config.cfg.decode_finished_cbk = decode_finished_cbk; - config.cfg.force_tcp = true; // rtsp用tcp - config.cfg.gpuid = to_string(m_devId); - config.cfg.skip_frame = skip_frame_; - - config.dec_type = DECODER_TYPE_DVPP; - - AbstractDecoder* dec = pDecManager->createDecoder(config); - if (!dec){ - printf("创建解码器失败 \n"); - return false; - } - - decode_cbk_userdata* userPtr = new decode_cbk_userdata; - userPtr->task_id = string(task_id); - pDecManager->setPostDecArg(config.name, userPtr); - pDecManager->setFinishedDecArg(config.name, userPtr); - - - int input_image_width = 0; - int input_image_height = 0; - pDecManager->getResolution(config.name, input_image_width, input_image_height); - - - // 创建算法线程 - m_pAlgorthimThread = new thread([](void* arg) { - algorthim_process_thread(); - return (void*)0; - } - , nullptr); - - // m_recodeThread = new thread([](void* arg) { - // recode_thread(); - // return (void*)0; - // } - // , nullptr); - - m_recodeThread = new thread([](void* arg) { - test_recode_thread(); - return (void*)0; - } - , nullptr); - - pDecManager->startDecodeByName(config.name); - - while (getchar() != 'q'); -} - -void algorthim_process_thread(){ - - while (true){ - if(m_bfinish){ - break; - } - - vector vec_gpuMem; - m_DataListMtx.lock(); - while (!m_RgbDataList.empty()){ - DeviceMemory* gpuMem = m_RgbDataList.front(); - if(gpuMem->getMem() == nullptr){ - // 错误数据,直接删除 - delete gpuMem; - gpuMem = nullptr; - printf("mem is null \n"); - } else { - vec_gpuMem.push_back(gpuMem); - } - m_RgbDataList.pop_front(); - if(vec_gpuMem.size() >= m_batch_size){ - break; - } - } - m_DataListMtx.unlock(); - - if(vec_gpuMem.size() <= 0){ - std::this_thread::sleep_for(std::chrono::milliseconds(3)); - continue; - } - - algorthim_face_detect(vec_gpuMem); - - for(int i=0;i < vec_gpuMem.size(); i++){ - DeviceMemory* mem = vec_gpuMem[i]; - if(mem->getSize() <= 0){ - continue; - } - delete mem; - mem = nullptr; - } - vec_gpuMem.clear(); - - } - - printf("algorthim_process_thread exit. \n"); -} - -static int interval = 0; -static int obj_id = 0; - -void algorthim_face_detect(vector vec_gpuMem) { - interval ++ ; - - if(interval % 50 != 0) { - return; - } - - for(int i= 0; i < vec_gpuMem.size(); i++) { - DeviceMemory* mem = vec_gpuMem[i]; - string task_id = mem->getId(); - - RecoderInfo recoderInfo; - recoderInfo.task_id = task_id; - recoderInfo.object_id = std::to_string(obj_id); - recoderInfo.recoderPath = "./res/recode"; - recoderInfo.frame_nb = mem->getFrameNb(); - - m_recoderinfo_queue_mtx.lock(); - m_recoderinfo_queue.push_back(recoderInfo); - m_recoderinfo_queue_mtx.unlock(); - - obj_id++; - - } -} - -void test_recode_thread() { - unsigned long long frame_index = 0; - while(true) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - - DeviceMemory* mem = nullptr; - m_DataListMtx.lock(); - while (!m_RgbDataList.empty()){ - DeviceMemory* gpuMem = m_RgbDataList.front(); - if(gpuMem->getMem() == nullptr){ - // 错误数据,直接删除 - delete gpuMem; - gpuMem = nullptr; - printf("mem is null \n"); - } else { - frame_index ++ ; - if (frame_index % 50 == 0) { - RecoderInfo recoderInfo; - recoderInfo.task_id = gpuMem->getId(); - recoderInfo.object_id = std::to_string(obj_id); - recoderInfo.recoderPath = "./res/recode"; - recoderInfo.frame_nb = gpuMem->getFrameNb(); - - DecoderManager* pDecManager = DecoderManager::getInstance(); - pDecManager->doRecode(recoderInfo); - - obj_id++; - } - delete gpuMem; - gpuMem = nullptr; - } - m_RgbDataList.pop_front(); - } - m_DataListMtx.unlock(); - } -} - -void recode_thread() { - while(true) { - - m_recoderinfo_queue_mtx.lock(); - if(m_recoderinfo_queue.size() <= 0) { - m_recoderinfo_queue_mtx.unlock(); - std::this_thread::sleep_for(std::chrono::milliseconds(5)); - continue; - } - - RecoderInfo info = m_recoderinfo_queue.front(); - m_recoderinfo_queue.pop_front(); - m_recoderinfo_queue_mtx.unlock(); - - DecoderManager* pDecManager = DecoderManager::getInstance(); - pDecManager->doRecode(info); - } -} \ No newline at end of file diff --git a/src/decoder/test_recoder.cpp1 b/src/decoder/test_recoder.cpp1 new file mode 100644 index 0000000..d373aa8 --- /dev/null +++ b/src/decoder/test_recoder.cpp1 @@ -0,0 +1,248 @@ +#include "./interface/DecoderManager.h" +#include +#include +#include + +using namespace std; + +struct decode_cbk_userdata{ + string task_id; + void* opaque; + void* opaque1; +}; + +deque m_RgbDataList; +mutex m_DataListMtx; + +thread* m_pAlgorthimThread{nullptr}; +thread* m_recodeThread{nullptr}; +bool m_bfinish{false}; +int m_devId = 0; +const char* task_id = "test0"; +int skip_frame_ = 5; +int m_batch_size = 20; + +deque m_recoderinfo_queue; +mutex m_recoderinfo_queue_mtx; + +void algorthim_process_thread(); +void recode_thread(); +void algorthim_face_detect(vector vec_gpuMem); + +void test_recode_thread(); + +void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){ + do{ + if(m_bfinish){ + break; + } + m_DataListMtx.lock(); + if(m_RgbDataList.size() >= 30){ + m_DataListMtx.unlock(); + std::this_thread::sleep_for(std::chrono::milliseconds(3)); + continue; + } + m_RgbDataList.push_back(devFrame); + m_DataListMtx.unlock(); + break; + }while (true); +} + +void decode_finished_cbk(const void * userPtr){ + decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr; + if (ptr!= nullptr){ + printf("task finished: %s \n", ptr->task_id.c_str()); + } + delete ptr; + ptr = nullptr; +} + +int main(){ + + // 创建解码任务 + DecoderManager* pDecManager = DecoderManager::getInstance(); + + MgrDecConfig config; + config.name = task_id; + config.cfg.uri = "/opt/cmhu/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4"; + config.cfg.post_decoded_cbk = post_decod_cbk; + config.cfg.decode_finished_cbk = decode_finished_cbk; + config.cfg.force_tcp = true; // rtsp用tcp + config.cfg.gpuid = to_string(m_devId); + config.cfg.skip_frame = skip_frame_; + + config.dec_type = DECODER_TYPE_DVPP; + + AbstractDecoder* dec = pDecManager->createDecoder(config); + if (!dec){ + printf("创建解码器失败 \n"); + return false; + } + + decode_cbk_userdata* userPtr = new decode_cbk_userdata; + userPtr->task_id = string(task_id); + pDecManager->setPostDecArg(config.name, userPtr); + pDecManager->setFinishedDecArg(config.name, userPtr); + + + int input_image_width = 0; + int input_image_height = 0; + pDecManager->getResolution(config.name, input_image_width, input_image_height); + + + // 创建算法线程 + m_pAlgorthimThread = new thread([](void* arg) { + algorthim_process_thread(); + return (void*)0; + } + , nullptr); + + // m_recodeThread = new thread([](void* arg) { + // recode_thread(); + // return (void*)0; + // } + // , nullptr); + + m_recodeThread = new thread([](void* arg) { + test_recode_thread(); + return (void*)0; + } + , nullptr); + + pDecManager->startDecodeByName(config.name); + + while (getchar() != 'q'); +} + +void algorthim_process_thread(){ + + while (true){ + if(m_bfinish){ + break; + } + + vector vec_gpuMem; + m_DataListMtx.lock(); + while (!m_RgbDataList.empty()){ + DeviceMemory* gpuMem = m_RgbDataList.front(); + if(gpuMem->getMem() == nullptr){ + // 错误数据,直接删除 + delete gpuMem; + gpuMem = nullptr; + printf("mem is null \n"); + } else { + vec_gpuMem.push_back(gpuMem); + } + m_RgbDataList.pop_front(); + if(vec_gpuMem.size() >= m_batch_size){ + break; + } + } + m_DataListMtx.unlock(); + + if(vec_gpuMem.size() <= 0){ + std::this_thread::sleep_for(std::chrono::milliseconds(3)); + continue; + } + + algorthim_face_detect(vec_gpuMem); + + for(int i=0;i < vec_gpuMem.size(); i++){ + DeviceMemory* mem = vec_gpuMem[i]; + if(mem->getSize() <= 0){ + continue; + } + delete mem; + mem = nullptr; + } + vec_gpuMem.clear(); + + } + + printf("algorthim_process_thread exit. \n"); +} + +static int interval = 0; +static int obj_id = 0; + +void algorthim_face_detect(vector vec_gpuMem) { + interval ++ ; + + if(interval % 50 != 0) { + return; + } + + for(int i= 0; i < vec_gpuMem.size(); i++) { + DeviceMemory* mem = vec_gpuMem[i]; + string task_id = mem->getId(); + + RecoderInfo recoderInfo; + recoderInfo.task_id = task_id; + recoderInfo.object_id = std::to_string(obj_id); + recoderInfo.recoderPath = "./res/recode"; + recoderInfo.frame_nb = mem->getFrameNb(); + + m_recoderinfo_queue_mtx.lock(); + m_recoderinfo_queue.push_back(recoderInfo); + m_recoderinfo_queue_mtx.unlock(); + + obj_id++; + + } +} + +void test_recode_thread() { + unsigned long long frame_index = 0; + while(true) { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + + DeviceMemory* mem = nullptr; + m_DataListMtx.lock(); + while (!m_RgbDataList.empty()){ + DeviceMemory* gpuMem = m_RgbDataList.front(); + if(gpuMem->getMem() == nullptr){ + // 错误数据,直接删除 + delete gpuMem; + gpuMem = nullptr; + printf("mem is null \n"); + } else { + frame_index ++ ; + if (frame_index % 50 == 0) { + RecoderInfo recoderInfo; + recoderInfo.task_id = gpuMem->getId(); + recoderInfo.object_id = std::to_string(obj_id); + recoderInfo.recoderPath = "./res/recode"; + recoderInfo.frame_nb = gpuMem->getFrameNb(); + + DecoderManager* pDecManager = DecoderManager::getInstance(); + pDecManager->doRecode(recoderInfo); + + obj_id++; + } + delete gpuMem; + gpuMem = nullptr; + } + m_RgbDataList.pop_front(); + } + m_DataListMtx.unlock(); + } +} + +void recode_thread() { + while(true) { + + m_recoderinfo_queue_mtx.lock(); + if(m_recoderinfo_queue.size() <= 0) { + m_recoderinfo_queue_mtx.unlock(); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + continue; + } + + RecoderInfo info = m_recoderinfo_queue.front(); + m_recoderinfo_queue.pop_front(); + m_recoderinfo_queue_mtx.unlock(); + + DecoderManager* pDecManager = DecoderManager::getInstance(); + pDecManager->doRecode(info); + } +} \ No newline at end of file diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index b1aa00e..80e495b 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -651,7 +651,7 @@ string createTask(void *handle, std::vector algor_vec, int gi) tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/V5nXRHa?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiMTBjZjM4N2JjY2Y5NDg3YzhjNWYzNjE2M2ViMWUyNTJ8MXwwfDEiLCJ0IjoxfQ=="; break; case 4: - tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0"; + tparam.ipc_url = "rtsp://admin:ad123456@192.168.10.166:554/cam/realmonitor?channel=1&subtype=0"; break; case 5: tparam.ipc_url = "/opt/share/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4"; @@ -659,6 +659,9 @@ string createTask(void *handle, std::vector algor_vec, int gi) case 6: tparam.ipc_url = "/opt/share/data/不带头盔2.mp4"; break; + case 7: + tparam.ipc_url = "/opt/share/data/caishenkezhan.mp4"; + break; default: tparam.ipc_url = "/opt/share/data/Street.uvf"; break; @@ -730,16 +733,18 @@ void test_gpu(int gpuID){ #endif // #ifdef POST_USE_RABBITMQ std::vector 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, - 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}; + 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, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED}; std::vector algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED}; // std::vector algor_vec2 = {algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED}; + std::vector algor_vec3 = {algorithm_type_t::FACE_SNAPSHOT}; // string task_id = createTask(handle, algor_vec, 3 + gpuID * 10); - string task_id1 = createTask(handle, algor_vec2, 5); - string task_id2 = createTask(handle, algor_vec2, 6); + // string task_id1 = createTask(handle, algor_vec2, 5); + string task_id2 = createTask(handle, algor_vec, 1); // test_snapshot(handle); -- libgit2 0.21.4