From dce94814c6d00e95f07ba7877ff13fff259965e3 Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Thu, 6 Jun 2024 17:44:59 +0800 Subject: [PATCH] 同步windows代码 --- .vscode/launch.json | 2 +- vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile | 4 ++-- vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.cpp | 39 +++++++++++++++++++++++++++++++++++++-- vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.h | 5 ++++- vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.cpp | 37 +++++++++++++++++++++---------------- vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.h | 5 +++++ vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxEnv.hpp | 24 ++++++++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp | 37 +++++++++++++++++++++++++++---------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h | 9 ++++++--- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp | 1 + vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h | 1 + vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h | 22 ++++++++++++++++------ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp | 1 + vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/ImageSaveGPU.cpp | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/PartMemCopy.cu | 35 ++++++++++++++++++----------------- vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp | 21 ++++++++++++++++----- 17 files changed, 182 insertions(+), 65 deletions(-) create mode 100644 vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxEnv.hpp diff --git a/.vscode/launch.json b/.vscode/launch.json index ce5b0f8..b7aff4f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512/test", - "args": ["file:///home/cmhu/data/video/Street.uvf","1","0","./db/mvpt.bin"], + "args": ["file:///home/cmhu/data/video/Street.uvf","2","0","./db/mvpt.bin"], "stopAtEntry": false, "cwd": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512", "environment": [], diff --git a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile index 07e4c6e..3b31a4c 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile +++ b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile @@ -60,7 +60,7 @@ INCLUDE= -I $(OPENCV_ROOT)/include/opencv4 \ LIBSPATH=-L/usr/local/cuda/lib64 -lcuda -lcudart -lcurand -lcublas \ -L/usr/lib/x86_64-linux-gnu -lnvcuvid \ - -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lSfxDecoder -lSfxStreamHandler \ + -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lSfxDecoder -lSfxStreamHandler -lSfxTranscoder -lSfxLog -lSfxHttpServer -lSfxNetwork\ -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lface_detect -lvehicle_recognize -lvehicle_color -lhuman_parsing -lhuman_car_parsing -lnon_vehicle_fea_trt -lvehicle_rear_recognition -lvehicle_fea_int8 -lvehicle_plate_dr -lvpd2 \ -L$(UTOOLS_SSD_ROOT) -l:libutools.so \ -L$(DEPEND_DIR)/lib -l:liblibjasper.a -l:libIlmImf.a -l:liblibjpeg.a -l:liblibtiff.a -l:liblibpng.a \ @@ -70,7 +70,7 @@ LIBSPATH=-L/usr/local/cuda/lib64 -lcuda -lcudart -lcurand -lcublas \ -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ -CFLAGS_LIB=-g -O2 -Wall -Wno-deprecated $(DEFS) -lz -ldl -lpthread -fPIC -fvisibility=hidden -Wl,-Bsymbolic +CFLAGS_LIB=-g -O0 -Wall -Wno-deprecated $(DEFS) -lz -ldl -lpthread -fPIC -fvisibility=hidden -Wl,-Bsymbolic CFLAGS = $(CFLAGS_LIB) $(INCLUDE) -std=c++11 -DUSE_CUDNN # -DUNICODE -D_UNICODE NFLAGS_LIB=-g -c $(DEFS) -shared -Xcompiler -fPIC -Xcompiler -fvisibility=hidden diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.cpp index 39ccd5d..d3f670a 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.cpp @@ -4,6 +4,7 @@ #include "ColorSpace.h" #include "sfx_depend_inc.h" +#include "opencv2/opencv.hpp" #include @@ -58,7 +59,11 @@ bool DxDecoderWrap::isStream(string sVideoFileName) { if (pos == 0) { int n = target.size(); sVideoFileName = sVideoFileName.erase(pos, n); + }else { + // 非file 开头,直接判为视频流 + return true; } + pos = sVideoFileName.find_first_of('?'); if (pos != string::npos) { sVideoFileName = sVideoFileName.substr(0, pos); @@ -78,9 +83,13 @@ bool DxDecoderWrap::isStream(string sVideoFileName) { int DxDecoderWrap::DxOpenDecoder(const DxConfig& cfg) { + cout << "before check: " << cfg.uri << endl; + //判断是否为实时流 m_bReal = isStream(cfg.uri); + cout << "before check: " << cfg.uri << endl; + m_nums = 0; m_bPause = false; @@ -93,6 +102,8 @@ int DxDecoderWrap::DxOpenDecoder(const DxConfig& cfg) m_cfg.userPtr = this; m_cfg.escbk = CUDADecoder_Callback; m_cfg.logcbk = DecoderLog_Callback; + m_cfg.log_all = cfg.log_all; + m_cfg.log_user_ptr = cfg.log_user_ptr; m_cfg.devId = cfg.devId; m_cfg.uri = cfg.uri; m_cfg.dec_name = cfg.name; @@ -101,6 +112,8 @@ int DxDecoderWrap::DxOpenDecoder(const DxConfig& cfg) m_name = cfg.name; m_devId = cfg.devId; + cout << "before open: " << m_cfg.uri << endl; + bool bRet= m_pDec->OpenDecoder(m_cfg); if (bRet) { @@ -285,7 +298,29 @@ void DxDecoderWrap::DxCUDADecoderCallback( void * buf, unsigned int size, int wi return ; } - Nv12ToColor24((unsigned char*)buf, width, pHwData, 3 * width, width, height, 0); + // Nv12ToColor24((unsigned char*)buf, m_width, pHwData, 3 * m_width, m_width, m_height, 0); + + + cudaStatus = cudaMemcpy(pHwData, buf, rgbSize * sizeof(unsigned char), cudaMemcpyDeviceToDevice); + + + // int rgb_size = 3 * m_width * m_height; + // unsigned char* cpu_data = new unsigned char[rgb_size]; + // cudaStatus = cudaMemcpy(cpu_data, pHwData, rgb_size * sizeof(unsigned char), cudaMemcpyDeviceToHost); + + // if (timestamp > 245 && timestamp < 255) + // { + // string file_name = "./nv12/"+to_string(timestamp) + ".txt"; + // FILE* fp=fopen(file_name.c_str(),"wb"); + // fwrite(cpu_data, rgb_size, 1, fp); + // fclose(fp); + // } + + // cv::Mat img(m_height, m_width, CV_8UC3, cpu_data); + // cv::imwrite("test.jpg", img); + // delete[] cpu_data; + // cpu_data = nullptr; + DxGPUFrame frame; frame.width = m_width; @@ -309,7 +344,7 @@ void DxDecoderWrap::DxCUDADecoderCallback( void * buf, unsigned int size, int wi return; } - std::cout << "waiting queue " << frame_nb << std::endl; + // std::cout << "waiting queue " << frame_nb << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.h b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.h index 326fb49..d28fe77 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/DxDecoderWrap.h @@ -27,6 +27,9 @@ typedef struct DxConfig int skip_frame; string uri; + + LOG_ALL_CALLBACK log_all; + void* log_user_ptr; }DxConfig; typedef struct DxGPUFrame @@ -78,7 +81,7 @@ public: public: string GetName() {return m_name;}; bool isStream(string sVideoFileName); - + void DxCUDADecoderCallback(void * buf, unsigned int size, int width, int height, unsigned long long timestamp ); int DxDecoderLogCallback(DxLogLevel level, const char * log, unsigned int logLen ); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.cpp index 1bfc319..37a2bde 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.cpp @@ -2,9 +2,14 @@ #include #include +#include #include "sfx_depend_inc.h" +#include "cuda_kernels.h" +#include +#include + using namespace std; SfxDecoder::SfxDecoder( ) @@ -42,13 +47,15 @@ bool SfxDecoder::OpenDecoder(DxDecoderConfig& cfg) sfx_cfg->flags.useFastDecode = 0; sfx_cfg->flags.accelId = m_cfg.devId; sfx_cfg->flags.frameNumber = 1; - sfx_cfg->flags.fmt = SFX_VIDEO_FORMAT_NV12U8; - //sfx_cfg->flags.fmt = SFX_VIDEO_FORMAT_C3BGRU8; + // sfx_cfg->flags.fmt = SFX_VIDEO_FORMAT_NV12U8; + sfx_cfg->flags.fmt = SFX_VIDEO_FORMAT_C3BGRU8; m_handler = SfxStreamHandlerInterface::SfxGetInstance(sfx_cfg); m_dec_name = m_cfg.dec_name; + cout << "open: " << m_cfg.uri << endl; + int nRet = m_handler->SfxOpenStreamHandler( m_cfg.uri.c_str() ); if (nRet != 0) { m_bRun = false; @@ -63,10 +70,12 @@ bool SfxDecoder::OpenDecoder(DxDecoderConfig& cfg) int SfxDecoder::CloseDecoder() { - m_handler->SfxCloseStreamHandler(); - while (m_bRun) - { - std::this_thread::sleep_for(std::chrono::milliseconds(250)); + if (sfx_null != m_handler) { // linux待同步 + m_handler->SfxCloseStreamHandler(); + while (m_bRun) + { + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + } } return 0; @@ -128,9 +137,7 @@ sfx_32 SfxDecoder::SfxLogDefaultHandler( sfx_u32 logLen ) { - SfxDecoder * pThis = sfx_null; - - pThis = ( SfxDecoder * )userPtr; + SfxDecoder * pThis = ( SfxDecoder * )userPtr; if ( SFX_LOG_LEVEL_IMPORTANT == level) //modify by zsh 220602 { @@ -138,19 +145,17 @@ sfx_32 SfxDecoder::SfxLogDefaultHandler( return 0; } - if ( SFX_LOG_LEVEL_CLEANUP == level ) { pThis->m_bRun = sfx_false; if ( pThis->m_cfg.logcbk ) { - pThis->m_cfg.logcbk( - pThis->m_cfg.userPtr, - DX_LOG_LEVEL_CLEANUP, - "DxDecoder[CUDA] module exited..", - 0 - ); + pThis->m_cfg.logcbk( pThis->m_cfg.userPtr, DX_LOG_LEVEL_CLEANUP, "DxDecoder[CUDA] module exited..", 0 ); } + } + else if (pThis->m_cfg.log_all) + { + pThis->m_cfg.log_all(pThis->m_cfg.log_user_ptr, (int)level, log, logLen); } return 0; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.h b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.h index 6b92617..439c03c 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxDecoder.h @@ -21,12 +21,17 @@ typedef enum DxLogLevel typedef int (*DxLogHandler)( const void * userPtr, DxLogLevel level, const char * log, unsigned int logLen ); +typedef void(*LOG_ALL_CALLBACK)(const void * userPtr, int log_level, const char* log, unsigned int logLen); + + typedef void (*DXDECODER_CALLBACK)( const void * userPtr, void * buf, unsigned int size, int width, int height, unsigned long long timestamp ); typedef struct DxDecoderConfig { DxLogHandler logcbk; // 日志回调接口 + LOG_ALL_CALLBACK log_all{nullptr}; + void* log_user_ptr{nullptr}; const void * userPtr; // 用户数据 DXDECODER_CALLBACK escbk; // 解码后帧数据回调接口 int devId; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxEnv.hpp b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxEnv.hpp new file mode 100644 index 0000000..381ee65 --- /dev/null +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/SfxDecoder/SfxEnv.hpp @@ -0,0 +1,24 @@ +#include "SfxStreamHandlerInterface.h" + + +using namespace std; + +class SfxEnv { +public: + static void init(){ + static SfxEnv* singleton = nullptr; + if (singleton == nullptr){ + singleton = new SfxEnv(); + } + return ; + } + +private: + SfxEnv(){ + SfxStreamHandlerInterface::SfxInitialize(100); + } + + ~SfxEnv(){ + SfxStreamHandlerInterface::SfxUninitialize(); + } +}; \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp index 256a1f2..f00b4b5 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp @@ -13,6 +13,7 @@ #include "../utils/logger.hpp" #include "../cuda_src/CropImg.h" +#include "../SfxDecoder/SfxEnv.hpp" #define AUTHORIZATION @@ -101,9 +102,9 @@ int CMutliSourceVideoProcess::FinishProcessThread() AI_LOG_LEVEL_WARNING = 3, // 警告日志通知,模块一切正常(如:重要流程通知) AI_LOG_LEVEL_ERROR = 4, // 重要日志,如结果和严重错误 */ -int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc, VIDEO_FINISH_CALLBACK tFinishCallbackFunc) +int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc) { - set_default_logger(LogLevel(1), "multi_source_process", "logs/main.log", 64 * 1024 * 1024, 30); + set_default_logger(LogLevel(vptParam.serviceID), vptParam.name, vptParam.path, 64 * 1024 * 1024, 30); licence_status = -1; thrd_status = -1; @@ -127,6 +128,7 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN return AUTHOR_ERROR; } + SfxEnv::init(); cuInit(0); int device_count = 0; @@ -164,10 +166,6 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN viewTaskID = -1; TotalTask = 0; - - taskFinishCallbackFunc = nullptr; - if (tFinishCallbackFunc != nullptr) - taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1); taskObjInfoCallbackFunc = nullptr; if (tObjInfoCallbackFunc != nullptr) @@ -242,9 +240,9 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID) task.taskTcuvid = NULL; //回调通知上层任务结束 - if (taskFinishCallbackFunc != nullptr) { + if (task.taskFinishCallbackFunc != nullptr) { std::lock_guard l(m_snaphot_helper.callback_tx); - taskFinishCallbackFunc(task.taskID); + task.taskFinishCallbackFunc(task.taskID); } LOG_INFO("task {} is finished. timeusing: {}", taskID, get_cur_time_ms() - task.timestamp); @@ -329,6 +327,8 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh return false; } + cout << "AddTask: " << new_task.taskFileSource << endl; + DxConfig cfg = { 0 }; cfg.devId = mgpuid; cfg.forceTcp = false; @@ -336,6 +336,8 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh cfg.name = std::to_string(new_task.taskID); cfg.skip_frame = skip_frame_; cfg.uri = new_task.taskFileSource; + cfg.log_all = (LOG_ALL_CALLBACK)tparam.log; + cfg.log_user_ptr = tparam.userPtr; if (new_task.taskTcuvid->DxOpenDecoder(cfg) != 0) { cout << "Add Task Failed! Please check you video file name!" << endl; @@ -353,11 +355,15 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh new_task.taskObjCallbackFunc = nullptr; if (objCallbackFunc != nullptr) - new_task.taskObjCallbackFunc = std::bind(objCallbackFunc, this, std::placeholders::_1); + new_task.taskObjCallbackFunc = std::bind(objCallbackFunc, tparam.userPtr, std::placeholders::_1); new_task.taskRealTimeCallbackFunc = nullptr; if (realTimeCallbackFunc != nullptr) - new_task.taskRealTimeCallbackFunc = std::bind(realTimeCallbackFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + new_task.taskRealTimeCallbackFunc = std::bind(realTimeCallbackFunc, tparam.userPtr, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + + new_task.taskFinishCallbackFunc = nullptr; + if (tparam.tFinishCallbackFunc != nullptr) + new_task.taskFinishCallbackFunc = std::bind(tparam.tFinishCallbackFunc, tparam.userPtr, std::placeholders::_1); if (resultFolderLittle == NULL) { @@ -459,9 +465,14 @@ int CMutliSourceVideoProcess::AddOperator(task_param tparam) newOper.decMode = tparam.decMode; newOper.taskObjCallbackFunc = tparam.obj_snapshot_callback_func; newOper.taskRealTimeCallbackFunc = tparam.rt_view_callback_func; + newOper.tFinishCallbackFunc = tparam.tFinishCallbackFunc; + newOper.taskSfxLogFunc = tparam.log; + newOper.logUserPtr = tparam.userPtr; memcpy(newOper.minBoxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); TaskOperatorQ.push_back(newOper); taskCondVar.wait_for(l, std::chrono::seconds(20)); + + cout << "AddOperator: " << newOper.videoFileName << endl; } int addRes = -1; @@ -534,7 +545,13 @@ void CMutliSourceVideoProcess::OperatorTask() memcpy(tparam.minBoxsize, newOperator.minBoxsize, sizeof(sy_rect)* DETECTTYPE); tparam.obj_snapshot_callback_func = newOperator.taskObjCallbackFunc; tparam.rt_view_callback_func = newOperator.taskRealTimeCallbackFunc; + tparam.tFinishCallbackFunc = newOperator.tFinishCallbackFunc; tparam.decMode = newOperator.decMode; + tparam.log = newOperator.taskSfxLogFunc; + tparam.userPtr = newOperator.logUserPtr; + + cout << "before AddTask: " << tparam.video_filename << endl; + AddTask(tparam); } break; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h index b853597..6f2b4da 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h @@ -99,7 +99,11 @@ struct Operator{ TaskOperator changeTaskOperator; VIDEO_OBJECT_SNAPSHOT_CALLBACK taskObjCallbackFunc; VIDEO_REALTIME_CALLBACK taskRealTimeCallbackFunc; + VIDEO_FINISH_CALLBACK tFinishCallbackFunc; sy_rect minBoxsize[DETECTTYPE]; + + SFX_LOG_CALLBACK taskSfxLogFunc; + void* logUserPtr; }; @@ -109,7 +113,7 @@ public: CMutliSourceVideoProcess(); ~CMutliSourceVideoProcess(); - int InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc, VIDEO_FINISH_CALLBACK tFinishCallbackFunc); + int InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc); int get_task_progress(int taskid, double & progress); void OperatorTask(); @@ -140,8 +144,7 @@ public: int viewTaskID; - FINISH_CALLBACK taskFinishCallbackFunc; - OBJECT_INFO_CALLBACK taskObjInfoCallbackFunc; + OBJECT_INFO_CALLBACK taskObjInfoCallbackFunc {nullptr}; std::mutex taskMutex; std::condition_variable taskCondVar; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp index 316b9ff..60bfcd2 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp @@ -44,6 +44,7 @@ static long long get_cur_time_ms(){ VPTProcess::VPTProcess(/* args */) { + m_taskTrackerMap.clear(); } VPTProcess::~VPTProcess() diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h index 95d409c..0d12258 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h @@ -86,6 +86,7 @@ struct Task{ int taskTotalFrameCount{1}; SNAPSHOT_CALLBACK taskObjCallbackFunc; REALTIME_CALLBACK taskRealTimeCallbackFunc; + FINISH_CALLBACK taskFinishCallbackFunc{nullptr}; cv::Mat frameImage; char* folderNameLittle; char* folderName; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h index 65cd06d..dbe9dfb 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h @@ -85,6 +85,7 @@ typedef struct vplate_num { char character[4]; float maxprob; + int index; }vplate_num; #endif @@ -96,7 +97,12 @@ typedef struct vplate_result float detect_score; vplate_num recg[PLATENUM]; float num_score; - int type; //车牌类型 + int type; //车牌类型。只做车牌检测,车牌类型为:0-单层车牌,1-双层车牌;做车牌检测识别,0-单排蓝色 1-单排黄色 2-单排白色 3-单排黑色 4-双排黄色 5-双排白色 6-新能源黄绿色 7-新能源白绿色 + + int state; //车牌状态:0-无车牌,1-车牌,2-遮挡车牌 + float state_score;//车牌状态置信度 + + sy_point rr_point[4];//斜框 }vplate_result; #endif @@ -219,11 +225,16 @@ typedef void(*VIDEO_REALTIME_CALLBACK)(void * handle, unsigned char *img_data, i typedef void(*VIDEO_FINISH_CALLBACK)(void * handle, const int task_id); +typedef void(*SFX_LOG_CALLBACK)(void * userPtr, int log_level, const char* log, unsigned int logLen); + + //TASK初始化参数 #ifndef __TASK_PARAM__ #define __TASK_PARAM__ typedef struct task_param { + void* userPtr; + SFX_LOG_CALLBACK log; char video_filename[256]; char result_folder_little[256]; char result_folder[256]; @@ -234,9 +245,9 @@ typedef struct task_param sy_rect minBoxsize[DETECTTYPE]; //自定义的minBoxsize大小 VIDEO_OBJECT_SNAPSHOT_CALLBACK obj_snapshot_callback_func; VIDEO_REALTIME_CALLBACK rt_view_callback_func; + VIDEO_FINISH_CALLBACK tFinishCallbackFunc; - //task_param() : video_filename(0), result_folder_little(0), result_folder(0), result_folder_face(0) {} - task_param() : jpeg_quality(30) {} //debug by zsh + task_param() : jpeg_quality(30) {} }task_param; #endif @@ -253,8 +264,8 @@ typedef struct mvpt_param int skip_frame; //内部跳帧数 /********************************日志参数*****************************/ - char path[2048]; - char name[512]; + char* path; + char* name; unsigned int serviceID; unsigned char logMask; unsigned int limitSize; @@ -269,7 +280,6 @@ typedef struct mvpt_param sy_command face_det_config; //是否开启人脸检测 VIDEO_OBJECT_INFO_CALLBACK task_obj_info_callback_func; //目标检测结果实时返回回调函数 - VIDEO_FINISH_CALLBACK task_finish_callbackfunc; //任务分析结束结果回调函数 }mvpt_param; #endif diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp index e60cb65..8b62cdc 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp @@ -7,7 +7,7 @@ int mvpt_init(void **handle, mvpt_param param) *handle = new CMutliSourceVideoProcess(); CMutliSourceVideoProcess* tools = (CMutliSourceVideoProcess*)*handle; - return tools->InitAlgorthim(param, param.task_obj_info_callback_func, param.task_finish_callbackfunc); + return tools->InitAlgorthim(param, param.task_obj_info_callback_func); } //int AddTask(void *handle, char* videoFileName) diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp index f98295a..6017ae1 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp @@ -61,6 +61,7 @@ int HumanCarParsing::init(int gpuid, char* auth_license) param.engine = ENGINE_TENSORRT; param.serialize_file = "./serialize_file/HCP"; param.max_batch = 20; + param.auth_license = auth_license; if (hcp_init(&handle, param) != 0) { LOG_ERROR("hcp_init Failed!"); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/ImageSaveGPU.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/ImageSaveGPU.cpp index 8572e40..0efdbd1 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/ImageSaveGPU.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/ImageSaveGPU.cpp @@ -37,7 +37,7 @@ int partMemCopy(unsigned char* d_srcRGB, int src_width, int src_height, unsigned { cudaError_t cudaStatus = cuda_common::PartMemCopy(d_srcRGB, src_width, src_height, d_dstRGB, left, top, right, bottom); if (cudaStatus != cudaSuccess) { - LOG_ERROR("cuda_common::PartMemCopy failed: {} {} {} {} {} {} {}",cudaGetErrorString(cudaStatus), left, top, right, bottom, src_height, d_dstRGB); + LOG_ERROR("cuda_common::PartMemCopy failed: {} {} {} {} {} {}",cudaGetErrorString(cudaStatus), left, top, right, bottom, src_height); return -1; } diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/PartMemCopy.cu b/vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/PartMemCopy.cu index 396765b..5aae91d 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/PartMemCopy.cu +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/cuda_src/PartMemCopy.cu @@ -1,5 +1,6 @@ #include "cuda_kernels.h" #include + typedef unsigned char uchar; typedef unsigned int uint32; typedef int int32; @@ -246,17 +247,28 @@ namespace cuda_common cudaMalloc(&gpu_dst_rgb, 1000 * sizeof(unsigned char*)); cudaMemcpy(gpu_dst_rgb, d_dstRGB, count * sizeof(unsigned char*), cudaMemcpyHostToDevice); - //cudaMemcpy(cpu_personfloat, d_srcRGB, 112*224*2*sizeof(float), cudaMemcpyDeviceToHost); - // for(int i=0;i<100;i++) - // { - // printf("the score is %f\t",cpu_personfloat[i]); - // } + PartCopy_ResizeImgBilinearBGR_Mean_Variance_CUDAKernel << < grid, block >> > ( d_srcRGB, src_width, src_height, gpu_left, gpu_top, gpu_right, gpu_bottom, gpu_dst_rgb, count, gpu_dst_w, gpu_dst_h, submeanb, submeang, submeanr, varianceb, varianceg, variancer); + + cudaError_t cudaStatus = cudaGetLastError(); + do + { + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "Part 270 kernel_memcopy launch failed: %s\n", cudaGetErrorString(cudaStatus)); + break; + } + cudaStatus = cudaDeviceSynchronize(); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching kernel_bilinear!\n", cudaStatus); + break; + } + } while (0); + cudaFree(gpu_top); cudaFree(gpu_bottom); cudaFree(gpu_left); @@ -264,24 +276,13 @@ namespace cuda_common cudaFree(gpu_dst_w); cudaFree(gpu_dst_h); cudaFree(gpu_dst_rgb); - - cudaError_t cudaStatus = cudaGetLastError(); - if (cudaStatus != cudaSuccess) { - fprintf(stderr, "Part 270 kernel_memcopy launch failed: %s\n", cudaGetErrorString(cudaStatus)); - return cudaStatus; - } - cudaStatus = cudaDeviceSynchronize(); - if (cudaStatus != cudaSuccess) { - fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching kernel_bilinear!\n", cudaStatus); - return cudaStatus; - } /*cudaEventRecord(stop, 0); cudaEventSynchronize(stop); cudaEventElapsedTime(&time, start, stop); cudaEventDestroy(start); cudaEventDestroy(stop); - printf("˺ʱ:%f\n", time);*/ + printf("�˺�������ʱ��:%f\n", time);*/ return cudaStatus; } diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp index cf17af1..631e4c0 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp @@ -664,6 +664,10 @@ void videoFinishCallback(void * handle, const int taskID) // } } +void log_all(void * userPtr, int log_level, const char* log, unsigned int logLen) { + // cout << "log all: " << log_level << " " << logLen << " " << log << endl; +} + //操作句柄 void *handle; static int total_index = 0; @@ -687,11 +691,16 @@ void create_task(const char * videoFileName, int total_index) { tparam.on_image_display = false; tparam.jpeg_quality = 30; //debug by zsh tparam.decMode = 0; // 关键帧解码 + tparam.log = log_all; + tparam.userPtr = nullptr; + + cout << "create_task:" << tparam.video_filename << endl; //tparam.video_filename = argv[total_index%4]; memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE); tparam.rt_view_callback_func = videoRTViewCallback; tparam.obj_snapshot_callback_func = videoObjSnapshotCallback; + tparam.tFinishCallbackFunc = videoFinishCallback; for (int tmp = 0; tmp < 10; tmp ++) { string tmp_path = "results/" + vpt_types[tmp]; @@ -710,10 +719,13 @@ int main(int argc, char* argv[]) cout << "You must input videoFileName, iAddTaskCount and gpuid." << endl; return -1; } + const char * videoFileName = argv[1]; addTaskCount = atoi(argv[2]); int gpuID = atoi(argv[3]); + cout << "cmd:" << videoFileName << endl; + //初始化参数设置 mvpt_param vptParam; // vptParam.hp_analysis_config = SY_CONFIG_CLOSE; @@ -722,7 +734,7 @@ int main(int argc, char* argv[]) // vptParam.hf_recg_config = SY_CONFIG_CLOSE; // vptParam.hcf_recg_config = SY_CONFIG_CLOSE; // vptParam.vcf_recg_config = SY_CONFIG_CLOSE; - vptParam.face_det_config = SY_CONFIG_CLOSE; + // vptParam.face_det_config = SY_CONFIG_CLOSE; vptParam.hp_analysis_config = SY_CONFIG_OPEN; vptParam.hcp_analysis_config = SY_CONFIG_OPEN; @@ -730,20 +742,19 @@ int main(int argc, char* argv[]) vptParam.hf_recg_config = SY_CONFIG_OPEN; vptParam.hcf_recg_config = SY_CONFIG_OPEN; vptParam.vcf_recg_config = SY_CONFIG_OPEN; - // vptParam.face_det_config = SY_CONFIG_OPEN; + vptParam.face_det_config = SY_CONFIG_OPEN; vptParam.vrdbpath = argv[4]; //vptParam.vrdbpath = "../../db/mvpt.bin"; vptParam.auth_license = "sy_va_sub_sdk_2023"; //通用授权 vptParam.task_obj_info_callback_func = videoObjInfoCallback; - vptParam.task_finish_callbackfunc = videoFinishCallback; vptParam.gpuid = gpuID; vptParam.wait_framecount = 30; vptParam.serviceID = 0; vptParam.limitSize = (10 << 20); vptParam.skip_frame = 5; - strcat(vptParam.name, "gbrealtime"); - strcat(vptParam.path, "./log/"); + vptParam.name = "gbrealtime"; + vptParam.path = "./logs/main.log"; int flag = mvpt_init(&handle, vptParam); if (0 != flag) -- libgit2 0.21.4