From a1c0194c32d446cd68a73914ed9961ff2375d516 Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Mon, 9 Oct 2023 11:26:30 +0800 Subject: [PATCH] FFNvDecoder 初步功能版 --- .vscode/launch.json | 18 ++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile | 30 +++++++++++++++++++++++------- vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.FFNvDecoder | 121 ------------------------------------------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.qx | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp | 3 ++- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h | 3 ++- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++-------------- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h | 11 ++++++----- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp | 47 ++++++++++++++++++++++++++--------------------- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h | 1 + vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp | 129 +++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.FFNvDecoder | 1862 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx | 1860 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h | 18 +++++++++--------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.h | 11 ++++++----- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------- 19 files changed, 2219 insertions(+), 2194 deletions(-) delete mode 100644 vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.FFNvDecoder create mode 100644 vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.qx delete mode 100644 vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.FFNvDecoder create mode 100644 vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx diff --git a/.vscode/launch.json b/.vscode/launch.json index cd62d79..1469354 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,6 +20,24 @@ } ] },{ + "name": "test_ffnvdecoder", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512/test", + "args": ["/home/cmhu/data/video/Street.uvf","6","0","./db/mvpt.bin"], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + },{ "name": "test_face", "type": "cppdbg", "request": "launch", 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 f22b6ba..bc88b66 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile +++ b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile @@ -2,6 +2,7 @@ CC = gcc XX = g++ AR = ar +CUDA = /usr/local/cuda NVCC = /usr/local/cuda/bin/nvcc MNT_HOME = /home/cmhu/Project_VideoStructure @@ -11,6 +12,7 @@ DEPEND_DIR = $(MNT_HOME)/Linux_3rdparty SDK_ROOT = $(MNT_HOME)/SDK SRC_ROOT = $(PROJECT_ROOT)/src/VPT +FFNVDECODER_ROOT = $(PROJECT_ROOT)/src/FFNvDecoder UTOOLS_SSD_ROOT = $(DEPEND_DIR)/utools_trt_v1.4.0 HIDE_MODEL_CAFFE2 = $(PROJECT_ROOT)/model/hidemodel_caffe_1108 @@ -19,6 +21,7 @@ AUTHORITY_DIR = $(DEPEND_DIR)/authority_linux_20200114 TRT_ROOT = $(DEPEND_DIR)/TensorRT-8.6.1.6 OPENCV_ROOT = $(DEPEND_DIR)/opencv-4.5.4/release FFMPEG_ROOT = $(DEPEND_DIR)/ffmpeg-5.0.1/release +SPDLOG_ROOT = $(DEPEND_DIR)/spdlog-1.9.2/release TARGET = $(DEPEND_DIR)/video_structure_sdk_20220512/libmvpt.so @@ -34,16 +37,18 @@ INCLUDE= -I $(DEPEND_DIR)/include/boost_linux_x86_64/include \ -I $(DEPEND_DIR)/include/cairo \ -I $(SRC_ROOT)/sort \ -I $(SRC_ROOT)/snapshot_analysis \ - -I $(SRC_ROOT)/../DxDecoder \ - -I /usr/local/cuda/include \ -I $(HIDE_MODEL_CAFFE2) \ -I $(HIDE_MODEL_TRT) \ -I $(AUTHORITY_DIR) \ -I $(FFMPEG_ROOT)/include \ -I $(SDK_ROOT)/face_detect2/face_detect \ + -I $(SPDLOG_ROOT)/include \ + -I $(FFNVDECODER_ROOT) \ + -I $(FFNVDECODER_ROOT)/common/inc \ + -I $(FFNVDECODER_ROOT)/common/UtilNPP \ + -I $(CUDA)/include \ -LIBSPATH= -L ../DxDecoder -l:libDxDecoder.a \ - -L/usr/local/cuda/lib64 -lcuda -lcudart -lcurand -lcublas \ +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 -lvpd2 \ -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lface_detect -lvehicle_brand_cls -lvr_vehicle_type_10cls -lvr5905cls -lvehicle_recognize -lvehicle_color -lhuman_parsing -lhuman_car_parsing -lnon_vehicle_fea_trt -lvehicle_rear_recognition -lvf_int8 -lvp2_yolo\ @@ -53,9 +58,10 @@ LIBSPATH= -L ../DxDecoder -l:libDxDecoder.a \ -L $(OPENCV_ROOT)/lib -lopencv_video -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs\ -L$(AUTHORITY_DIR) -l:libauthority.a \ -L $(DEPEND_DIR)/include/boost_linux_x86_64/lib -l:libboost_system.a -l:libboost_thread.a \ + -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ -CFLAGS_LIB=-g -O0 -Wall -Wno-deprecated $(DEFS) -lz -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 @@ -69,10 +75,13 @@ SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) \ $(wildcard $(HIDE_MODEL_CAFFE2)/*.cpp) \ $(wildcard $(HIDE_MODEL_TRT)/*.cpp) \ $(wildcard $(SRC_ROOT)/snapshot_analysis/*.cpp) \ - + $(wildcard $(FFNVDECODER_ROOT)/*.cpp) + OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) -CU_SOURCES = $(wildcard ${SRC_ROOT}/snapshot_analysis/*.cu) +CU_SOURCES = $(wildcard ${SRC_ROOT}/snapshot_analysis/*.cu) \ + $(wildcard ${FFNVDECODER_ROOT}/*.cu) + CU_OBJS = $(patsubst %.cu, %.o, $(notdir $(CU_SOURCES))) all:$(TARGET) @@ -97,6 +106,13 @@ $(TARGET):$(OBJS) $(CU_OBJS) %.o:$(SRC_ROOT)/snapshot_analysis/%.cu @echo "#######################CU_OBJS:$@###############" $(NVCC) $(NFLAGS) -o $@ $< + +%.o:$(FFNVDECODER_ROOT)/%.cpp + $(XX) $(CFLAGS) -c $< + +%.o:$(FFNVDECODER_ROOT)/%.cu + @echo "#######################CU_OBJS:$@###############" + $(NVCC) $(NFLAGS) -o $@ $< .PHONY:clean clean: diff --git a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.FFNvDecoder b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.FFNvDecoder deleted file mode 100644 index bc88b66..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.FFNvDecoder +++ /dev/null @@ -1,121 +0,0 @@ -CC = gcc -XX = g++ -AR = ar - -CUDA = /usr/local/cuda -NVCC = /usr/local/cuda/bin/nvcc - -MNT_HOME = /home/cmhu/Project_VideoStructure - -PROJECT_ROOT= $(MNT_HOME)/vehicle_structure_platform.git0708-3080-trt-face -DEPEND_DIR = $(MNT_HOME)/Linux_3rdparty -SDK_ROOT = $(MNT_HOME)/SDK - -SRC_ROOT = $(PROJECT_ROOT)/src/VPT -FFNVDECODER_ROOT = $(PROJECT_ROOT)/src/FFNvDecoder - -UTOOLS_SSD_ROOT = $(DEPEND_DIR)/utools_trt_v1.4.0 -HIDE_MODEL_CAFFE2 = $(PROJECT_ROOT)/model/hidemodel_caffe_1108 -HIDE_MODEL_TRT = $(PROJECT_ROOT)/model/vptModeTrt -AUTHORITY_DIR = $(DEPEND_DIR)/authority_linux_20200114 -TRT_ROOT = $(DEPEND_DIR)/TensorRT-8.6.1.6 -OPENCV_ROOT = $(DEPEND_DIR)/opencv-4.5.4/release -FFMPEG_ROOT = $(DEPEND_DIR)/ffmpeg-5.0.1/release -SPDLOG_ROOT = $(DEPEND_DIR)/spdlog-1.9.2/release - -TARGET = $(DEPEND_DIR)/video_structure_sdk_20220512/libmvpt.so - -DEFS=-DOS_LINUX -DLOG_INFO2 - -INCLUDE= -I $(DEPEND_DIR)/include/boost_linux_x86_64/include \ - -I $(DEPEND_DIR)/include \ - -I $(OPENCV_ROOT)/include/opencv4 \ - -I $(OPENCV_ROOT)/include/opencv4/opencv2 \ - -I $(UTOOLS_SSD_ROOT) \ - -I $(SRC_ROOT) \ - -I $(TRT_ROOT)/include \ - -I $(DEPEND_DIR)/include/cairo \ - -I $(SRC_ROOT)/sort \ - -I $(SRC_ROOT)/snapshot_analysis \ - -I $(HIDE_MODEL_CAFFE2) \ - -I $(HIDE_MODEL_TRT) \ - -I $(AUTHORITY_DIR) \ - -I $(FFMPEG_ROOT)/include \ - -I $(SDK_ROOT)/face_detect2/face_detect \ - -I $(SPDLOG_ROOT)/include \ - -I $(FFNVDECODER_ROOT) \ - -I $(FFNVDECODER_ROOT)/common/inc \ - -I $(FFNVDECODER_ROOT)/common/UtilNPP \ - -I $(CUDA)/include \ - -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 -lvpd2 \ - -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lface_detect -lvehicle_brand_cls -lvr_vehicle_type_10cls -lvr5905cls -lvehicle_recognize -lvehicle_color -lhuman_parsing -lhuman_car_parsing -lnon_vehicle_fea_trt -lvehicle_rear_recognition -lvf_int8 -lvp2_yolo\ - -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 \ - -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ - -L $(OPENCV_ROOT)/lib -lopencv_video -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs\ - -L$(AUTHORITY_DIR) -l:libauthority.a \ - -L $(DEPEND_DIR)/include/boost_linux_x86_64/lib -l:libboost_system.a -l:libboost_thread.a \ - -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ - - -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 -NFLAGS = $(NFLAGS_LIB) $(INCLUDE) -std=c++11 - -LIBS= - -SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) \ - $(wildcard ${SRC_ROOT}/sort/*.cpp) \ - $(wildcard $(SRC_ROOT)/MD5/mID.cpp) \ - $(wildcard $(HIDE_MODEL_CAFFE2)/*.cpp) \ - $(wildcard $(HIDE_MODEL_TRT)/*.cpp) \ - $(wildcard $(SRC_ROOT)/snapshot_analysis/*.cpp) \ - $(wildcard $(FFNVDECODER_ROOT)/*.cpp) - -OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) - -CU_SOURCES = $(wildcard ${SRC_ROOT}/snapshot_analysis/*.cu) \ - $(wildcard ${FFNVDECODER_ROOT}/*.cu) - -CU_OBJS = $(patsubst %.cu, %.o, $(notdir $(CU_SOURCES))) - -all:$(TARGET) - -$(TARGET):$(OBJS) $(CU_OBJS) - rm -f $(TARGET) - $(XX) $(CFLAGS) -shared -o $@ $^ $(LIBSPATH) $(LIBS) -Wl,-rpath=$(DEPEND_DIR)/video_structure_sdk_20220512 - rm -f *.o - -%.o:$(SRC_ROOT)/%.cpp - $(XX) $(CFLAGS) -c $< -%.o:$(SRC_ROOT)/MD5/%.cpp - $(XX) $(CFLAGS) -c $< -%.o:$(SRC_ROOT)/sort/%.cpp - $(XX) $(CFLAGS) -c $< -%.o:$(HIDE_MODEL_CAFFE2)/%.cpp - $(XX) $(CFLAGS) -c $< -%.o:$(HIDE_MODEL_TRT)/%.cpp - $(XX) $(CFLAGS) -c $< -%.o:$(SRC_ROOT)/snapshot_analysis/%.cpp - $(XX) $(CFLAGS) -c $< -%.o:$(SRC_ROOT)/snapshot_analysis/%.cu - @echo "#######################CU_OBJS:$@###############" - $(NVCC) $(NFLAGS) -o $@ $< - -%.o:$(FFNVDECODER_ROOT)/%.cpp - $(XX) $(CFLAGS) -c $< - -%.o:$(FFNVDECODER_ROOT)/%.cu - @echo "#######################CU_OBJS:$@###############" - $(NVCC) $(NFLAGS) -o $@ $< - -.PHONY:clean -clean: - rm -f *.o $(TARGET) - - diff --git a/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.qx b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.qx new file mode 100644 index 0000000..f22b6ba --- /dev/null +++ b/vehicle_structure_platform.git0708-3080-trt-face/linux/VPT/Makefile.qx @@ -0,0 +1,105 @@ +CC = gcc +XX = g++ +AR = ar + +NVCC = /usr/local/cuda/bin/nvcc + +MNT_HOME = /home/cmhu/Project_VideoStructure + +PROJECT_ROOT= $(MNT_HOME)/vehicle_structure_platform.git0708-3080-trt-face +DEPEND_DIR = $(MNT_HOME)/Linux_3rdparty +SDK_ROOT = $(MNT_HOME)/SDK + +SRC_ROOT = $(PROJECT_ROOT)/src/VPT + +UTOOLS_SSD_ROOT = $(DEPEND_DIR)/utools_trt_v1.4.0 +HIDE_MODEL_CAFFE2 = $(PROJECT_ROOT)/model/hidemodel_caffe_1108 +HIDE_MODEL_TRT = $(PROJECT_ROOT)/model/vptModeTrt +AUTHORITY_DIR = $(DEPEND_DIR)/authority_linux_20200114 +TRT_ROOT = $(DEPEND_DIR)/TensorRT-8.6.1.6 +OPENCV_ROOT = $(DEPEND_DIR)/opencv-4.5.4/release +FFMPEG_ROOT = $(DEPEND_DIR)/ffmpeg-5.0.1/release + +TARGET = $(DEPEND_DIR)/video_structure_sdk_20220512/libmvpt.so + +DEFS=-DOS_LINUX -DLOG_INFO2 + +INCLUDE= -I $(DEPEND_DIR)/include/boost_linux_x86_64/include \ + -I $(DEPEND_DIR)/include \ + -I $(OPENCV_ROOT)/include/opencv4 \ + -I $(OPENCV_ROOT)/include/opencv4/opencv2 \ + -I $(UTOOLS_SSD_ROOT) \ + -I $(SRC_ROOT) \ + -I $(TRT_ROOT)/include \ + -I $(DEPEND_DIR)/include/cairo \ + -I $(SRC_ROOT)/sort \ + -I $(SRC_ROOT)/snapshot_analysis \ + -I $(SRC_ROOT)/../DxDecoder \ + -I /usr/local/cuda/include \ + -I $(HIDE_MODEL_CAFFE2) \ + -I $(HIDE_MODEL_TRT) \ + -I $(AUTHORITY_DIR) \ + -I $(FFMPEG_ROOT)/include \ + -I $(SDK_ROOT)/face_detect2/face_detect \ + +LIBSPATH= -L ../DxDecoder -l:libDxDecoder.a \ + -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 -lvpd2 \ + -L$(DEPEND_DIR)/video_structure_sdk_20220512 -lface_detect -lvehicle_brand_cls -lvr_vehicle_type_10cls -lvr5905cls -lvehicle_recognize -lvehicle_color -lhuman_parsing -lhuman_car_parsing -lnon_vehicle_fea_trt -lvehicle_rear_recognition -lvf_int8 -lvp2_yolo\ + -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 \ + -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ + -L $(OPENCV_ROOT)/lib -lopencv_video -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_imgcodecs\ + -L$(AUTHORITY_DIR) -l:libauthority.a \ + -L $(DEPEND_DIR)/include/boost_linux_x86_64/lib -l:libboost_system.a -l:libboost_thread.a \ + + +CFLAGS_LIB=-g -O0 -Wall -Wno-deprecated $(DEFS) -lz -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 +NFLAGS = $(NFLAGS_LIB) $(INCLUDE) -std=c++11 + +LIBS= + +SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) \ + $(wildcard ${SRC_ROOT}/sort/*.cpp) \ + $(wildcard $(SRC_ROOT)/MD5/mID.cpp) \ + $(wildcard $(HIDE_MODEL_CAFFE2)/*.cpp) \ + $(wildcard $(HIDE_MODEL_TRT)/*.cpp) \ + $(wildcard $(SRC_ROOT)/snapshot_analysis/*.cpp) \ + +OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) + +CU_SOURCES = $(wildcard ${SRC_ROOT}/snapshot_analysis/*.cu) +CU_OBJS = $(patsubst %.cu, %.o, $(notdir $(CU_SOURCES))) + +all:$(TARGET) + +$(TARGET):$(OBJS) $(CU_OBJS) + rm -f $(TARGET) + $(XX) $(CFLAGS) -shared -o $@ $^ $(LIBSPATH) $(LIBS) -Wl,-rpath=$(DEPEND_DIR)/video_structure_sdk_20220512 + rm -f *.o + +%.o:$(SRC_ROOT)/%.cpp + $(XX) $(CFLAGS) -c $< +%.o:$(SRC_ROOT)/MD5/%.cpp + $(XX) $(CFLAGS) -c $< +%.o:$(SRC_ROOT)/sort/%.cpp + $(XX) $(CFLAGS) -c $< +%.o:$(HIDE_MODEL_CAFFE2)/%.cpp + $(XX) $(CFLAGS) -c $< +%.o:$(HIDE_MODEL_TRT)/%.cpp + $(XX) $(CFLAGS) -c $< +%.o:$(SRC_ROOT)/snapshot_analysis/%.cpp + $(XX) $(CFLAGS) -c $< +%.o:$(SRC_ROOT)/snapshot_analysis/%.cu + @echo "#######################CU_OBJS:$@###############" + $(NVCC) $(NFLAGS) -o $@ $< + +.PHONY:clean +clean: + rm -f *.o $(TARGET) + + diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp index df72bfc..995c17f 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.cpp @@ -40,7 +40,8 @@ FFImgInfo* AbstractDecoder::snapshot(){ } // 队列中数据大于1 - gpuFrame = mFrameQueue.front(); + GPUFrame* frame = mFrameQueue.front(); + gpuFrame = frame->gpuFrame; m_queue_mutex.unlock(); break; } diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h index 94b616d..73caa60 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/AbstractDecoder.h @@ -57,6 +57,7 @@ struct FFDecConfig{ string gpuid; // gpu id bool force_tcp{true}; // 是否指定使用tcp连接 int skip_frame{1}; // 跳帧数 + bool keyframe_decode_mod; // 关键帧模式解码 int port; // gb28181接收数据的端口号 DECODE_REQUEST_STREAM_CALLBACK request_stream_cbk; // gb28181请求流 @@ -129,7 +130,7 @@ public: FFDecConfig m_cfg; - queue mFrameQueue; + queue mFrameQueue; mutex m_queue_mutex; mutex m_snapshot_mutex; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp index 54ce35f..25e7d94 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp @@ -21,7 +21,8 @@ void decode_finished_cbk(const void * userPtr){ DxDecoderWrap::DxDecoderWrap( const DxConfig * cfg ) { m_bClose = false; - m_pDec = NULL; + m_pDec = nullptr; + m_pHwData = nullptr; m_cfg.post_decoded_cbk = decoded_cbk; m_cfg.decode_finished_cbk = decode_finished_cbk; @@ -29,6 +30,11 @@ DxDecoderWrap::DxDecoderWrap( const DxConfig * cfg ) m_cfg.gpuid = std::to_string(cfg->devId); m_name = cfg->name; + m_decMode = cfg->decMode; + + CUdevice cuDevice; + cuDeviceGet(&cuDevice, cfg->devId); + cuCtxCreate(&m_cuda_cxt, 0, cuDevice); return; } @@ -60,6 +66,10 @@ int DxDecoderWrap::DxOpenDecoder( const char * uri, unsigned int skip ) m_pDec->setName(m_name) ; m_pDec->m_postDecArg = this; m_pDec->m_finishedDecArg = this; + if(1 == m_decMode) { + m_pDec->setDecKeyframe(true); + } + m_pDec->start(); LOG_INFO("[{}][{}]- 解码器初始化成功", m_name.c_str(), uri); return 0; } @@ -77,16 +87,29 @@ int DxDecoderWrap::DxOpenDecoder( const char * uri, unsigned int skip ) int DxDecoderWrap::DxCloseDecoder() { m_bClose = true; + if(m_pDec) { m_pDec->close(); delete m_pDec; m_pDec = nullptr; } - if(pHwData != nullptr){ - cudaFree(pHwData); + m_queue_frames_mutex.lock(); + while (m_queue_frames.size() > 0) { + GPUFrame * decodedFrame = m_queue_frames.front(); + m_queue_frames.pop(); + delete decodedFrame; + decodedFrame = nullptr; + } + m_queue_frames_mutex.unlock(); + + if(m_pHwData != nullptr){ + cudaFree(m_pHwData); } + cuCtxPopCurrent(nullptr); + cuCtxDestroy(m_cuda_cxt); + return 0; } @@ -112,8 +135,8 @@ int DxDecoderWrap::DxGetResolution( int * width, int * height ) return -1; } -int DxDecoderWrap::DxGetFrameCount(){ - +int DxDecoderWrap::DxGetFrameCount() +{ if(m_pDec != nullptr){ return m_pDec->GetFrameCount(); } @@ -150,9 +173,13 @@ bool DxDecoderWrap::DxDecoderIsRun() const } -bool DxDecoderWrap::DxFrameIsEmpty() const +bool DxDecoderWrap::DxFrameIsEmpty() { - return 0 == m_frames.counts; + m_queue_frames_mutex.lock(); + int count = m_queue_frames.size(); + m_queue_frames_mutex.unlock(); + + return 0 == count; } @@ -164,6 +191,11 @@ int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) } m_queue_frames_mutex.lock(); + if(m_queue_frames.size() <= 0) { + m_queue_frames_mutex.unlock(); + return -1; + } + GPUFrame * decodedFrame = m_queue_frames.front(); m_queue_frames.pop(); m_queue_frames_mutex.unlock(); @@ -171,17 +203,18 @@ int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) AVFrame* gpuFrame = decodedFrame->gpuFrame; cudaSetDevice(atoi(m_cfg.gpuid.c_str())); + cuCtxPushCurrent(m_cuda_cxt); cudaError_t cudaStatus; size_t rgbSize = 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char); - if(pHwData == nullptr){ - cudaStatus = cudaMalloc((void **)&pHwData, rgbSize); + if(m_pHwData == nullptr){ + cudaStatus = cudaMalloc((void **)&m_pHwData, rgbSize); if (cudaStatus != cudaSuccess) { LOG_ERROR("[{}]- cudaMalloc failed !!!", m_name.c_str()); return -1; } } cuda_common::setColorSpace( ITU_709, 0 ); - cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height); + cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], m_pHwData, gpuFrame->width, gpuFrame->height); cudaDeviceSynchronize(); if (cudaStatus != cudaSuccess) { LOG_ERROR("[{}]- CUDAToBGR failed !!!", m_name.c_str()); @@ -191,7 +224,7 @@ int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) frame->width = gpuFrame->width; frame->height = gpuFrame->height; frame->size = rgbSize; - frame->frame = pHwData; + frame->frame = m_pHwData; frame->timestamp = decodedFrame->ts; delete decodedFrame; @@ -200,12 +233,14 @@ int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) return 0; } -void DxDecoderWrap::post_decode_thread(GPUFrame * gpuFrame) { +void DxDecoderWrap::post_decode_thread(GPUFrame * decodedFrame) { while(!m_bClose) { m_queue_frames_mutex.lock(); if(m_queue_frames.size() < 3) { - m_queue_frames.push(gpuFrame); + // 入队 + m_queue_frames.push(decodedFrame); m_queue_frames_mutex.unlock(); + break; } else { m_queue_frames_mutex.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); @@ -214,5 +249,5 @@ void DxDecoderWrap::post_decode_thread(GPUFrame * gpuFrame) { } void DxDecoderWrap::decode_finished_thread() { - + m_bClose = true; } \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h index 7b4b301..b89448e 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h @@ -16,7 +16,7 @@ typedef struct DxConfig { int devId; // 设备(GPU)ID - int decMode; // 解码模式 + int decMode; // 解码模式: 0 全解码; 1 关键帧解码 int colorFmt; // 颜色空间 bool forceTcp; // 对于实时流,是否强制为TCP取流 std::string name; @@ -58,7 +58,7 @@ public: int DxGetResolution( int * width, int * height ); - bool DxFrameIsEmpty() const; + bool DxFrameIsEmpty(); int DxLockFrame( DxGPUFrame * frame ); int PauseDecoder(); @@ -72,8 +72,6 @@ public: private: bool m_bClose; - DxGPUFrames m_frames; - FFDecConfig m_cfg; string m_name; FFNvDecoder* m_pDec; @@ -81,7 +79,10 @@ private: std::queue m_queue_frames; std::mutex m_queue_frames_mutex; - unsigned char *pHwData {nullptr}; + unsigned char *m_pHwData {nullptr}; + CUcontext m_cuda_cxt; + + int m_decMode{0}; }; #endif \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp index 2873fa3..cf08bd7 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp @@ -59,14 +59,14 @@ bool FFNvDecoder::init(FFDecConfig& cfg) { m_cfg = cfg; - // todo : fstream判断错误 - fstream infile(cfg.uri); - if (infile.is_open()){ + FILE* fp; + fp=fopen(cfg.uri.c_str(),"rb"); + if(fp!=nullptr) { m_bReal = false; - infile.close(); - }else { + } else { m_bReal = true; } + fclose(fp); post_decoded_cbk = cfg.post_decoded_cbk; decode_finished_cbk = cfg.decode_finished_cbk; @@ -119,6 +119,7 @@ bool FFNvDecoder::init(const char* uri, const char* gpuid, bool force_tcp) return false; m_fps = av_q2d(stream ->avg_frame_rate); + m_nb_frames = stream->nb_frames; avctx->opaque = this; // 设置解码器管理器的像素格式回调函数 @@ -197,6 +198,7 @@ void FFNvDecoder::decode_thread() // long start_time = get_cur_time(); + unsigned long long index = 0; while (m_bRunning) { if (!m_bReal) @@ -220,15 +222,10 @@ void FFNvDecoder::decode_thread() if (result == AVERROR_EOF || result < 0) { av_packet_unref(pkt); - LOG_ERROR("Failed to read frame!"); + LOG_INFO("Failed to read frame!"); break; } - if (m_dec_keyframe && !(pkt->flags & AV_PKT_FLAG_KEY)) { - av_packet_unref(pkt); - continue; - } - if (m_bReal) { if (m_bPause) @@ -240,6 +237,14 @@ void FFNvDecoder::decode_thread() } if (stream_index == pkt->stream_index){ + + index++; + + if (m_dec_keyframe && !(pkt->flags & AV_PKT_FLAG_KEY)) { + av_packet_unref(pkt); + continue; + } + result = avcodec_send_packet(avctx, pkt); if (result < 0){ av_packet_unref(pkt); @@ -260,7 +265,10 @@ void FFNvDecoder::decode_thread() if(gpuFrame != nullptr){ m_queue_mutex.lock(); if(mFrameQueue.size() <= 10){ - mFrameQueue.push(gpuFrame); + GPUFrame* frame = new GPUFrame(); + frame->ts = index; + frame->gpuFrame = gpuFrame; + mFrameQueue.push(frame); }else{ av_frame_free(&gpuFrame); } @@ -286,8 +294,9 @@ void FFNvDecoder::decode_thread() // 清空队列 while(mFrameQueue.size() > 0){ - AVFrame * gpuFrame = mFrameQueue.front(); - av_frame_free(&gpuFrame); + GPUFrame * frame = mFrameQueue.front(); + delete frame; + frame = nullptr; mFrameQueue.pop(); } @@ -323,18 +332,15 @@ void FFNvDecoder::post_decode_thread(){ std::lock_guard l(m_snapshot_mutex); // 取队头数据 m_queue_mutex.lock(); - AVFrame * gpuFrame = mFrameQueue.front(); + GPUFrame* frame = mFrameQueue.front(); mFrameQueue.pop(); m_queue_mutex.unlock(); // 跳帧 if (skip_frame == 1 || index % skip_frame == 0){ - GPUFrame* frame = new GPUFrame(); - frame->ts = index; - frame->gpuFrame = gpuFrame; post_decoded_cbk(m_postDecArg, frame); } - av_frame_free(&gpuFrame); + // av_frame_free(&gpuFrame); index++; } @@ -403,6 +409,5 @@ float FFNvDecoder::fps(){ } unsigned long long FFNvDecoder::GetFrameCount() { - // todo - return 1; + return m_nb_frames; } \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h index b317d2b..cafc5dd 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h @@ -60,4 +60,5 @@ private: bool m_bReal; // 是否实时流 float m_fps; + unsigned long long m_nb_frames; }; \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h index 98cb1d8..0e89424 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h @@ -3,7 +3,7 @@ #include #include "common.h" #include -#include "../DxDecoder/DxDecoderWrap.h" +#include "../FFNvDecoder/DxDecoderWrap.h" using std::map; using std::vector; class ImageSaveCache 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 2b1e6f5..39cbf63 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 @@ -394,7 +394,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID) tasks[i].taskObjCallbackFunc = nullptr; tasks[i].taskRealTimeCallbackFunc = nullptr; - m_snaphot_helper.finish_task_ss_analysis(taskID, m_hp_analysis_config, m_hcp_analysis_config, m_vehicle_analysis_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config); //�Ƿ�����������ʶ��); if (tasks[i].folderName) @@ -488,11 +487,15 @@ void CMutliSourceVideoProcess::FinishViewTask() printf("-----------------------finish view task-----------------------\n"); } - -//bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) -bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, int jpeg_quality, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) //debug by zsh +bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh { - //checkGpuMem(); + const char* videoFileName = tparam.video_filename; + const char* resultFolderLittle = tparam.result_folder_little; + const char* resultFolder = tparam.result_folder; + const char* resultFolderface = tparam.result_folder_face; + VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc = tparam.obj_snapshot_callback_func; + VIDEO_REALTIME_CALLBACK realTimeCallbackFunc = tparam.rt_view_callback_func; + std::lock_guard l(_tx_add_task); using std::placeholders::_1; // printf("begin real add task\n"); @@ -503,31 +506,16 @@ bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* re VPTResult.resize(capacity); } - string sVideoFileName = videoFileName; - - string target = "file://"; - int pos = sVideoFileName.find(target); - if (pos == 0) { - int n = target.size(); - sVideoFileName = sVideoFileName.erase(pos, n); - } - pos = sVideoFileName.find_first_of('?'); - if (pos != string::npos) { - sVideoFileName = sVideoFileName.substr(0, pos); - } - Task new_task = {}; new_task.taskID = TotalTask; new_task.taskFileSource = videoFileName; - memcpy(new_task.task_min_boxsize, minBoxsize, sizeof(sy_rect)* DETECTTYPE); - + memcpy(new_task.task_min_boxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); DxConfig cfg = { 0 }; cfg.devId = mgpuid; - cfg.decMode = 0; - cfg.colorFmt = 0; cfg.forceTcp = false; - cfg.type = DX_DECODER_TYPE_SFXLAB; + cfg.decMode = tparam.decMode; + cfg.name = std::to_string(new_task.taskID); new_task.taskTcuvid = new DxDecoderWrap(&cfg); if (NULL == new_task.taskTcuvid) { @@ -631,8 +619,8 @@ bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* re new_task_info.snapshot_folder = new_task.folderNameLittle; new_task_info.snapshot_folder_face = new_task.folderNameFace; new_task_info.task_total_framecount = new_task.taskTotalFrameCount; - new_task_info._on_image_display = on_image_display; - new_task_info.jpeg_quality_ = jpeg_quality; //debug by zsh + new_task_info._on_image_display = tparam.on_image_display; + new_task_info.jpeg_quality_ = tparam.jpeg_quality; //debug by zsh new_task_info.obj_callback = new_task.taskObjCallbackFunc; m_snaphot_helper.add_task_info(new_task.taskID, new_task_info); @@ -640,20 +628,8 @@ bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* re TaskinPlay++; tasks.push_back(new_task); - // printf("finish push tasks\n"); - - //return 1; - //std::cout<<__LINE__<<"of"<<__FILE__<<"debug\n"; - if (!ProcessFlag) - { - /*for (int num = 0; num < 5; ++num) - {*/ - //create_thread()��һ���������������Դ���thead���������̣߳�ͬʱ�����ڲ���list - // group.create_thread(boost::bind(&runchild , num)) ; - //saveSnapshotsThreadGroup.create_thread(boost::bind(SnapshotThreadProcess, this, 0)); - //} + if (!ProcessFlag) { ProcessThread = boost::thread(ThreadProcess, this); - //std::cout << "begin algorithm" << std::endl; ProcessFlag = true; } @@ -668,8 +644,7 @@ int CMutliSourceVideoProcess::AddOperator(task_param tparam) if (!ProcessFlag) { - //AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.result_folder_face, tparam.on_image_display, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); - AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.result_folder_face, tparam.on_image_display, tparam.jpeg_quality, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); //debug by zsh + AddTask(tparam); boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(500)); } else @@ -680,12 +655,14 @@ int CMutliSourceVideoProcess::AddOperator(task_param tparam) Operator newOper; newOper.changeTaskID = 0; newOper.changeTaskOperator = ADDTASK; - newOper.videoFileName = tparam.video_filename; - newOper.resultFolderLittleName = tparam.result_folder_little; - newOper.result_folder_face = tparam.result_folder_face; - newOper.resultFolderName = tparam.result_folder; + + strcpy(newOper.videoFileName, tparam.video_filename); + strcpy(newOper.resultFolderLittleName, tparam.result_folder_little); + strcpy(newOper.resultFolderName, tparam.result_folder); + strcpy(newOper.result_folder_face, tparam.result_folder_face); newOper.on_image_display = tparam.on_image_display; - newOper.jpeg_quality = tparam.jpeg_quality; //debug by zsh + newOper.jpeg_quality = tparam.jpeg_quality; + newOper.decMode = tparam.decMode; newOper.taskObjCallbackFunc = tparam.obj_snapshot_callback_func; newOper.taskRealTimeCallbackFunc = tparam.rt_view_callback_func; memcpy(newOper.minBoxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); @@ -741,7 +718,6 @@ void CMutliSourceVideoProcess::AddOperator(int taskID, int taskOper) Operator newOper = {}; newOper.changeTaskID = taskID; newOper.changeTaskOperator = TaskOperator(taskOper); - newOper.videoFileName = NULL; //TaskOperatorQ.push(newOper); TaskOperatorQ.push_back(newOper); } @@ -757,8 +733,20 @@ void CMutliSourceVideoProcess::OperatorTask() switch (newOperator.changeTaskOperator) { case ADDTASK: - //AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); - AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.jpeg_quality, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); //debug by zsh + { + task_param tparam; + strcpy(tparam.video_filename, newOperator.videoFileName); + strcpy(tparam.result_folder_little, newOperator.resultFolderLittleName); + strcpy(tparam.result_folder, newOperator.resultFolderName); + strcpy(tparam.result_folder_face, newOperator.result_folder_face); + tparam.on_image_display = newOperator.on_image_display; + tparam.jpeg_quality = newOperator.jpeg_quality; + memcpy(tparam.minBoxsize, newOperator.minBoxsize, sizeof(sy_rect)* DETECTTYPE); + tparam.obj_snapshot_callback_func = newOperator.taskObjCallbackFunc; + tparam.rt_view_callback_func = newOperator.taskRealTimeCallbackFunc; + tparam.decMode = newOperator.decMode; + AddTask(tparam); + } break; case PAUSETASK: PauseTask(newOperator.changeTaskID); @@ -1031,44 +1019,9 @@ DWORD ThreadProcess(LPVOID param) { if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) { - if (pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&frame) == 0) - { - if (!pThreadParam->tasks[i].task_algorithm_data.frame && frame.width > 0 && frame.height > 0) - { - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->tasks[i].task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(unsigned char)); - if (cudaStatus != cudaSuccess) { - fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); - break; - } - - pThreadParam->tasks[i].task_algorithm_data.height = frame.height; - pThreadParam->tasks[i].task_algorithm_data.width = frame.width; - pThreadParam->tasks[i].task_algorithm_data.size = frame.size; - - pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3); - pThreadParam->tasks[i].taskDataToRT = (float*)malloc(3 * frame.height * frame.width * sizeof(unsigned char)); - AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1); - } - - //copy decode data - if (pThreadParam->tasks[i].task_algorithm_data.frame) - { - int height = frame.height; - int width = frame.width; - - Nv12ToColor24( (unsigned char *)frame.frame, width, (unsigned char *)pThreadParam->tasks[i].task_algorithm_data.frame, 3 * width, width, height, 0 ); - - pThreadParam->tasks[i].task_algorithm_data.timestamp = frame.timestamp; - - k.insert(i); - pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); - } - else - { - std::cout << "NOT ALLOC: pThreadParam->tasks[i].taskDataToBackup.frame" << pThreadParam->tasks[i].task_algorithm_data.frame << std::endl; - } - - pThreadParam->tasks[i].taskTcuvid->DxUnlockFrame(); + if(pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&pThreadParam->tasks[i].task_algorithm_data) == 0) { + k.insert(i); + pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); } } else if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && !pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) @@ -1756,7 +1709,7 @@ DWORD ThreadProcess(LPVOID param) vector().swap(deleteObjectID[i]); vector>().swap(deleteObjectID); - // pThreadParam->m_snaphot_helper.object_attri_analysis(); + pThreadParam->m_snaphot_helper.object_attri_analysis(); #ifdef LOG_INFO2 long long second_analysis_time2 = get_cur_time_ms(); @@ -1788,7 +1741,7 @@ DWORD ThreadProcess(LPVOID param) } long long costTime1 = get_cur_time_ms() - begintime1; std::cout << "==================== Process Thread is Finished: " << std::endl; - printf("total frame cost time = %lld us, process times: %d \n", costTime1, process_times); + printf("total frame cost time = %lld us, process times: %d total_count: %d \n", costTime1, process_times, total_count); pThreadParam->m_snaphot_helper.snapShotInfo.clear(); pThreadParam->ProcessFlag = false; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.FFNvDecoder b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.FFNvDecoder deleted file mode 100644 index 813f94f..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.FFNvDecoder +++ /dev/null @@ -1,1862 +0,0 @@ -#include "MutliSourceVideoProcess.h" - -#ifdef _MSC_VER -#include -#include -#include "../putText.h" -#endif -#include -#include -#include -#include - -#include "face_detect.h" -#include "CropImg.h" -//#include -//#include -//#include -//#pragma comment(lib, "DbgHelp.Lib") -//#pragma comment(lib, "ShLwApi.lib") -//********************************************************// -//1.Ϊʲô��ʱ�򷵻ص�index=2��ȴδ�����ﳵ�ķ�������Ϊindex�ں�����Ϊ��2�����Ǵ�ʱ�Ŀ��ղ�������֮ǰ�Ŀ��գ����Կ���δ���£�����ͼ���С����Ϊ112*224 - -#define AUTHORIZATION -//#define DQ_AUTHORIZATION - -#include - -#ifdef DQ_AUTHORIZATION -#include "license_validator.h" -#ifdef _MSC_VER -#define productSN "2AC69C4638EF46c884BD2BF132FF41D9" //��ǧ����-������ȨID -#else -#define productSN "683E9D5E56474da5A4C2D3EA9A00568E" //��ǧ����-������ȨID -#endif -#endif - -#ifdef AUTHORIZATION -#include "authority.h" -#ifdef _MSC_VER -#define productSN "4ACFCBE67EF645AB8F0B4CFCDD1926F1" //WINDOWS�����Ʒϵ�к� -#else -#define productSN "4FD45501D5104F0C8C4BE530FC872F46" //LINUX�����Ʒϵ�к� -//#define productSN "7CF8B4797F9E441686145BED07F662DE" //LINUX�����Ʒϵ�к� -#endif -#endif - -#include "../DxDecoder/ColorSpace.h" - -//#define LOG_INFO //�Ƿ������ٴ�ӡ -// #define SKIP_FRMAE 5 //��֡֡�� -#define EXTIME 500 - -static int TaskID = 0; - -auto show_gpu_syimage_ = [](sy_img& cur_frame) { - - unsigned char* cpu_data = new unsigned char[3 * cur_frame.w_ * cur_frame.h_]; - cudaMemcpy(cpu_data, cur_frame.data_, 3 * cur_frame.w_ * cur_frame.h_ * sizeof(unsigned char), cudaMemcpyDeviceToHost); - cv::Mat img(cur_frame.h_, cur_frame.w_, CV_8UC3, cpu_data); - - cv::imshow("img", img); - cv::waitKey(0); - delete[] cpu_data; -}; - -auto show_gpu_image_ = [](DxGPUFrame& cur_frame) { - - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); - - cv::imshow("img2", img); - cv::waitKey(0); - delete[] cpu_data; -}; - -auto show_gpu_image_withrect_ = [](DxGPUFrame& cur_frame, sy_rect &rect) { - - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); - cv::rectangle(img, cv::Rect(rect.left_, rect.top_, rect.width_, rect.height_), cv::Scalar(25, 25, 250), 2, 8, 0); - cv::imshow("ori", img); - cv::waitKey(0); - delete[] cpu_data; -}; - -auto show_gpu_image_withfdinfo_ = [](DxGPUFrame& cur_frame, fd_info &face_info) { - - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); - - printf("%d %d\n", cur_frame.width , cur_frame.height); - for (int ii = 0; ii < 25; ii++) - { - printf("(%d %d) ", face_info.facial_fea_point[ii].x_, face_info.facial_fea_point[ii].y_); - cv::circle(img, cv::Point(face_info.facial_fea_point[ii].x_, face_info.facial_fea_point[ii].y_), 1, cv::Scalar(0, 255, 0)); - - } - //cv::rectangle(img, cv::Rect(face_info.face_position.left_, face_info.face_position.top_, face_info.face_position.width_, face_info.face_position.height_), cv::Scalar(25, 25, 250), 2, 8, 0); - - cv::Mat big_img; - cv::resize(img, big_img, cv::Size(400, 400)); - - - cv::imshow("ori33", img); - cv::imshow("ori44", big_img); - cv::waitKey(0); - delete[] cpu_data; -}; - -auto show_gpu_image_with2rect_ = [](DxGPUFrame& cur_frame, sy_rect &rect, sy_rect &rect2) { - - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); - cv::rectangle(img, cv::Rect(rect.left_, rect.top_, rect.width_, rect.height_), cv::Scalar(25, 25, 250), 1, 8, 0); - cv::rectangle(img, cv::Rect(rect2.left_, rect2.top_, rect2.width_, rect2.height_), cv::Scalar(25, 250, 25), 1, 8, 0); - cv::imshow("ori2", img); - cv::waitKey(0); - delete[] cpu_data; -}; - -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(); -} - -std::function show_gpu_img_func = show_gpu_image_; - -void check_thread(void* handle); -DWORD ThreadProcess(LPVOID param); - - -//std::ofstream g_os("./cudaMem.txt", std::ofstream::out | std::ofstream::trunc); -CMutliSourceVideoProcess::CMutliSourceVideoProcess() -{ -} - -// dump�ļ� -//static LONG WINAPI CustomExceptionCrashHandler(_In_ EXCEPTION_POINTERS *CONST pException) -//{ -// char dumpPath[MAX_PATH]; -// -// BOOL tempDump = FALSE; -// do { -// -// if (0 == GetTempPath(_countof(dumpPath), dumpPath)) -// break; -// -// // %temp%Ŀ¼���½�dump�ļ��� -// if (!PathAppend(dumpPath, "dump")) -// break; -// CreateDirectory(dumpPath, NULL); -// // dump�ļ�����dump�ļ��ļ��� ���Զ����޸� -// if (!PathAppend(dumpPath, "HSTProcessor")) -// break; -// -// SYSTEMTIME lclTm; -// GetLocalTime(&lclTm); -// char ext[29]; -// // dump�ļ�������ʱ���� -// if (FAILED(StringCchPrintf(ext, _countof(ext), ".%04hu%02hu%02hu%02hu%02hu%02hu.unhdlexc.dmp", lclTm.wYear, lclTm.wMonth, lclTm.wDay, lclTm.wHour, lclTm.wMinute, lclTm.wSecond))) -// break; -// if (FAILED(StringCchCat(dumpPath, _countof(dumpPath), ext))) -// break; -// -// tempDump = TRUE; -// } while (FALSE); -// HANDLE CONST dumpFile = CreateFile(dumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); -// if (INVALID_HANDLE_VALUE == dumpPath) -// { -// return EXCEPTION_EXECUTE_HANDLER; -// } -// -// MINIDUMP_EXCEPTION_INFORMATION dumpInfo; -// dumpInfo.ThreadId = GetCurrentThreadId(); -// dumpInfo.ExceptionPointers = pException; -// dumpInfo.ClientPointers = TRUE; -// -// if (FAILED(MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL))) -// { -// CloseHandle(dumpFile); -// } -// CloseHandle(dumpFile); -// -// return EXCEPTION_EXECUTE_HANDLER; -//} - - -CMutliSourceVideoProcess::~CMutliSourceVideoProcess() -{ - //��־����ʼ�� - //DxUninitializeLog(); -} - -int CMutliSourceVideoProcess::FinishProcessThread() -{ - if (thrd_status == 0) - { - thrd.interrupt(); - thrd.join(); - thrd_status = -1; - } - - ProcessThread.interrupt(); //interrupt thread - ProcessThread.join(); //waiting thread finish - - VPT_Release(VPT_Handle); - m_face_det_module->face_det_module_release(); - - m_snaphot_helper.snapshot_helper_release(); - - return 1; -} - -int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc, VIDEO_FINISH_CALLBACK tFinishCallbackFunc) -{ - // checkGpuMem(); - licence_status = -1; - thrd_status = -1; - //SetUnhandledExceptionFilter(CustomExceptionCrashHandler); - - int ret = SUCCESS; - /*DxLogConfig sCfg = { 0 }; - sCfg.serviceID = vptParam.serviceID; - sCfg.limitSize = vptParam.limitSize; - strcpy(sCfg.name, vptParam.name); - strcpy(sCfg.path, vptParam.path); - DxInitializeLog(&sCfg);*/ - - /*printf("=====================��ȨERROR==================\n"); - printf("=====================��ȨERROR==================\n"); - printf("=====================��ȨERROR==================\n");*/ -#ifdef AUTHORIZATION -#ifdef _WIN32 - if (SUCCESS == (ret = sy_licence(productSN))) -#elif __linux__ - char wtime[15]; - memset(wtime, 0, 15); - char * time = wtime; - if (SUCCESS == (ret = sy_licence(productSN, &time))) -#endif -#else - ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2); - if (ret == SUCCESS) -#endif - { - cuInit(0); - int device_count = 0; - cuDeviceGetCount(&device_count); - - if (vptParam.gpuid >= device_count) - { - printf("\nGPU_ID PARAM WRONG, gpuid: %d device_count: %d\n", vptParam.gpuid, device_count); - return GPUID_PARAM_ERROR; - } - - CUdevice dev = 0; - size_t memSize = 0; - dev = vptParam.gpuid; - - CUresult rlt = CUDA_SUCCESS; - rlt = cuDeviceTotalMem(&memSize, dev); - - gpu_total_memory = (float)memSize / (1024 * 1024); - - if (gpu_total_memory < 9000) //8G�Դ棬С�ڴ淽�� - section_batch_size = 10; - else - section_batch_size = 20; - - if(vptParam.skip_frame > 0){ - // 默认值为5 - skip_frame_ = vptParam.skip_frame; - } - - VPTProcess_PARAM param{}; - //param.c = 3; - param.mode = DEVICE_GPU; - param.gpuid = vptParam.gpuid; - //param.threshold = 0.6; - param.threshold = 0.5; - param.engine = ENGINE_TENSORRT; - param.max_batch = section_batch_size; - param.serialize_file = "./serialize_file/VPT"; - param.auth_license = vptParam.auth_license; - mgpuid = vptParam.gpuid; - VPT_Handle = NULL; - ret = VPT_Init(VPT_Handle, param); - if (0 != ret) - return ret; - - m_face_det_module = nullptr; - if (vptParam.face_det_config == SY_CONFIG_OPEN) - { - m_face_det_module = new face_det_module(); - printf("begin init face det\n"); - m_face_det_module->face_det_module_init(vptParam.gpuid, vptParam.auth_license); - } - - viewTaskID = -1; - TaskinPlay = 0; - TotalTask = 0; - capacity = 20; - VPTResult.resize(capacity); - //dwThreadID = 0; - ProcessFlag = false; - SourceFlag = false; - - mModeSnapshotVideo = "cpu"; - mModeSnapshotLittle = "cpu"; - - taskFinishCallbackFunc = nullptr; - if (tFinishCallbackFunc != nullptr) - taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1); - - taskObjInfoCallbackFunc = nullptr; - if (tObjInfoCallbackFunc != nullptr) - taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1); - - minDistance[0] = minDistance[2] = 35; //left right - minDistance[1] = minDistance[3] = 50; //top bottom - - m_hp_analysis_config = vptParam.hp_analysis_config; - m_hcp_analysis_config = vptParam.hcp_analysis_config; - m_vehicle_analysis_config = vptParam.vehicle_analysis_config; - m_hf_recg_config = vptParam.hf_recg_config; - m_hcf_recg_config = vptParam.hcf_recg_config; - m_vcf_recg_config = vptParam.vcf_recg_config; - m_face_det_config = vptParam.face_det_config; - - m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, vptParam.auth_license, vptParam.wait_framecount, m_hp_analysis_config, \ - m_hcp_analysis_config, m_vehicle_analysis_config, m_vehicle_recg_config, m_vehicle_plate_det_recg_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config); - if (ret == SUCCESS) //�ɹ� - { - licence_status = 0; -#ifdef AUTHORIZATION - thrd = boost::thread(check_thread, this); -#endif - thrd_status = 0; - } - - } - else - { - return AUTHOR_ERROR; - } -/* -#ifdef AUTHORIZATION -#ifdef __linux__ - if (wtime) - { - delete[] wtime; - wtime = NULL; - } -#endif -#endif */ // debug by zsh - return ret; -} - -void CMutliSourceVideoProcess::FinishDecode(const int taskID) -{ - boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(400)); - - for (int i = 0; i < tasks.size(); i++) - { - if (tasks[i].taskID == taskID && tasks[taskID].taskTcuvid != NULL) - { - tasks[taskID].taskState == FINISH; - tasks[taskID].taskTcuvid->DxCloseDecoder(); - delete tasks[taskID].taskTcuvid; - tasks[taskID].taskTcuvid = NULL; - printf("-----------------------finish task: %d-----------------------\n", taskID); - break; - } - } - -} - -void CMutliSourceVideoProcess::FinishTask(const int taskID) -{ - for (int i = 0; i < tasks.size(); i++) - { - if (tasks[i].taskID == taskID) - { - //printf("first begin finish\n"); - if (tasks[i].taskState == PLAY) TaskinPlay--; - tasks[i].taskState = FINISH; - tasks[i].taskFileSource = nullptr; - tasks[i].taskObjCallbackFunc = nullptr; - tasks[i].taskRealTimeCallbackFunc = nullptr; - - - m_snaphot_helper.finish_task_ss_analysis(taskID, m_hp_analysis_config, m_hcp_analysis_config, m_vehicle_analysis_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config); //�Ƿ�����������ʶ��); - - if (tasks[i].folderName) - { - delete tasks[i].folderName; - tasks[i].folderName = nullptr; - } - - - if (tasks[i].folderNameLittle) - { - delete tasks[i].folderNameLittle; - tasks[i].folderNameLittle = nullptr; - } - - - if (tasks[i].taskDataToRT) - { - free(tasks[i].taskDataToRT); - tasks[i].taskDataToRT = nullptr; - } - - tasks[i].frameImage.release(); - - - if (tasks[i].task_algorithm_data.frame) - { - cudaFree(tasks[i].task_algorithm_data.frame); - tasks[i].task_algorithm_data.frame = nullptr; - } - - FinishTaskTracker(VPT_Handle, taskID); - - if (viewTaskID == taskID) viewTaskID = -1; - - - break; - } - } -} - -void CMutliSourceVideoProcess::PauseTask(const int taskID) -{ - for (int i = 0; i < tasks.size(); i++) - { - if (tasks[i].taskID == taskID) - { - if (tasks[i].taskState == PLAY) TaskinPlay--; - tasks[i].taskState = PAUSE; - PauseTaskTracker(VPT_Handle, taskID); - tasks[i].taskTcuvid->PauseDecoder(); - if (viewTaskID == taskID) viewTaskID = -1; - printf("-----------------------pasue task: %d-----------------------\n", taskID); - break; - } - } -} - -void CMutliSourceVideoProcess::RestartTask(const int taskID) -{ - for (int i = 0; i < tasks.size(); i++) - { - if (tasks[i].taskID == taskID) - { - tasks[i].taskState = PLAY; - TaskinPlay++; - RestartTaskTraker(VPT_Handle, taskID); - tasks[i].taskTcuvid->ResumeDecoder(); - printf("-----------------------restart task: %d-----------------------\n", taskID); - break; - } - } -} - -//ʵʱ�鿴�ӿ� �ɿ���һ·��ʵʱ�鿴������·�ķ������OSD��Ȼ�󽫻���ͨ���ص��������ظ��û� -void CMutliSourceVideoProcess::ViewTask(const int taskID) -{ - if (tasks.size() > taskID && tasks[taskID].taskState == PLAY) - { - viewTaskID = taskID; - printf("-----------------------view task: %d-----------------------\n", taskID); - } - else - printf("Only can view playing task!"); -} - -//����ʵʱ�鿴�ӿڣ��ر�ʵʱ����ķ��� -void CMutliSourceVideoProcess::FinishViewTask() -{ - viewTaskID = -1; - printf("-----------------------finish view task-----------------------\n"); -} - - -//bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) -bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, int jpeg_quality, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) //debug by zsh -{ - //checkGpuMem(); - std::lock_guard l(_tx_add_task); - using std::placeholders::_1; - // printf("begin real add task\n"); - if (TaskinPlay >= capacity) - { - //cout << "********************** resize capacity *************************" << endl; - capacity *= 2; - VPTResult.resize(capacity); - } - - string sVideoFileName = videoFileName; - - string target = "file://"; - int pos = sVideoFileName.find(target); - if (pos == 0) { - int n = target.size(); - sVideoFileName = sVideoFileName.erase(pos, n); - } - pos = sVideoFileName.find_first_of('?'); - if (pos != string::npos) { - sVideoFileName = sVideoFileName.substr(0, pos); - } - - Task new_task = {}; - new_task.taskID = TotalTask; - new_task.taskFileSource = videoFileName; - memcpy(new_task.task_min_boxsize, minBoxsize, sizeof(sy_rect)* DETECTTYPE); - - - DxConfig cfg = { 0 }; - cfg.devId = mgpuid; - cfg.forceTcp = false; - cfg.name = std::to_string(new_task.taskID); - new_task.taskTcuvid = new DxDecoderWrap(&cfg); - if (NULL == new_task.taskTcuvid) - { - printf("Add New DxDecoder Failed!"); - AddTaskSucFlag = -1; - return false; - } - - if (new_task.taskTcuvid->DxOpenDecoder(new_task.taskFileSource, skip_frame_) != 0) - { - cout << "Add Task Failed! Please check you video file name!" << endl; - delete new_task.taskTcuvid; - new_task.taskTcuvid = NULL; - AddTaskSucFlag = -1; - return false; - } - - int tmp_total_frame = new_task.taskTcuvid->DxGetFrameCount(); - - printf("finish add codec. tmp_total_frame: %d \n", tmp_total_frame); - - new_task.taskState = PLAY; - new_task.task_algorithm_data.frame = NULL; - new_task.taskFrameCount = 0; - new_task.taskLastFrameCount = 0; - new_task.taskDataToRT = NULL; - - new_task.taskObjCallbackFunc = nullptr; - if (objCallbackFunc != nullptr) - new_task.taskObjCallbackFunc = std::bind(objCallbackFunc, this, 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.taskTotalFrameCount = tmp_total_frame; - if (resultFolderLittle == NULL) - { - new_task.folderNameLittle = NULL; - } - else - { - new_task.folderNameLittle = new char[strlen(resultFolderLittle) + 2]{}; - strcpy(new_task.folderNameLittle, resultFolderLittle); - - int length = strlen(new_task.folderNameLittle); - if (new_task.folderNameLittle[length - 1] != '\\' && new_task.folderNameLittle[length - 1] != '/') - { - new_task.folderNameLittle[length] = '/'; - new_task.folderNameLittle[length + 1] = '\0'; - } - - CreateResultFolder(new_task.folderNameLittle, ""); - } - - - if (resultFolder == NULL) - { - new_task.folderName = NULL; - } - else - { - new_task.folderName = new char[strlen(resultFolder) + 2]{}; - strcpy(new_task.folderName, resultFolder); - - int length = strlen(new_task.folderName); - if (new_task.folderName[length - 1] != '\\' && new_task.folderName[length - 1] != '/') - { - new_task.folderName[length] = '/'; - new_task.folderName[length + 1] = '\0'; - } - - CreateResultFolder(new_task.folderName, ""); - } - - if (resultFolderface == NULL) - { - new_task.folderNameFace = NULL; - } - else - { - new_task.folderNameFace = new char[strlen(resultFolderface) + 2]{}; - strcpy(new_task.folderNameFace, resultFolderface); - - int length = strlen(new_task.folderNameFace); - if (new_task.folderNameFace[length - 1] != '\\' && new_task.folderNameFace[length - 1] != '/') - { - new_task.folderNameFace[length] = '/'; - new_task.folderNameFace[length + 1] = '\0'; - } - - CreateResultFolder(new_task.folderNameFace, ""); - } - - // printf("finish create folder\n"); - - //Sleep(10); - //std::cout << "CreateResultFolder" << std::endl; - TASK_INFO new_task_info = {}; - new_task_info.image_folder = new_task.folderName; - new_task_info.snapshot_folder = new_task.folderNameLittle; - new_task_info.snapshot_folder_face = new_task.folderNameFace; - new_task_info.task_total_framecount = new_task.taskTotalFrameCount; - new_task_info._on_image_display = on_image_display; - new_task_info.jpeg_quality_ = jpeg_quality; //debug by zsh - new_task_info.obj_callback = new_task.taskObjCallbackFunc; - m_snaphot_helper.add_task_info(new_task.taskID, new_task_info); - - TotalTask++; - TaskinPlay++; - tasks.push_back(new_task); - - // printf("finish push tasks\n"); - - //return 1; - //std::cout<<__LINE__<<"of"<<__FILE__<<"debug\n"; - if (!ProcessFlag) - { - /*for (int num = 0; num < 5; ++num) - {*/ - //create_thread()��һ���������������Դ���thead���������̣߳�ͬʱ�����ڲ���list - // group.create_thread(boost::bind(&runchild , num)) ; - //saveSnapshotsThreadGroup.create_thread(boost::bind(SnapshotThreadProcess, this, 0)); - //} - ProcessThread = boost::thread(ThreadProcess, this); - //std::cout << "begin algorithm" << std::endl; - ProcessFlag = true; - } - - printf("-----------------------add task: %d-----------------------\n", tasks.size() - 1); - AddTaskSucFlag = 1; - return true; -} - -int CMutliSourceVideoProcess::AddOperator(task_param tparam) -{ - //boost::mutex::scoped_lock lock(process_thread_mutex); - - if (!ProcessFlag) - { - //AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.result_folder_face, tparam.on_image_display, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); - AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.result_folder_face, tparam.on_image_display, tparam.jpeg_quality, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); //debug by zsh - boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(500)); - } - else - { - // printf("add first task in operator queue\n"); - std::unique_lock l(taskMutex); - AddTaskSucFlag = 0; - Operator newOper; - newOper.changeTaskID = 0; - newOper.changeTaskOperator = ADDTASK; - newOper.videoFileName = tparam.video_filename; - newOper.resultFolderLittleName = tparam.result_folder_little; - newOper.result_folder_face = tparam.result_folder_face; - newOper.resultFolderName = tparam.result_folder; - newOper.on_image_display = tparam.on_image_display; - newOper.jpeg_quality = tparam.jpeg_quality; //debug by zsh - newOper.taskObjCallbackFunc = tparam.obj_snapshot_callback_func; - newOper.taskRealTimeCallbackFunc = tparam.rt_view_callback_func; - memcpy(newOper.minBoxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); - TaskOperatorQ.push_back(newOper); - taskCondVar.wait_for(l, std::chrono::seconds(20)); - // printf("finish first task in operator queue\n"); - } - - int addRes = -1; - int newTaskID = TaskID++; - - if (AddTaskSucFlag == 1) - { - addRes = newTaskID; - } - else if (AddTaskSucFlag == -1) - { - addRes = -1; - TaskID--; - } - else if (AddTaskSucFlag == 0) - { - Operator newOper = TaskOperatorQ.back(); - if (strcmp(newOper.videoFileName, tparam.video_filename) == 0) - { - TaskOperatorQ.pop_back(); - } - cout << "Failed Add New Task! Algorithm Process Error! " << endl; - } - - return addRes; -} - -int CMutliSourceVideoProcess::get_task_progress(int taskid, double &progress) -{ - int ret = 0; - for (auto &item : tasks) - { - if (item.taskID == taskid) - { - progress = (double)item.taskFrameCount / (double)item.taskTotalFrameCount; - return 0; - } - } - return -1; - -} - -void CMutliSourceVideoProcess::AddOperator(int taskID, int taskOper) -{ - if (taskOper > 0 && taskOper < 4) - { - Operator newOper = {}; - newOper.changeTaskID = taskID; - newOper.changeTaskOperator = TaskOperator(taskOper); - newOper.videoFileName = NULL; - //TaskOperatorQ.push(newOper); - TaskOperatorQ.push_back(newOper); - } -} - -void CMutliSourceVideoProcess::OperatorTask() -{ - while (!TaskOperatorQ.empty()) - { - Operator newOperator = TaskOperatorQ.front(); - TaskOperatorQ.pop_front(); - - switch (newOperator.changeTaskOperator) - { - case ADDTASK: - //AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); - AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.jpeg_quality, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); //debug by zsh - break; - case PAUSETASK: - PauseTask(newOperator.changeTaskID); - break; - case RESTARTTASK: - RestartTask(newOperator.changeTaskID); - break; - case FINISHTASK: - FinishTask(newOperator.changeTaskID); - break; - default: - break; - } - - } -} - - -int CMutliSourceVideoProcess::SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value) -{ - if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT) - { - if (m_face_det_config == SY_CONFIG_OPEN) - { - m_snaphot_helper.save_face_snapshot(obj_key); - } - - if (m_hp_analysis_config == SY_CONFIG_OPEN || m_hf_recg_config == SY_CONFIG_OPEN) - { - m_snaphot_helper.save_snapshot(obj_key); - m_snaphot_helper.hp_analysis(obj_key); - } - else - { - m_snaphot_helper.save_without_analysis(obj_key); - } - } - else if ((1 == obj_value.index.index || 2 == obj_value.index.index) && obj_value.snapShotLittle.width == HCP_WIDTH && obj_value.snapShotLittle.height == HCP_HEIGHT) - { - if (m_hcp_analysis_config == SY_CONFIG_OPEN || m_hcf_recg_config == SY_CONFIG_OPEN) - { - m_snaphot_helper.save_snapshot(obj_key); - m_snaphot_helper.hcp_analysis(obj_key); - } - else - { - m_snaphot_helper.save_without_analysis(obj_key); - } - } - else if ((8 == obj_value.index.index || (obj_value.index.index >= 4 && obj_value.index.index <= 6)) && obj_value.snapShotLittle.width == VEHICLE_WIDTH && obj_value.snapShotLittle.height == VEHICLE_HEIGHT) - { - //VEHICLEAnalysis(obj_key, obj_value); - if (m_vehicle_analysis_config == SY_CONFIG_OPEN || m_vcf_recg_config == SY_CONFIG_OPEN) - { - m_snaphot_helper.save_snapshot(obj_key); - m_snaphot_helper.vehicle_analysis(obj_key); - } - else - { - m_snaphot_helper.save_without_analysis(obj_key); - } - - } - else - { - m_snaphot_helper.save_without_analysis(obj_key); - } - - return 0; -} - - -//#define LOG_INFO -void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId) -{ - if (objCount == 0) - { - video_object_info newObjInfo; - newObjInfo.task_id = taskId; - newObjInfo.task_frame_count = taskFrameCount; - newObjInfo.object_id = -1; - newObjInfo.left = 0; - newObjInfo.right = 0; - newObjInfo.top = 0; - newObjInfo.bottom = 0; - newObjInfo.index = 0; - newObjInfo.confidence = 0; - - if (taskObjInfoCallbackFunc != nullptr) - taskObjInfoCallbackFunc(&newObjInfo); - } - else - { - for (int c = 0; c < objCount; c++) - { - OBJ_KEY newObj = { taskId, obj[c].id }; - video_object_info newObjInfo; - newObjInfo.task_id = taskId; - newObjInfo.task_frame_count = taskFrameCount; - newObjInfo.object_id = obj[c].id; - newObjInfo.left = obj[c].left; - newObjInfo.right = obj[c].right; - newObjInfo.top = obj[c].top; - newObjInfo.bottom = obj[c].bottom; - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) - newObjInfo.index = obj[c].index; - else - newObjInfo.index = m_snaphot_helper.snapShotInfo[newObj].index.index; - newObjInfo.confidence = obj[c].confidence; - if (taskObjInfoCallbackFunc != nullptr) - { - taskObjInfoCallbackFunc(&newObjInfo); - } - } - - } -} -DWORD ThreadProcess(LPVOID param) -{ - set k; - int count = 0; - sy_img * batch_img = new sy_img[20]{}; - - DxGPUFrame frame = {}; - - CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)param; - - cudaSetDevice(pThreadParam->mgpuid); - - // CUdevice cuDevice; - // cuDeviceGet(&cuDevice, pThreadParam->mgpuid); - // CUcontext context; - // cuCtxCreate(&context, 0, cuDevice); - // cuCtxPushCurrent(context); - - // cuda_common::setColorSpace2(ITU709, 0); - // cudaMalloc((void**)&pThreadParam->FrameTemp, 3 * 4096 * 4096 * sizeof(unsigned char)); - int total_count = 0; - long long begintime1 =get_cur_time_ms(); - - int process_times = 0; - //std::string osPath = "./vptlog"; - //osPath += std::to_string(pThreadParam->mgpuid); - //osPath += ".txt"; - //std::ofstream os(osPath, std::ofstream::out | std::ofstream::trunc); - //os << unitbuf; - //try - - long long last_time = get_cur_time_ms(); - - { - while (1) - { - if (pThreadParam->licence_status <= -3) - { - printf("authority failed!\n"); - break; - } - - double time_val, time_val_p = 0; - { - std::lock_guard l(pThreadParam->taskMutex); - pThreadParam->OperatorTask(); - } - pThreadParam->taskCondVar.notify_all(); - - int curTaskSize = pThreadParam->tasks.size(); - - count = 0; - static int ncount = 0; - map> finishTaskDeleteObj; - int curPlayTaskCount = 0; - - //�жϵ�ǰPLAY����Ľ���״̬��������ڽ����쳣��·������������·���� - for (int i = 0; i < curTaskSize; i++) - { - if ((pThreadParam->tasks[i].taskState == PLAY || pThreadParam->tasks[i].taskState == DECODEERROR)) - { - if (!pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) - { - cudaError_t cudaStatus = cudaGetLastError(); - if (cudaStatus != cudaSuccess) { - printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); - } - - cout << "***************** Task " << i << " is Finished *****************" << endl; - pThreadParam->tasks[i].taskState = FINISH; - - pThreadParam->FinishTask(pThreadParam->tasks[i].taskID); - - pThreadParam->tasks[i].taskTcuvid->DxCloseDecoder(); - delete pThreadParam->tasks[i].taskTcuvid; - pThreadParam->tasks[i].taskTcuvid = NULL; - int taskid = pThreadParam->tasks[i].taskID; - - //ѭ���ȴ� ֱ��finished_analysis_ss_info�����и�·Ŀ�궼�Ѿ����ظ��û����ſ��������������� - std::unique_lock lock(pThreadParam->m_snaphot_helper.analysisThreadMutex); - while (std::find_if(pThreadParam->m_snaphot_helper.finished_analysis_ss_info.begin(), pThreadParam->m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair & item) ->bool { - if (item.first.videoID == taskid) - { - return true; - } - else - { - return false; - } - - }) != pThreadParam->m_snaphot_helper.finished_analysis_ss_info.end()) - { - lock.unlock(); - std::this_thread::yield(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - lock.lock(); - } - - //�ص�֪ͨ�û� ��·����������� - if (pThreadParam->taskFinishCallbackFunc != nullptr) - { - std::lock_guard l(pThreadParam->m_snaphot_helper.callback_tx); - pThreadParam->taskFinishCallbackFunc(pThreadParam->tasks[i].taskID); - } - - pThreadParam->TaskinPlay--; - } - } - - if (pThreadParam->tasks[i].taskState == FINISH) - count++; - } - - //�������������FINISH״̬ - if (count >= pThreadParam->tasks.size()) //have no decode video, break - { - { - std::lock_guard l(pThreadParam->taskMutex); - //�ж���������ȴ������Ƿ����µ��������� - if (pThreadParam->HasNewTask()) - { - continue; - } - else - { - //std::this_thread::sleep_for(std::chrono::milliseconds(40)); - //continue; - //printf("802 set ProcessFlag false\n"); - - //Sleep(10); - //continue; - - //printf("0708\n"); - //pThreadParam->ProcessFlag = false; - break; - } - } - } - - //��ǰû��PLAY������ ѭ���ȴ� - curPlayTaskCount = pThreadParam->TaskinPlay; - if (curPlayTaskCount <= 0) { - Sleep(30); - continue; - } - - k.clear(); - pThreadParam->TaskinPlayID.clear(); - - //��ȡ�������� - getdata_flag: - for (int i = 0; i < curTaskSize; i++) - { - if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) - { - if(pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&pThreadParam->tasks[i].task_algorithm_data) == 0) { - k.insert(i); - pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); - } - // if (pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&frame) == 0) - // { - // if (!pThreadParam->tasks[i].task_algorithm_data.frame && frame.width > 0 && frame.height > 0) - // { - // cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->tasks[i].task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(unsigned char)); - // if (cudaStatus != cudaSuccess) { - // fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); - // break; - // } - - // pThreadParam->tasks[i].task_algorithm_data.height = frame.height; - // pThreadParam->tasks[i].task_algorithm_data.width = frame.width; - // pThreadParam->tasks[i].task_algorithm_data.size = frame.size; - - // pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3); - // pThreadParam->tasks[i].taskDataToRT = (float*)malloc(3 * frame.height * frame.width * sizeof(unsigned char)); - // AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1); - // } - - // //copy decode data - // if (pThreadParam->tasks[i].task_algorithm_data.frame) - // { - // int height = frame.height; - // int width = frame.width; - - // Nv12ToColor24( (unsigned char *)frame.frame, width, (unsigned char *)pThreadParam->tasks[i].task_algorithm_data.frame, 3 * width, width, height, 0 ); - - // pThreadParam->tasks[i].task_algorithm_data.timestamp = frame.timestamp; - - // k.insert(i); - // pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); - // } - // else - // { - // std::cout << "NOT ALLOC: pThreadParam->tasks[i].taskDataToBackup.frame" << pThreadParam->tasks[i].task_algorithm_data.frame << std::endl; - // } - - // pThreadParam->tasks[i].taskTcuvid->DxUnlockFrame(); - // } - } - else if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && !pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) - { - pThreadParam->tasks[i].taskState = DECODEERROR; - curPlayTaskCount--; - FinishTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID); - } - } - - if (curPlayTaskCount <= 0) { - Sleep(30); - continue; - } - - //��û�л�ȡ������·���Ľ������� ѭ���ȴ� - if (k.size() < curPlayTaskCount) - { - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - goto getdata_flag; - } - -#ifdef LOG_INFO2 - long long gather_data_time = get_cur_time_ms(); - std::cout << "gather_data time_using: " << gather_data_time - last_time << std::endl; -#endif - - cudaDeviceSynchronize(); - - //------------------------------ ͳһBATCH���� --------------------------------// - ////////////////////////////////////////////////////////////// - //// - //// compose data -> batch - //// - ///////////////////////////////////////////////////////////// - - vector> deleteObjectID; - set::iterator iter = pThreadParam->TaskinPlayID.begin(); - - int cur_batch_size = 0; - cur_batch_size = pThreadParam->section_batch_size; - - if (0) - { - if (pThreadParam->section_batch_size == 20) - cur_batch_size = pThreadParam->section_batch_size; - else - { - if (curPlayTaskCount <= 2 * pThreadParam->section_batch_size) - cur_batch_size = pThreadParam->section_batch_size; - else if (curPlayTaskCount >= 2 * MAX_BATCH) - cur_batch_size = MAX_BATCH; - else - cur_batch_size = curPlayTaskCount / 2 + (curPlayTaskCount % 2); - } - } - - long long start_time_vpt = get_cur_time_ms(); - - vector> unUsedResult; - vector vec_frameIndex; - unUsedResult.resize(pThreadParam->VPTResult.size()); - int cycleTimes = curPlayTaskCount / cur_batch_size + (curPlayTaskCount % cur_batch_size == 0 ? 0 : 1); - for (int c = 0; c < cycleTimes; c++) - { - int batchsize = c == cycleTimes - 1 ? (curPlayTaskCount - cur_batch_size*c) : cur_batch_size; - int startbatch = c*cur_batch_size; - - vec_frameIndex.clear(); - for (int i = 0; i < batchsize; i++) - { - DxGPUFrame task_algorithm_data = pThreadParam->tasks[*iter].task_algorithm_data; - int w = task_algorithm_data.width; - int h = task_algorithm_data.height; - int npitch = task_algorithm_data.size; - - batch_img[i].set_data(w, h, 3, (unsigned char *)task_algorithm_data.frame); - vec_frameIndex.push_back(task_algorithm_data.timestamp); - iter++; - } - - vector> tempDeleteObjectID; - tempDeleteObjectID.resize(batchsize); - int flag = VPT_Process_GPU(pThreadParam->GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, pThreadParam->VPTResult, tempDeleteObjectID, unUsedResult); - process_times++ ; - - for (auto iter : tempDeleteObjectID) - { - deleteObjectID.push_back(iter); - } - vector>().swap(tempDeleteObjectID); - } -#ifdef LOG_INFO2 - std::cout << "VPT_Process_GPU time_using: " << get_cur_time_ms() - start_time_vpt << std::endl; -#endif - - long long result_analysis_time = get_cur_time_ms(); - - iter = pThreadParam->TaskinPlayID.begin(); - for (int i = 0; i < curPlayTaskCount; i++) - { - pThreadParam->tasks[*iter].taskFrameCount = pThreadParam->tasks[*iter].task_algorithm_data.timestamp; - //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 - if (pThreadParam->VPTResult[i].objCount == 0) - { - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskFrameCount, *iter); - } - - //实时查看模块,若存在实时查看,把当前视频画面cp回内存 - bool view = false; - int frameHeight = pThreadParam->tasks[*iter].task_algorithm_data.height; - int frameWidth = pThreadParam->tasks[*iter].task_algorithm_data.width; - - if (*iter == pThreadParam->viewTaskID) - { - cudaMemcpy(pThreadParam->tasks[*iter].frameImage.data, pThreadParam->tasks[*iter].task_algorithm_data.frame, 3 * pThreadParam->tasks[*iter].task_algorithm_data.width * pThreadParam->tasks[*iter].task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); - view = true; - } - - //跟踪帧也需要返回跟踪的结果 - if (pThreadParam->tasks[*iter].taskLastFrameCount > 0) - { - vector OneUnUsedResult = unUsedResult[i]; - if (OneUnUsedResult.size() == 0) - { - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskLastFrameCount + 1, *iter); - } - for (int k = 0; k < OneUnUsedResult.size(); ++k) - { - if (OneUnUsedResult[k].objCount == 0) - { - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskLastFrameCount + k + 1, *iter); - } - else - { - //cout << "OneUnUsedResult.size = " << OneUnUsedResult.size() << " k=" << k << " OneUnUsedResult[k].objCount = " << OneUnUsedResult[k].objCount << endl; - pThreadParam->callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, pThreadParam->tasks[*iter].taskLastFrameCount + k + 1, *iter); - } - } - } - pThreadParam->tasks[*iter].taskLastFrameCount = pThreadParam->tasks[*iter].taskFrameCount; - - unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{};// = new unsigned char*[pThreadParam->VPTResult[i].objCount]; - int snapshot_left[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_right[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_top[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_bottom[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_dst_width[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_dst_height[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - - int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 - vector human_idx; //用于记录快照数组中那些是人脸 - vector human_obj_keys; - - pThreadParam->callTaskObjInfoCallbackFunc(pThreadParam->VPTResult[i].objCount, pThreadParam->VPTResult[i].obj, pThreadParam->tasks[*iter].taskFrameCount, *iter); - for (int c = 0; c < pThreadParam->VPTResult[i].objCount; c++) - { - OBJ_KEY newObj = { (*iter), pThreadParam->VPTResult[i].obj[c].id }; - - int index = 0; - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) - index = pThreadParam->VPTResult[i].obj[c].index; - else - index = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; - - //实时查看模块 绘制目标框到画面上 - if (view) - { - //cout << "---- vew ---- "; - int p1 = pThreadParam->VPTResult[i].obj[c].left - 10 > 0 ? pThreadParam->VPTResult[i].obj[c].left - 10 : 0; - int p2 = pThreadParam->VPTResult[i].obj[c].top - 15 > 0 ? pThreadParam->VPTResult[i].obj[c].top - 15 : 0; - - cv::rectangle(pThreadParam->tasks[*iter].frameImage, Rect(pThreadParam->VPTResult[i].obj[c].left, pThreadParam->VPTResult[i].obj[c].top, - pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left, - pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top), Scalar(158, 52, 254), 3, 1, 0); - #ifdef _MSC_VER - string resss = "" + to_string(index) + " " + ObjTypes[index]; - putTextZH(pThreadParam->tasks[*iter].frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); - #else - string resss = "" + to_string(pThreadParam->VPTResult[i].obj[c].id) + " " + ObjTypesEnglish[pThreadParam->VPTResult[i].obj[c].index]; - cv::putText(pThreadParam->tasks[*iter].frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); - #endif - } - - //逐个目标更新快照 - int boundary = 10; - int boundaryLittle = 4; - - int cur_real_width = (pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left); - int cur_real_height = (pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top); - int cur_real_index = pThreadParam->VPTResult[i].obj[c].index; - - //第一次添加快照 - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) - { - //DxAppendLog(DxLOG_INFO, "30"); - if (LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) - { - //DxAppendLog(DxLOG_INFO, "31"); - //--------------------- 保存快照视频截图 -----------------------------// - - int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left - boundaryLittle)); - int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top - boundaryLittle)); - int right = min({ frameWidth - 1, (int)(pThreadParam->VPTResult[i].obj[c].right + boundaryLittle) }); - int bottom = min({ frameHeight - 1, (int)(pThreadParam->VPTResult[i].obj[c].bottom + boundaryLittle) }); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].frameCount = pThreadParam->tasks[*iter].taskFrameCount; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].isupdate = true; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lost = 0; - - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; - - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; - - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left = left; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top = top; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right = right; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); - - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom - - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = NULL; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.frame = NULL; - - if (pThreadParam->tasks[*iter].folderName != NULL) - { - //DxAppendLog(DxLOG_INFO, "32"); - FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; - pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); - - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.height = frameHeight; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.width = frameWidth; - } - - - //--------------------- 保存快照抠图 -----------------------------/ - int vLeft = 0; - int vTop = 0; - int vRight = 0; - int vBottom = 0; - - vLeft = max(0, pThreadParam->VPTResult[i].obj[c].left - boundary); - vTop = max(0, pThreadParam->VPTResult[i].obj[c].top - boundary); - vRight = min({ frameWidth - 1, pThreadParam->VPTResult[i].obj[c].right + boundary }); - vBottom = min({ frameHeight - 1, pThreadParam->VPTResult[i].obj[c].bottom + boundary }); - //DxAppendLog(DxLOG_INFO, "34"); - if (pThreadParam->tasks[*iter].folderNameLittle != NULL) - { - //DxAppendLog(DxLOG_INFO, "35"); - int cur_width = 0; - int cur_height = 0; - - if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) - { - cur_width = HP_WIDTH; - cur_height = HP_HEIGHT; - - human_idx.emplace_back(copy_obj_count); - human_obj_keys.emplace_back (newObj); - } - else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) - { - cur_width = HCP_WIDTH; - cur_height = HCP_HEIGHT; - } - else if (8 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index <= 6)) - { - cur_width = VEHICLE_WIDTH; - cur_height = VEHICLE_HEIGHT; - } - else //其余类别 - { - cur_width = vRight - vLeft; - cur_height = vBottom - vTop; - } - - if (cur_width != 0 && cur_height != 0) - { - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = cur_height; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = cur_width; - - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; - snapshot_left[copy_obj_count] = vLeft; - snapshot_top[copy_obj_count] = vTop; - snapshot_right[copy_obj_count] = vRight; - snapshot_bottom[copy_obj_count] = vBottom; - - snapshot_dst_width[copy_obj_count] = cur_width; - snapshot_dst_height[copy_obj_count++] = cur_height; - } - } - } - } - else - { - //DxAppendLog(DxLOG_INFO, "36"); - bool updateShotInfo = false; - int oldIndex = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].frameCount = pThreadParam->tasks[*iter].taskFrameCount; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].isupdate = true; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lost = 0; - - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count == 0) - { - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; - } - else - { - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index == pThreadParam->VPTResult[i].obj[c].index) - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; - else - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count--; - } - if (oldIndex != pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) - { - updateShotInfo = true; - } - - int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left - boundaryLittle)); - int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top - boundaryLittle)); - int right = min(frameWidth - 1, (int)(pThreadParam->VPTResult[i].obj[c].right + boundaryLittle)); - int bottom = min(frameHeight - 1, (int)(pThreadParam->VPTResult[i].obj[c].bottom + boundaryLittle)); - - int maxArea = (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left)*(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top); - - if ((LegalArea(maxArea, pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea, left, top, right, bottom) - && LegalPos(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth) - && LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) || updateShotInfo) - { - //DxAppendLog(DxLOG_INFO, "37"); - int boundary_w = (pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left) * 0.1; - int boundary_h = (pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top)* 0.1; - - int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h; - - ExpandMargin((left - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left), - (bottom - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom), - boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom); - - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left = left; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top = top; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right = right; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; - //printf("ori: %d %d %d %d\n", left, top, right - left, bottom - top); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; - if (pThreadParam->tasks[*iter].folderName != NULL) - { - FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; - pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); - } - - - //--------------------- 保存快照抠图 -----------------------------// - int vLeft = 0; - int vTop = 0; - int vRight = 0; - int vBottom = 0; - - vLeft = max(0, pThreadParam->VPTResult[i].obj[c].left - boundary_left); - vTop = max(0, pThreadParam->VPTResult[i].obj[c].top - boundary_top); - vRight = min(frameWidth - 1, pThreadParam->VPTResult[i].obj[c].right + boundary_right); - vBottom = min(frameHeight - 1, pThreadParam->VPTResult[i].obj[c].bottom + boundary_bottom); - if (pThreadParam->tasks[*iter].folderNameLittle != NULL) - { - - if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) - { - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) - { - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT; - } - - human_idx.push_back(copy_obj_count); - human_obj_keys.emplace_back(newObj); - - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; - snapshot_left[copy_obj_count] = vLeft; - snapshot_top[copy_obj_count] = vTop; - snapshot_right[copy_obj_count] = vRight; - snapshot_bottom[copy_obj_count] = vBottom; - //printf("crop: %d %d %d %d\n", vLeft, vTop, vRight - vLeft, vBottom - vTop); - snapshot_dst_width[copy_obj_count] = HP_WIDTH; - snapshot_dst_height[copy_obj_count++] = HP_HEIGHT; - - } - else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) - { - //DxAppendLog(DxLOG_INFO, "42"); - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) - { - //DxAppendLog(DxLOG_INFO, "43"); - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT; - } - - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; - snapshot_left[copy_obj_count] = vLeft; - snapshot_top[copy_obj_count] = vTop; - snapshot_right[copy_obj_count] = vRight; - snapshot_bottom[copy_obj_count] = vBottom; - - snapshot_dst_width[copy_obj_count] = HCP_WIDTH; - snapshot_dst_height[copy_obj_count++] = HCP_HEIGHT; - - } - else if (8 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index <= 6)) - { - //DxAppendLog(DxLOG_INFO, "43.1"); - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT) - { - //DxAppendLog(DxLOG_INFO, "44"); - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT; - } - - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; - snapshot_left[copy_obj_count] = vLeft; - snapshot_top[copy_obj_count] = vTop; - snapshot_right[copy_obj_count] = vRight; - snapshot_bottom[copy_obj_count] = vBottom; - - snapshot_dst_width[copy_obj_count] = VEHICLE_WIDTH; - snapshot_dst_height[copy_obj_count++] = VEHICLE_HEIGHT; - - } - else - { - //DxAppendLog(DxLOG_INFO, "45"); - // modified by zsh 220614---------------------------- - int cur_width = vRight - vLeft; - int cur_height = vBottom - vTop; - if (cur_width != 0 && cur_height != 0) { - //---------------------------------------- - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft; - - //printf("begin partMemCopy: %d %d %d %d %d %d\n", vLeft, vTop, vRight, vBottom, frameWidth, frameHeight); - partMemCopy((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, - (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom); - } - } - - } - } - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); - } - - } - - //若待抠图的快照数不为0 则进行批量抠图 - if (0 != copy_obj_count) - { - cudaSetDevice(pThreadParam->mgpuid); - PartMemResizeBatch((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, - snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1); - - //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选 - if (pThreadParam->m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) - { - //需要做人脸检测 - int human_count = human_idx.size(); - sy_img *human_img = new sy_img[human_count]; - - sy_point* ori_points = new sy_point[human_count]; - for (int idx = 0; idx < human_count; idx++) - { - int ii = human_idx[idx]; - human_img[idx].set_data(snapshot_dst_width[ii], snapshot_dst_height[ii], 3, snapshot_image_data[ii]); - ori_points[idx].x_ = (snapshot_right[ii] - snapshot_left[ii]); - ori_points[idx].y_ = (snapshot_bottom[ii] - snapshot_top[ii]); - } - - fd_result *face_det_result = new fd_result[human_count]; - for (int fd_i = 0; fd_i < human_count; fd_i++) - { - face_det_result[fd_i].info = new fd_info[10]; //内存由外部申请 - } - - if (pThreadParam->m_face_det_module->face_det_module_process(human_img, human_count, face_det_result, ori_points) == SUCCESS) - { - //printf("finish face_det_module_process: %d\n", human_count); - for (int idx = 0; idx < human_count; idx++) - { - OBJ_KEY cur_obj_key = human_obj_keys[idx]; - fd_result &cur_det_res = face_det_result[idx]; - int face_count = cur_det_res.count; - int face_idx = 0; - int ii = human_idx[idx]; - - if (face_count == 0) continue; - - if (face_count > 1) //检测到多余一个人脸 选最佳 - { - sy_point center_human = { human_img[idx].w_/2, human_img [idx].h_/2}; - float min_distance = INT_MAX; - - for (int c = 0; c < face_count; c++) - { - sy_point face_center = { cur_det_res.info[c].face_position.width_/2, cur_det_res.info[c].face_position.height_/2}; - float distance = fabs(center_human.x_ - face_center.x_) + fabs(center_human.y_ - face_center.y_); - - if (distance < min_distance) - { - min_distance = distance; - face_idx = c; - } - } - } - - fd_info& cur_det_info = cur_det_res.info[face_idx]; - if (pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame == nullptr) - { - sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_ ), - (int)(snapshot_top[ii] + cur_det_info.face_position.top_), - (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; - - int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); - int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); - int new_right = min((int)pThreadParam->tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); - int new_bottom = min((int)pThreadParam->tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); - int new_width = new_right - new_left; - int new_height = new_bottom - new_top; - - sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; - - int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; - - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); - if (cudaStatus != cudaSuccess) { - fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); - break; - } - - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; - memcpy((void*)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); - - //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 - fd_info& tmp_info = pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; - - for (int p = 0; p < FACIALFEAPOINTSIZE; p++) - { - tmp_info.facial_fea_point[p].x_ = - tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); - tmp_info.facial_fea_point[p].y_ = - tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); - } - - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = - { (face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_ }; - - - cudacommon::CropImgGpu((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, pThreadParam->tasks[*iter].task_algorithm_data.width, pThreadParam->tasks[*iter].task_algorithm_data.height, - (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); - - //show_gpu_img_func(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace); - } - else - { - sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_), - (int)(snapshot_top[ii] + cur_det_info.face_position.top_), - (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; - - //更新人脸快照条件:① 角度满足条件 ② 面积比之前人脸面积大 - if (validAngle(cur_det_res.info[face_idx].roll, cur_det_res.info[face_idx].yaw, cur_det_res.info[face_idx].pitch, 15.0, 20.0) - && betterArea(face_ori_rect, pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position)) - { - int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); - int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); - int new_right = min((int)pThreadParam->tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); - int new_bottom = min((int)pThreadParam->tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); - int new_width = new_right - new_left; - int new_height = new_bottom - new_top; - - sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; - - //更新快照 - int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; - - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame); - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); - if (cudaStatus != cudaSuccess) { - fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); - break; - } - - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; - memcpy((void*)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); - - //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 - fd_info& tmp_info = pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; - - for (int p = 0; p < FACIALFEAPOINTSIZE; p++) - { - tmp_info.facial_fea_point[p].x_ = - tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); - tmp_info.facial_fea_point[p].y_ = - tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); - } - - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = - {(face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_}; - - cudacommon::CropImgGpu((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, pThreadParam->tasks[*iter].task_algorithm_data.width, pThreadParam->tasks[*iter].task_algorithm_data.height, - (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); - - //show_gpu_image_withfdinfo_(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, cur_det_info); - - //show_gpu_image_withfdinfo_(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info); - } - } - } - } - - if (face_det_result) - { - for (int fd_i = 0; fd_i < human_count; fd_i++) - delete[] face_det_result[fd_i].info; - delete face_det_result; - } - - if (human_img) delete[] human_img; - if (ori_points) delete[] ori_points; - } - } - - //实时查看 绘制目标轨迹 回调函数返回 - if (view) - { - DrawTracker(pThreadParam->VPT_Handle, *iter, &pThreadParam->tasks[*iter].frameImage); - if (pThreadParam->tasks[*iter].taskRealTimeCallbackFunc != nullptr) - pThreadParam->tasks[*iter].taskRealTimeCallbackFunc(pThreadParam->tasks[*iter].frameImage.data, pThreadParam->tasks[*iter].frameImage.rows, pThreadParam->tasks[*iter].frameImage.cols); - } - // pThreadParam->tasks[*iter].taskFrameCount += pThreadParam->skip_frame_; - iter++; - } - -#ifdef LOG_INFO2 - long long result_analysis_time2 = get_cur_time_ms(); - cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; -#endif - - - auto task_iter = pThreadParam->TaskinPlayID.begin(); - - pThreadParam->AttributionAnalysis = false; - - long long second_analysis_time = get_cur_time_ms(); - - for (int i = 0; i < curPlayTaskCount; i++) - { - for (int j = 0; j < deleteObjectID[i].size(); j++) - { - OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; - - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) - continue; - - auto iter = pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj); - iter->second.finishTracker = true; - - pThreadParam->SaveResultInFile(iter->first, iter->second); - } - - task_iter++; - } - - for (int i = 0; i < deleteObjectID.size(); i++) - vector().swap(deleteObjectID[i]); - vector>().swap(deleteObjectID); - - // pThreadParam->m_snaphot_helper.object_attri_analysis(); - -#ifdef LOG_INFO2 - long long second_analysis_time2 = get_cur_time_ms(); - cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl; -#endif - - cudaError_t cudaStatus = cudaGetLastError(); - if (cudaStatus != cudaSuccess) { - printf("object_attri_analysis last error: %s\n", cudaGetErrorString(cudaStatus)); - } - - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - - ++total_count; - ++ncount; - -#ifdef LOG_INFO2 - last_time = get_cur_time_ms(); - cout << "process time_using:" << last_time - gather_data_time << endl; - cout << endl; -#endif - } - } - //catch (exception &e) - { - //os << 51 << e.what()<< std::endl; - /* std::cout << e.what() << std::endl; - exit(-1);*/ - } - long long costTime1 = get_cur_time_ms() - begintime1; - std::cout << "==================== Process Thread is Finished: " << std::endl; - printf("total frame cost time = %lld us, process times: %d \n", costTime1, process_times); - - pThreadParam->m_snaphot_helper.snapShotInfo.clear(); - pThreadParam->ProcessFlag = false; - - // printf("1499 set ProcessFlag false\n"); - // if (pThreadParam->FrameTemp) - // { - // cudaFree(pThreadParam->FrameTemp); - // } - - if (batch_img != NULL) - { - delete[] batch_img; - batch_img = NULL; - } - - // cuCtxPopCurrent(nullptr); - // cuCtxDestroy(context); - - return 0; -} - -int CMutliSourceVideoProcess::GetRuningNb() { - int no = 0; - for(int i=0; i < tasks.size(); i++){ - if(tasks[i].taskState == PLAY){ - no ++; - } - } - - return no; -} - -#ifdef AUTHORIZATION -void check_thread(void* handle) -{ - int res = -1; -#ifndef _MSC_VER - char wtime[15]; - memset(wtime, 0, 15); - char * time = wtime; -#endif - - CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)handle; - - while (1) - { - //printf("xxx check status on process...\n"); -#ifdef _MSC_VER - res = sy_licence(productSN); -#else - res = sy_licence(productSN, &time); - //printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status); -#endif - if (res < 0) - { - pThreadParam->licence_status = pThreadParam->licence_status - 1; - } - else - { - if (pThreadParam->licence_status < 0) - { - pThreadParam->licence_status = 0; - } - } - boost::this_thread::sleep(boost::posix_time::seconds(300)); //5min - } -} -#endif \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx new file mode 100644 index 0000000..2b1e6f5 --- /dev/null +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx @@ -0,0 +1,1860 @@ +#include "MutliSourceVideoProcess.h" + +#ifdef _MSC_VER +#include +#include +#include "../putText.h" +#endif +#include +#include +#include +#include + +#include "face_detect.h" +#include "CropImg.h" +//#include +//#include +//#include +//#pragma comment(lib, "DbgHelp.Lib") +//#pragma comment(lib, "ShLwApi.lib") +//********************************************************// +//1.Ϊʲô��ʱ�򷵻ص�index=2��ȴδ�����ﳵ�ķ�������Ϊindex�ں�����Ϊ��2�����Ǵ�ʱ�Ŀ��ղ�������֮ǰ�Ŀ��գ����Կ���δ���£�����ͼ���С����Ϊ112*224 + +#define AUTHORIZATION +//#define DQ_AUTHORIZATION + +#include + +#ifdef DQ_AUTHORIZATION +#include "license_validator.h" +#ifdef _MSC_VER +#define productSN "2AC69C4638EF46c884BD2BF132FF41D9" //��ǧ����-������ȨID +#else +#define productSN "683E9D5E56474da5A4C2D3EA9A00568E" //��ǧ����-������ȨID +#endif +#endif + +#ifdef AUTHORIZATION +#include "authority.h" +#ifdef _MSC_VER +#define productSN "4ACFCBE67EF645AB8F0B4CFCDD1926F1" //WINDOWS�����Ʒϵ�к� +#else +#define productSN "4FD45501D5104F0C8C4BE530FC872F46" //LINUX�����Ʒϵ�к� +//#define productSN "7CF8B4797F9E441686145BED07F662DE" //LINUX�����Ʒϵ�к� +#endif +#endif + +#include "../DxDecoder/ColorSpace.h" + +//#define LOG_INFO //�Ƿ������ٴ�ӡ +// #define SKIP_FRMAE 5 //��֡֡�� +#define EXTIME 500 + +static int TaskID = 0; + +auto show_gpu_syimage_ = [](sy_img& cur_frame) { + + unsigned char* cpu_data = new unsigned char[3 * cur_frame.w_ * cur_frame.h_]; + cudaMemcpy(cpu_data, cur_frame.data_, 3 * cur_frame.w_ * cur_frame.h_ * sizeof(unsigned char), cudaMemcpyDeviceToHost); + cv::Mat img(cur_frame.h_, cur_frame.w_, CV_8UC3, cpu_data); + + cv::imshow("img", img); + cv::waitKey(0); + delete[] cpu_data; +}; + +auto show_gpu_image_ = [](DxGPUFrame& cur_frame) { + + unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; + cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); + cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); + + cv::imshow("img2", img); + cv::waitKey(0); + delete[] cpu_data; +}; + +auto show_gpu_image_withrect_ = [](DxGPUFrame& cur_frame, sy_rect &rect) { + + unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; + cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); + cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); + cv::rectangle(img, cv::Rect(rect.left_, rect.top_, rect.width_, rect.height_), cv::Scalar(25, 25, 250), 2, 8, 0); + cv::imshow("ori", img); + cv::waitKey(0); + delete[] cpu_data; +}; + +auto show_gpu_image_withfdinfo_ = [](DxGPUFrame& cur_frame, fd_info &face_info) { + + unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; + cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); + cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); + + printf("%d %d\n", cur_frame.width , cur_frame.height); + for (int ii = 0; ii < 25; ii++) + { + printf("(%d %d) ", face_info.facial_fea_point[ii].x_, face_info.facial_fea_point[ii].y_); + cv::circle(img, cv::Point(face_info.facial_fea_point[ii].x_, face_info.facial_fea_point[ii].y_), 1, cv::Scalar(0, 255, 0)); + + } + //cv::rectangle(img, cv::Rect(face_info.face_position.left_, face_info.face_position.top_, face_info.face_position.width_, face_info.face_position.height_), cv::Scalar(25, 25, 250), 2, 8, 0); + + cv::Mat big_img; + cv::resize(img, big_img, cv::Size(400, 400)); + + + cv::imshow("ori33", img); + cv::imshow("ori44", big_img); + cv::waitKey(0); + delete[] cpu_data; +}; + +auto show_gpu_image_with2rect_ = [](DxGPUFrame& cur_frame, sy_rect &rect, sy_rect &rect2) { + + unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; + cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); + cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); + cv::rectangle(img, cv::Rect(rect.left_, rect.top_, rect.width_, rect.height_), cv::Scalar(25, 25, 250), 1, 8, 0); + cv::rectangle(img, cv::Rect(rect2.left_, rect2.top_, rect2.width_, rect2.height_), cv::Scalar(25, 250, 25), 1, 8, 0); + cv::imshow("ori2", img); + cv::waitKey(0); + delete[] cpu_data; +}; + +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(); +} + +std::function show_gpu_img_func = show_gpu_image_; + +void check_thread(void* handle); +DWORD ThreadProcess(LPVOID param); + + +//std::ofstream g_os("./cudaMem.txt", std::ofstream::out | std::ofstream::trunc); +CMutliSourceVideoProcess::CMutliSourceVideoProcess() +{ +} + +// dump�ļ� +//static LONG WINAPI CustomExceptionCrashHandler(_In_ EXCEPTION_POINTERS *CONST pException) +//{ +// char dumpPath[MAX_PATH]; +// +// BOOL tempDump = FALSE; +// do { +// +// if (0 == GetTempPath(_countof(dumpPath), dumpPath)) +// break; +// +// // %temp%Ŀ¼���½�dump�ļ��� +// if (!PathAppend(dumpPath, "dump")) +// break; +// CreateDirectory(dumpPath, NULL); +// // dump�ļ�����dump�ļ��ļ��� ���Զ����޸� +// if (!PathAppend(dumpPath, "HSTProcessor")) +// break; +// +// SYSTEMTIME lclTm; +// GetLocalTime(&lclTm); +// char ext[29]; +// // dump�ļ�������ʱ���� +// if (FAILED(StringCchPrintf(ext, _countof(ext), ".%04hu%02hu%02hu%02hu%02hu%02hu.unhdlexc.dmp", lclTm.wYear, lclTm.wMonth, lclTm.wDay, lclTm.wHour, lclTm.wMinute, lclTm.wSecond))) +// break; +// if (FAILED(StringCchCat(dumpPath, _countof(dumpPath), ext))) +// break; +// +// tempDump = TRUE; +// } while (FALSE); +// HANDLE CONST dumpFile = CreateFile(dumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); +// if (INVALID_HANDLE_VALUE == dumpPath) +// { +// return EXCEPTION_EXECUTE_HANDLER; +// } +// +// MINIDUMP_EXCEPTION_INFORMATION dumpInfo; +// dumpInfo.ThreadId = GetCurrentThreadId(); +// dumpInfo.ExceptionPointers = pException; +// dumpInfo.ClientPointers = TRUE; +// +// if (FAILED(MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL))) +// { +// CloseHandle(dumpFile); +// } +// CloseHandle(dumpFile); +// +// return EXCEPTION_EXECUTE_HANDLER; +//} + + +CMutliSourceVideoProcess::~CMutliSourceVideoProcess() +{ + //��־����ʼ�� + //DxUninitializeLog(); +} + +int CMutliSourceVideoProcess::FinishProcessThread() +{ + if (thrd_status == 0) + { + thrd.interrupt(); + thrd.join(); + thrd_status = -1; + } + + ProcessThread.interrupt(); //interrupt thread + ProcessThread.join(); //waiting thread finish + + VPT_Release(VPT_Handle); + m_face_det_module->face_det_module_release(); + + m_snaphot_helper.snapshot_helper_release(); + + return 1; +} + +int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc, VIDEO_FINISH_CALLBACK tFinishCallbackFunc) +{ + // checkGpuMem(); + licence_status = -1; + thrd_status = -1; + //SetUnhandledExceptionFilter(CustomExceptionCrashHandler); + + int ret = SUCCESS; + /*DxLogConfig sCfg = { 0 }; + sCfg.serviceID = vptParam.serviceID; + sCfg.limitSize = vptParam.limitSize; + strcpy(sCfg.name, vptParam.name); + strcpy(sCfg.path, vptParam.path); + DxInitializeLog(&sCfg);*/ + + /*printf("=====================��ȨERROR==================\n"); + printf("=====================��ȨERROR==================\n"); + printf("=====================��ȨERROR==================\n");*/ +#ifdef AUTHORIZATION +#ifdef _WIN32 + if (SUCCESS == (ret = sy_licence(productSN))) +#elif __linux__ + char wtime[15]; + memset(wtime, 0, 15); + char * time = wtime; + if (SUCCESS == (ret = sy_licence(productSN, &time))) +#endif +#else + ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2); + if (ret == SUCCESS) +#endif + { + cuInit(0); + int device_count = 0; + cuDeviceGetCount(&device_count); + + if (vptParam.gpuid >= device_count) + { + printf("\nGPU_ID PARAM WRONG, gpuid: %d device_count: %d\n", vptParam.gpuid, device_count); + return GPUID_PARAM_ERROR; + } + + CUdevice dev = 0; + size_t memSize = 0; + dev = vptParam.gpuid; + + CUresult rlt = CUDA_SUCCESS; + rlt = cuDeviceTotalMem(&memSize, dev); + + gpu_total_memory = (float)memSize / (1024 * 1024); + + if (gpu_total_memory < 9000) //8G�Դ棬С�ڴ淽�� + section_batch_size = 10; + else + section_batch_size = 20; + + if(vptParam.skip_frame > 0){ + // 默认值为5 + skip_frame_ = vptParam.skip_frame; + } + + VPTProcess_PARAM param{}; + //param.c = 3; + param.mode = DEVICE_GPU; + param.gpuid = vptParam.gpuid; + //param.threshold = 0.6; + param.threshold = 0.5; + param.engine = ENGINE_TENSORRT; + param.max_batch = section_batch_size; + param.serialize_file = "./serialize_file/VPT"; + param.auth_license = vptParam.auth_license; + mgpuid = vptParam.gpuid; + VPT_Handle = NULL; + ret = VPT_Init(VPT_Handle, param); + if (0 != ret) + return ret; + + m_face_det_module = nullptr; + if (vptParam.face_det_config == SY_CONFIG_OPEN) + { + m_face_det_module = new face_det_module(); + printf("begin init face det\n"); + m_face_det_module->face_det_module_init(vptParam.gpuid, vptParam.auth_license); + } + + viewTaskID = -1; + TaskinPlay = 0; + TotalTask = 0; + capacity = 20; + VPTResult.resize(capacity); + //dwThreadID = 0; + ProcessFlag = false; + SourceFlag = false; + + mModeSnapshotVideo = "cpu"; + mModeSnapshotLittle = "cpu"; + + taskFinishCallbackFunc = nullptr; + if (tFinishCallbackFunc != nullptr) + taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1); + + taskObjInfoCallbackFunc = nullptr; + if (tObjInfoCallbackFunc != nullptr) + taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1); + + minDistance[0] = minDistance[2] = 35; //left right + minDistance[1] = minDistance[3] = 50; //top bottom + + m_hp_analysis_config = vptParam.hp_analysis_config; + m_hcp_analysis_config = vptParam.hcp_analysis_config; + m_vehicle_analysis_config = vptParam.vehicle_analysis_config; + m_hf_recg_config = vptParam.hf_recg_config; + m_hcf_recg_config = vptParam.hcf_recg_config; + m_vcf_recg_config = vptParam.vcf_recg_config; + m_face_det_config = vptParam.face_det_config; + + m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, vptParam.auth_license, vptParam.wait_framecount, m_hp_analysis_config, \ + m_hcp_analysis_config, m_vehicle_analysis_config, m_vehicle_recg_config, m_vehicle_plate_det_recg_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config); + if (ret == SUCCESS) //�ɹ� + { + licence_status = 0; +#ifdef AUTHORIZATION + thrd = boost::thread(check_thread, this); +#endif + thrd_status = 0; + } + + } + else + { + return AUTHOR_ERROR; + } +/* +#ifdef AUTHORIZATION +#ifdef __linux__ + if (wtime) + { + delete[] wtime; + wtime = NULL; + } +#endif +#endif */ // debug by zsh + return ret; +} + +void CMutliSourceVideoProcess::FinishDecode(const int taskID) +{ + boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(400)); + + for (int i = 0; i < tasks.size(); i++) + { + if (tasks[i].taskID == taskID && tasks[taskID].taskTcuvid != NULL) + { + tasks[taskID].taskState == FINISH; + tasks[taskID].taskTcuvid->DxCloseDecoder(); + delete tasks[taskID].taskTcuvid; + tasks[taskID].taskTcuvid = NULL; + printf("-----------------------finish task: %d-----------------------\n", taskID); + break; + } + } + +} + +void CMutliSourceVideoProcess::FinishTask(const int taskID) +{ + for (int i = 0; i < tasks.size(); i++) + { + if (tasks[i].taskID == taskID) + { + //printf("first begin finish\n"); + if (tasks[i].taskState == PLAY) TaskinPlay--; + tasks[i].taskState = FINISH; + tasks[i].taskFileSource = nullptr; + tasks[i].taskObjCallbackFunc = nullptr; + tasks[i].taskRealTimeCallbackFunc = nullptr; + + + m_snaphot_helper.finish_task_ss_analysis(taskID, m_hp_analysis_config, m_hcp_analysis_config, m_vehicle_analysis_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config); //�Ƿ�����������ʶ��); + + if (tasks[i].folderName) + { + delete tasks[i].folderName; + tasks[i].folderName = nullptr; + } + + + if (tasks[i].folderNameLittle) + { + delete tasks[i].folderNameLittle; + tasks[i].folderNameLittle = nullptr; + } + + + if (tasks[i].taskDataToRT) + { + free(tasks[i].taskDataToRT); + tasks[i].taskDataToRT = nullptr; + } + + tasks[i].frameImage.release(); + + + if (tasks[i].task_algorithm_data.frame) + { + cudaFree(tasks[i].task_algorithm_data.frame); + tasks[i].task_algorithm_data.frame = nullptr; + } + + FinishTaskTracker(VPT_Handle, taskID); + + if (viewTaskID == taskID) viewTaskID = -1; + + + break; + } + } +} + +void CMutliSourceVideoProcess::PauseTask(const int taskID) +{ + for (int i = 0; i < tasks.size(); i++) + { + if (tasks[i].taskID == taskID) + { + if (tasks[i].taskState == PLAY) TaskinPlay--; + tasks[i].taskState = PAUSE; + PauseTaskTracker(VPT_Handle, taskID); + tasks[i].taskTcuvid->PauseDecoder(); + if (viewTaskID == taskID) viewTaskID = -1; + printf("-----------------------pasue task: %d-----------------------\n", taskID); + break; + } + } +} + +void CMutliSourceVideoProcess::RestartTask(const int taskID) +{ + for (int i = 0; i < tasks.size(); i++) + { + if (tasks[i].taskID == taskID) + { + tasks[i].taskState = PLAY; + TaskinPlay++; + RestartTaskTraker(VPT_Handle, taskID); + tasks[i].taskTcuvid->ResumeDecoder(); + printf("-----------------------restart task: %d-----------------------\n", taskID); + break; + } + } +} + +//ʵʱ�鿴�ӿ� �ɿ���һ·��ʵʱ�鿴������·�ķ������OSD��Ȼ�󽫻���ͨ���ص��������ظ��û� +void CMutliSourceVideoProcess::ViewTask(const int taskID) +{ + if (tasks.size() > taskID && tasks[taskID].taskState == PLAY) + { + viewTaskID = taskID; + printf("-----------------------view task: %d-----------------------\n", taskID); + } + else + printf("Only can view playing task!"); +} + +//����ʵʱ�鿴�ӿڣ��ر�ʵʱ����ķ��� +void CMutliSourceVideoProcess::FinishViewTask() +{ + viewTaskID = -1; + printf("-----------------------finish view task-----------------------\n"); +} + + +//bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) +bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, int jpeg_quality, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) //debug by zsh +{ + //checkGpuMem(); + std::lock_guard l(_tx_add_task); + using std::placeholders::_1; + // printf("begin real add task\n"); + if (TaskinPlay >= capacity) + { + //cout << "********************** resize capacity *************************" << endl; + capacity *= 2; + VPTResult.resize(capacity); + } + + string sVideoFileName = videoFileName; + + string target = "file://"; + int pos = sVideoFileName.find(target); + if (pos == 0) { + int n = target.size(); + sVideoFileName = sVideoFileName.erase(pos, n); + } + pos = sVideoFileName.find_first_of('?'); + if (pos != string::npos) { + sVideoFileName = sVideoFileName.substr(0, pos); + } + + Task new_task = {}; + new_task.taskID = TotalTask; + new_task.taskFileSource = videoFileName; + memcpy(new_task.task_min_boxsize, minBoxsize, sizeof(sy_rect)* DETECTTYPE); + + + DxConfig cfg = { 0 }; + cfg.devId = mgpuid; + cfg.decMode = 0; + cfg.colorFmt = 0; + cfg.forceTcp = false; + cfg.type = DX_DECODER_TYPE_SFXLAB; + new_task.taskTcuvid = new DxDecoderWrap(&cfg); + if (NULL == new_task.taskTcuvid) + { + printf("Add New DxDecoder Failed!"); + AddTaskSucFlag = -1; + return false; + } + + if (new_task.taskTcuvid->DxOpenDecoder(new_task.taskFileSource, skip_frame_) != 0) + { + cout << "Add Task Failed! Please check you video file name!" << endl; + delete new_task.taskTcuvid; + new_task.taskTcuvid = NULL; + AddTaskSucFlag = -1; + return false; + } + + int tmp_total_frame = new_task.taskTcuvid->DxGetFrameCount(); + + printf("finish add codec. tmp_total_frame: %d \n", tmp_total_frame); + + new_task.taskState = PLAY; + new_task.task_algorithm_data.frame = NULL; + new_task.taskFrameCount = 0; + new_task.taskLastFrameCount = 0; + new_task.taskDataToRT = NULL; + + new_task.taskObjCallbackFunc = nullptr; + if (objCallbackFunc != nullptr) + new_task.taskObjCallbackFunc = std::bind(objCallbackFunc, this, 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.taskTotalFrameCount = tmp_total_frame; + if (resultFolderLittle == NULL) + { + new_task.folderNameLittle = NULL; + } + else + { + new_task.folderNameLittle = new char[strlen(resultFolderLittle) + 2]{}; + strcpy(new_task.folderNameLittle, resultFolderLittle); + + int length = strlen(new_task.folderNameLittle); + if (new_task.folderNameLittle[length - 1] != '\\' && new_task.folderNameLittle[length - 1] != '/') + { + new_task.folderNameLittle[length] = '/'; + new_task.folderNameLittle[length + 1] = '\0'; + } + + CreateResultFolder(new_task.folderNameLittle, ""); + } + + + if (resultFolder == NULL) + { + new_task.folderName = NULL; + } + else + { + new_task.folderName = new char[strlen(resultFolder) + 2]{}; + strcpy(new_task.folderName, resultFolder); + + int length = strlen(new_task.folderName); + if (new_task.folderName[length - 1] != '\\' && new_task.folderName[length - 1] != '/') + { + new_task.folderName[length] = '/'; + new_task.folderName[length + 1] = '\0'; + } + + CreateResultFolder(new_task.folderName, ""); + } + + if (resultFolderface == NULL) + { + new_task.folderNameFace = NULL; + } + else + { + new_task.folderNameFace = new char[strlen(resultFolderface) + 2]{}; + strcpy(new_task.folderNameFace, resultFolderface); + + int length = strlen(new_task.folderNameFace); + if (new_task.folderNameFace[length - 1] != '\\' && new_task.folderNameFace[length - 1] != '/') + { + new_task.folderNameFace[length] = '/'; + new_task.folderNameFace[length + 1] = '\0'; + } + + CreateResultFolder(new_task.folderNameFace, ""); + } + + // printf("finish create folder\n"); + + //Sleep(10); + //std::cout << "CreateResultFolder" << std::endl; + TASK_INFO new_task_info = {}; + new_task_info.image_folder = new_task.folderName; + new_task_info.snapshot_folder = new_task.folderNameLittle; + new_task_info.snapshot_folder_face = new_task.folderNameFace; + new_task_info.task_total_framecount = new_task.taskTotalFrameCount; + new_task_info._on_image_display = on_image_display; + new_task_info.jpeg_quality_ = jpeg_quality; //debug by zsh + new_task_info.obj_callback = new_task.taskObjCallbackFunc; + m_snaphot_helper.add_task_info(new_task.taskID, new_task_info); + + TotalTask++; + TaskinPlay++; + tasks.push_back(new_task); + + // printf("finish push tasks\n"); + + //return 1; + //std::cout<<__LINE__<<"of"<<__FILE__<<"debug\n"; + if (!ProcessFlag) + { + /*for (int num = 0; num < 5; ++num) + {*/ + //create_thread()��һ���������������Դ���thead���������̣߳�ͬʱ�����ڲ���list + // group.create_thread(boost::bind(&runchild , num)) ; + //saveSnapshotsThreadGroup.create_thread(boost::bind(SnapshotThreadProcess, this, 0)); + //} + ProcessThread = boost::thread(ThreadProcess, this); + //std::cout << "begin algorithm" << std::endl; + ProcessFlag = true; + } + + printf("-----------------------add task: %d-----------------------\n", tasks.size() - 1); + AddTaskSucFlag = 1; + return true; +} + +int CMutliSourceVideoProcess::AddOperator(task_param tparam) +{ + //boost::mutex::scoped_lock lock(process_thread_mutex); + + if (!ProcessFlag) + { + //AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.result_folder_face, tparam.on_image_display, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); + AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.result_folder_face, tparam.on_image_display, tparam.jpeg_quality, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); //debug by zsh + boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(500)); + } + else + { + // printf("add first task in operator queue\n"); + std::unique_lock l(taskMutex); + AddTaskSucFlag = 0; + Operator newOper; + newOper.changeTaskID = 0; + newOper.changeTaskOperator = ADDTASK; + newOper.videoFileName = tparam.video_filename; + newOper.resultFolderLittleName = tparam.result_folder_little; + newOper.result_folder_face = tparam.result_folder_face; + newOper.resultFolderName = tparam.result_folder; + newOper.on_image_display = tparam.on_image_display; + newOper.jpeg_quality = tparam.jpeg_quality; //debug by zsh + newOper.taskObjCallbackFunc = tparam.obj_snapshot_callback_func; + newOper.taskRealTimeCallbackFunc = tparam.rt_view_callback_func; + memcpy(newOper.minBoxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); + TaskOperatorQ.push_back(newOper); + taskCondVar.wait_for(l, std::chrono::seconds(20)); + // printf("finish first task in operator queue\n"); + } + + int addRes = -1; + int newTaskID = TaskID++; + + if (AddTaskSucFlag == 1) + { + addRes = newTaskID; + } + else if (AddTaskSucFlag == -1) + { + addRes = -1; + TaskID--; + } + else if (AddTaskSucFlag == 0) + { + Operator newOper = TaskOperatorQ.back(); + if (strcmp(newOper.videoFileName, tparam.video_filename) == 0) + { + TaskOperatorQ.pop_back(); + } + cout << "Failed Add New Task! Algorithm Process Error! " << endl; + } + + return addRes; +} + +int CMutliSourceVideoProcess::get_task_progress(int taskid, double &progress) +{ + int ret = 0; + for (auto &item : tasks) + { + if (item.taskID == taskid) + { + progress = (double)item.taskFrameCount / (double)item.taskTotalFrameCount; + return 0; + } + } + return -1; + +} + +void CMutliSourceVideoProcess::AddOperator(int taskID, int taskOper) +{ + if (taskOper > 0 && taskOper < 4) + { + Operator newOper = {}; + newOper.changeTaskID = taskID; + newOper.changeTaskOperator = TaskOperator(taskOper); + newOper.videoFileName = NULL; + //TaskOperatorQ.push(newOper); + TaskOperatorQ.push_back(newOper); + } +} + +void CMutliSourceVideoProcess::OperatorTask() +{ + while (!TaskOperatorQ.empty()) + { + Operator newOperator = TaskOperatorQ.front(); + TaskOperatorQ.pop_front(); + + switch (newOperator.changeTaskOperator) + { + case ADDTASK: + //AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); + AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.jpeg_quality, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); //debug by zsh + break; + case PAUSETASK: + PauseTask(newOperator.changeTaskID); + break; + case RESTARTTASK: + RestartTask(newOperator.changeTaskID); + break; + case FINISHTASK: + FinishTask(newOperator.changeTaskID); + break; + default: + break; + } + + } +} + + +int CMutliSourceVideoProcess::SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value) +{ + if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT) + { + if (m_face_det_config == SY_CONFIG_OPEN) + { + m_snaphot_helper.save_face_snapshot(obj_key); + } + + if (m_hp_analysis_config == SY_CONFIG_OPEN || m_hf_recg_config == SY_CONFIG_OPEN) + { + m_snaphot_helper.save_snapshot(obj_key); + m_snaphot_helper.hp_analysis(obj_key); + } + else + { + m_snaphot_helper.save_without_analysis(obj_key); + } + } + else if ((1 == obj_value.index.index || 2 == obj_value.index.index) && obj_value.snapShotLittle.width == HCP_WIDTH && obj_value.snapShotLittle.height == HCP_HEIGHT) + { + if (m_hcp_analysis_config == SY_CONFIG_OPEN || m_hcf_recg_config == SY_CONFIG_OPEN) + { + m_snaphot_helper.save_snapshot(obj_key); + m_snaphot_helper.hcp_analysis(obj_key); + } + else + { + m_snaphot_helper.save_without_analysis(obj_key); + } + } + else if ((8 == obj_value.index.index || (obj_value.index.index >= 4 && obj_value.index.index <= 6)) && obj_value.snapShotLittle.width == VEHICLE_WIDTH && obj_value.snapShotLittle.height == VEHICLE_HEIGHT) + { + //VEHICLEAnalysis(obj_key, obj_value); + if (m_vehicle_analysis_config == SY_CONFIG_OPEN || m_vcf_recg_config == SY_CONFIG_OPEN) + { + m_snaphot_helper.save_snapshot(obj_key); + m_snaphot_helper.vehicle_analysis(obj_key); + } + else + { + m_snaphot_helper.save_without_analysis(obj_key); + } + + } + else + { + m_snaphot_helper.save_without_analysis(obj_key); + } + + return 0; +} + + +//#define LOG_INFO +void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId) +{ + if (objCount == 0) + { + video_object_info newObjInfo; + newObjInfo.task_id = taskId; + newObjInfo.task_frame_count = taskFrameCount; + newObjInfo.object_id = -1; + newObjInfo.left = 0; + newObjInfo.right = 0; + newObjInfo.top = 0; + newObjInfo.bottom = 0; + newObjInfo.index = 0; + newObjInfo.confidence = 0; + + if (taskObjInfoCallbackFunc != nullptr) + taskObjInfoCallbackFunc(&newObjInfo); + } + else + { + for (int c = 0; c < objCount; c++) + { + OBJ_KEY newObj = { taskId, obj[c].id }; + video_object_info newObjInfo; + newObjInfo.task_id = taskId; + newObjInfo.task_frame_count = taskFrameCount; + newObjInfo.object_id = obj[c].id; + newObjInfo.left = obj[c].left; + newObjInfo.right = obj[c].right; + newObjInfo.top = obj[c].top; + newObjInfo.bottom = obj[c].bottom; + if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) + newObjInfo.index = obj[c].index; + else + newObjInfo.index = m_snaphot_helper.snapShotInfo[newObj].index.index; + newObjInfo.confidence = obj[c].confidence; + if (taskObjInfoCallbackFunc != nullptr) + { + taskObjInfoCallbackFunc(&newObjInfo); + } + } + + } +} +DWORD ThreadProcess(LPVOID param) +{ + set k; + int count = 0; + sy_img * batch_img = new sy_img[20]{}; + + DxGPUFrame frame = {}; + + CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)param; + + cudaSetDevice(pThreadParam->mgpuid); + + // CUdevice cuDevice; + // cuDeviceGet(&cuDevice, pThreadParam->mgpuid); + // CUcontext context; + // cuCtxCreate(&context, 0, cuDevice); + // cuCtxPushCurrent(context); + + // cuda_common::setColorSpace2(ITU709, 0); + // cudaMalloc((void**)&pThreadParam->FrameTemp, 3 * 4096 * 4096 * sizeof(unsigned char)); + int total_count = 0; + long long begintime1 =get_cur_time_ms(); + + int process_times = 0; + //std::string osPath = "./vptlog"; + //osPath += std::to_string(pThreadParam->mgpuid); + //osPath += ".txt"; + //std::ofstream os(osPath, std::ofstream::out | std::ofstream::trunc); + //os << unitbuf; + //try + + long long last_time = get_cur_time_ms(); + + { + while (1) + { + if (pThreadParam->licence_status <= -3) + { + printf("authority failed!\n"); + break; + } + + double time_val, time_val_p = 0; + { + std::lock_guard l(pThreadParam->taskMutex); + pThreadParam->OperatorTask(); + } + pThreadParam->taskCondVar.notify_all(); + + int curTaskSize = pThreadParam->tasks.size(); + + count = 0; + static int ncount = 0; + map> finishTaskDeleteObj; + int curPlayTaskCount = 0; + + //�жϵ�ǰPLAY����Ľ���״̬��������ڽ����쳣��·������������·���� + for (int i = 0; i < curTaskSize; i++) + { + if ((pThreadParam->tasks[i].taskState == PLAY || pThreadParam->tasks[i].taskState == DECODEERROR)) + { + if (!pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) + { + cudaError_t cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); + } + + cout << "***************** Task " << i << " is Finished *****************" << endl; + pThreadParam->tasks[i].taskState = FINISH; + + pThreadParam->FinishTask(pThreadParam->tasks[i].taskID); + + pThreadParam->tasks[i].taskTcuvid->DxCloseDecoder(); + delete pThreadParam->tasks[i].taskTcuvid; + pThreadParam->tasks[i].taskTcuvid = NULL; + int taskid = pThreadParam->tasks[i].taskID; + + //ѭ���ȴ� ֱ��finished_analysis_ss_info�����и�·Ŀ�궼�Ѿ����ظ��û����ſ��������������� + std::unique_lock lock(pThreadParam->m_snaphot_helper.analysisThreadMutex); + while (std::find_if(pThreadParam->m_snaphot_helper.finished_analysis_ss_info.begin(), pThreadParam->m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair & item) ->bool { + if (item.first.videoID == taskid) + { + return true; + } + else + { + return false; + } + + }) != pThreadParam->m_snaphot_helper.finished_analysis_ss_info.end()) + { + lock.unlock(); + std::this_thread::yield(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + lock.lock(); + } + + //�ص�֪ͨ�û� ��·����������� + if (pThreadParam->taskFinishCallbackFunc != nullptr) + { + std::lock_guard l(pThreadParam->m_snaphot_helper.callback_tx); + pThreadParam->taskFinishCallbackFunc(pThreadParam->tasks[i].taskID); + } + + pThreadParam->TaskinPlay--; + } + } + + if (pThreadParam->tasks[i].taskState == FINISH) + count++; + } + + //�������������FINISH״̬ + if (count >= pThreadParam->tasks.size()) //have no decode video, break + { + { + std::lock_guard l(pThreadParam->taskMutex); + //�ж���������ȴ������Ƿ����µ��������� + if (pThreadParam->HasNewTask()) + { + continue; + } + else + { + //std::this_thread::sleep_for(std::chrono::milliseconds(40)); + //continue; + //printf("802 set ProcessFlag false\n"); + + //Sleep(10); + //continue; + + //printf("0708\n"); + //pThreadParam->ProcessFlag = false; + break; + } + } + } + + //��ǰû��PLAY������ ѭ���ȴ� + curPlayTaskCount = pThreadParam->TaskinPlay; + if (curPlayTaskCount <= 0) { + Sleep(30); + continue; + } + + k.clear(); + pThreadParam->TaskinPlayID.clear(); + + //��ȡ�������� + getdata_flag: + for (int i = 0; i < curTaskSize; i++) + { + if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) + { + if (pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&frame) == 0) + { + if (!pThreadParam->tasks[i].task_algorithm_data.frame && frame.width > 0 && frame.height > 0) + { + cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->tasks[i].task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(unsigned char)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); + break; + } + + pThreadParam->tasks[i].task_algorithm_data.height = frame.height; + pThreadParam->tasks[i].task_algorithm_data.width = frame.width; + pThreadParam->tasks[i].task_algorithm_data.size = frame.size; + + pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3); + pThreadParam->tasks[i].taskDataToRT = (float*)malloc(3 * frame.height * frame.width * sizeof(unsigned char)); + AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1); + } + + //copy decode data + if (pThreadParam->tasks[i].task_algorithm_data.frame) + { + int height = frame.height; + int width = frame.width; + + Nv12ToColor24( (unsigned char *)frame.frame, width, (unsigned char *)pThreadParam->tasks[i].task_algorithm_data.frame, 3 * width, width, height, 0 ); + + pThreadParam->tasks[i].task_algorithm_data.timestamp = frame.timestamp; + + k.insert(i); + pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); + } + else + { + std::cout << "NOT ALLOC: pThreadParam->tasks[i].taskDataToBackup.frame" << pThreadParam->tasks[i].task_algorithm_data.frame << std::endl; + } + + pThreadParam->tasks[i].taskTcuvid->DxUnlockFrame(); + } + } + else if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && !pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) + { + pThreadParam->tasks[i].taskState = DECODEERROR; + curPlayTaskCount--; + FinishTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID); + } + } + + if (curPlayTaskCount <= 0) { + Sleep(30); + continue; + } + + //��û�л�ȡ������·���Ľ������� ѭ���ȴ� + if (k.size() < curPlayTaskCount) + { + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + goto getdata_flag; + } + +#ifdef LOG_INFO2 + long long gather_data_time = get_cur_time_ms(); + std::cout << "gather_data time_using: " << gather_data_time - last_time << std::endl; +#endif + + cudaDeviceSynchronize(); + + //------------------------------ ͳһBATCH���� --------------------------------// + ////////////////////////////////////////////////////////////// + //// + //// compose data -> batch + //// + ///////////////////////////////////////////////////////////// + + vector> deleteObjectID; + set::iterator iter = pThreadParam->TaskinPlayID.begin(); + + int cur_batch_size = 0; + cur_batch_size = pThreadParam->section_batch_size; + + if (0) + { + if (pThreadParam->section_batch_size == 20) + cur_batch_size = pThreadParam->section_batch_size; + else + { + if (curPlayTaskCount <= 2 * pThreadParam->section_batch_size) + cur_batch_size = pThreadParam->section_batch_size; + else if (curPlayTaskCount >= 2 * MAX_BATCH) + cur_batch_size = MAX_BATCH; + else + cur_batch_size = curPlayTaskCount / 2 + (curPlayTaskCount % 2); + } + } + + long long start_time_vpt = get_cur_time_ms(); + + vector> unUsedResult; + vector vec_frameIndex; + unUsedResult.resize(pThreadParam->VPTResult.size()); + int cycleTimes = curPlayTaskCount / cur_batch_size + (curPlayTaskCount % cur_batch_size == 0 ? 0 : 1); + for (int c = 0; c < cycleTimes; c++) + { + int batchsize = c == cycleTimes - 1 ? (curPlayTaskCount - cur_batch_size*c) : cur_batch_size; + int startbatch = c*cur_batch_size; + + vec_frameIndex.clear(); + for (int i = 0; i < batchsize; i++) + { + DxGPUFrame task_algorithm_data = pThreadParam->tasks[*iter].task_algorithm_data; + int w = task_algorithm_data.width; + int h = task_algorithm_data.height; + int npitch = task_algorithm_data.size; + + batch_img[i].set_data(w, h, 3, (unsigned char *)task_algorithm_data.frame); + vec_frameIndex.push_back(task_algorithm_data.timestamp); + iter++; + } + + vector> tempDeleteObjectID; + tempDeleteObjectID.resize(batchsize); + int flag = VPT_Process_GPU(pThreadParam->GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, pThreadParam->VPTResult, tempDeleteObjectID, unUsedResult); + process_times++ ; + + for (auto iter : tempDeleteObjectID) + { + deleteObjectID.push_back(iter); + } + vector>().swap(tempDeleteObjectID); + } +#ifdef LOG_INFO2 + std::cout << "VPT_Process_GPU time_using: " << get_cur_time_ms() - start_time_vpt << std::endl; +#endif + + long long result_analysis_time = get_cur_time_ms(); + + iter = pThreadParam->TaskinPlayID.begin(); + for (int i = 0; i < curPlayTaskCount; i++) + { + pThreadParam->tasks[*iter].taskFrameCount = pThreadParam->tasks[*iter].task_algorithm_data.timestamp; + //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 + if (pThreadParam->VPTResult[i].objCount == 0) + { + pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskFrameCount, *iter); + } + + //实时查看模块,若存在实时查看,把当前视频画面cp回内存 + bool view = false; + int frameHeight = pThreadParam->tasks[*iter].task_algorithm_data.height; + int frameWidth = pThreadParam->tasks[*iter].task_algorithm_data.width; + + if (*iter == pThreadParam->viewTaskID) + { + cudaMemcpy(pThreadParam->tasks[*iter].frameImage.data, pThreadParam->tasks[*iter].task_algorithm_data.frame, 3 * pThreadParam->tasks[*iter].task_algorithm_data.width * pThreadParam->tasks[*iter].task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); + view = true; + } + + //跟踪帧也需要返回跟踪的结果 + if (pThreadParam->tasks[*iter].taskLastFrameCount > 0) + { + vector OneUnUsedResult = unUsedResult[i]; + if (OneUnUsedResult.size() == 0) + { + pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskLastFrameCount + 1, *iter); + } + for (int k = 0; k < OneUnUsedResult.size(); ++k) + { + if (OneUnUsedResult[k].objCount == 0) + { + pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskLastFrameCount + k + 1, *iter); + } + else + { + //cout << "OneUnUsedResult.size = " << OneUnUsedResult.size() << " k=" << k << " OneUnUsedResult[k].objCount = " << OneUnUsedResult[k].objCount << endl; + pThreadParam->callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, pThreadParam->tasks[*iter].taskLastFrameCount + k + 1, *iter); + } + } + } + pThreadParam->tasks[*iter].taskLastFrameCount = pThreadParam->tasks[*iter].taskFrameCount; + + unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{};// = new unsigned char*[pThreadParam->VPTResult[i].objCount]; + int snapshot_left[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; + int snapshot_right[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; + int snapshot_top[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; + int snapshot_bottom[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; + int snapshot_dst_width[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; + int snapshot_dst_height[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; + + int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 + vector human_idx; //用于记录快照数组中那些是人脸 + vector human_obj_keys; + + pThreadParam->callTaskObjInfoCallbackFunc(pThreadParam->VPTResult[i].objCount, pThreadParam->VPTResult[i].obj, pThreadParam->tasks[*iter].taskFrameCount, *iter); + for (int c = 0; c < pThreadParam->VPTResult[i].objCount; c++) + { + OBJ_KEY newObj = { (*iter), pThreadParam->VPTResult[i].obj[c].id }; + + int index = 0; + if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) + index = pThreadParam->VPTResult[i].obj[c].index; + else + index = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; + + //实时查看模块 绘制目标框到画面上 + if (view) + { + //cout << "---- vew ---- "; + int p1 = pThreadParam->VPTResult[i].obj[c].left - 10 > 0 ? pThreadParam->VPTResult[i].obj[c].left - 10 : 0; + int p2 = pThreadParam->VPTResult[i].obj[c].top - 15 > 0 ? pThreadParam->VPTResult[i].obj[c].top - 15 : 0; + + cv::rectangle(pThreadParam->tasks[*iter].frameImage, Rect(pThreadParam->VPTResult[i].obj[c].left, pThreadParam->VPTResult[i].obj[c].top, + pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left, + pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top), Scalar(158, 52, 254), 3, 1, 0); + #ifdef _MSC_VER + string resss = "" + to_string(index) + " " + ObjTypes[index]; + putTextZH(pThreadParam->tasks[*iter].frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); + #else + string resss = "" + to_string(pThreadParam->VPTResult[i].obj[c].id) + " " + ObjTypesEnglish[pThreadParam->VPTResult[i].obj[c].index]; + cv::putText(pThreadParam->tasks[*iter].frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); + #endif + } + + //逐个目标更新快照 + int boundary = 10; + int boundaryLittle = 4; + + int cur_real_width = (pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left); + int cur_real_height = (pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top); + int cur_real_index = pThreadParam->VPTResult[i].obj[c].index; + + //第一次添加快照 + if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) + { + //DxAppendLog(DxLOG_INFO, "30"); + if (LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) + { + //DxAppendLog(DxLOG_INFO, "31"); + //--------------------- 保存快照视频截图 -----------------------------// + + int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left - boundaryLittle)); + int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top - boundaryLittle)); + int right = min({ frameWidth - 1, (int)(pThreadParam->VPTResult[i].obj[c].right + boundaryLittle) }); + int bottom = min({ frameHeight - 1, (int)(pThreadParam->VPTResult[i].obj[c].bottom + boundaryLittle) }); + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].frameCount = pThreadParam->tasks[*iter].taskFrameCount; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].isupdate = true; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lost = 0; + + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; + + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; + + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left = left; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top = top; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right = right; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); + + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom + + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = NULL; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.frame = NULL; + + if (pThreadParam->tasks[*iter].folderName != NULL) + { + //DxAppendLog(DxLOG_INFO, "32"); + FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; + pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); + + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.height = frameHeight; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.width = frameWidth; + } + + + //--------------------- 保存快照抠图 -----------------------------/ + int vLeft = 0; + int vTop = 0; + int vRight = 0; + int vBottom = 0; + + vLeft = max(0, pThreadParam->VPTResult[i].obj[c].left - boundary); + vTop = max(0, pThreadParam->VPTResult[i].obj[c].top - boundary); + vRight = min({ frameWidth - 1, pThreadParam->VPTResult[i].obj[c].right + boundary }); + vBottom = min({ frameHeight - 1, pThreadParam->VPTResult[i].obj[c].bottom + boundary }); + //DxAppendLog(DxLOG_INFO, "34"); + if (pThreadParam->tasks[*iter].folderNameLittle != NULL) + { + //DxAppendLog(DxLOG_INFO, "35"); + int cur_width = 0; + int cur_height = 0; + + if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + { + cur_width = HP_WIDTH; + cur_height = HP_HEIGHT; + + human_idx.emplace_back(copy_obj_count); + human_obj_keys.emplace_back (newObj); + } + else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + { + cur_width = HCP_WIDTH; + cur_height = HCP_HEIGHT; + } + else if (8 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index <= 6)) + { + cur_width = VEHICLE_WIDTH; + cur_height = VEHICLE_HEIGHT; + } + else //其余类别 + { + cur_width = vRight - vLeft; + cur_height = vBottom - vTop; + } + + if (cur_width != 0 && cur_height != 0) + { + cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char)); + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = cur_height; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = cur_width; + + snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; + snapshot_left[copy_obj_count] = vLeft; + snapshot_top[copy_obj_count] = vTop; + snapshot_right[copy_obj_count] = vRight; + snapshot_bottom[copy_obj_count] = vBottom; + + snapshot_dst_width[copy_obj_count] = cur_width; + snapshot_dst_height[copy_obj_count++] = cur_height; + } + } + } + } + else + { + //DxAppendLog(DxLOG_INFO, "36"); + bool updateShotInfo = false; + int oldIndex = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].frameCount = pThreadParam->tasks[*iter].taskFrameCount; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].isupdate = true; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lost = 0; + + if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count == 0) + { + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; + } + else + { + if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index == pThreadParam->VPTResult[i].obj[c].index) + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; + else + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count--; + } + if (oldIndex != pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + { + updateShotInfo = true; + } + + int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left - boundaryLittle)); + int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top - boundaryLittle)); + int right = min(frameWidth - 1, (int)(pThreadParam->VPTResult[i].obj[c].right + boundaryLittle)); + int bottom = min(frameHeight - 1, (int)(pThreadParam->VPTResult[i].obj[c].bottom + boundaryLittle)); + + int maxArea = (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left)*(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top); + + if ((LegalArea(maxArea, pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea, left, top, right, bottom) + && LegalPos(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth) + && LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) || updateShotInfo) + { + //DxAppendLog(DxLOG_INFO, "37"); + int boundary_w = (pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left) * 0.1; + int boundary_h = (pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top)* 0.1; + + int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h; + + ExpandMargin((left - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left), + (bottom - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom), + boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom); + + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left = left; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top = top; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right = right; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; + //printf("ori: %d %d %d %d\n", left, top, right - left, bottom - top); + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; + if (pThreadParam->tasks[*iter].folderName != NULL) + { + FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; + pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); + } + + + //--------------------- 保存快照抠图 -----------------------------// + int vLeft = 0; + int vTop = 0; + int vRight = 0; + int vBottom = 0; + + vLeft = max(0, pThreadParam->VPTResult[i].obj[c].left - boundary_left); + vTop = max(0, pThreadParam->VPTResult[i].obj[c].top - boundary_top); + vRight = min(frameWidth - 1, pThreadParam->VPTResult[i].obj[c].right + boundary_right); + vBottom = min(frameHeight - 1, pThreadParam->VPTResult[i].obj[c].bottom + boundary_bottom); + if (pThreadParam->tasks[*iter].folderNameLittle != NULL) + { + + if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + { + if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) + { + cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char)); + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT; + } + + human_idx.push_back(copy_obj_count); + human_obj_keys.emplace_back(newObj); + + snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; + snapshot_left[copy_obj_count] = vLeft; + snapshot_top[copy_obj_count] = vTop; + snapshot_right[copy_obj_count] = vRight; + snapshot_bottom[copy_obj_count] = vBottom; + //printf("crop: %d %d %d %d\n", vLeft, vTop, vRight - vLeft, vBottom - vTop); + snapshot_dst_width[copy_obj_count] = HP_WIDTH; + snapshot_dst_height[copy_obj_count++] = HP_HEIGHT; + + } + else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + { + //DxAppendLog(DxLOG_INFO, "42"); + if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) + { + //DxAppendLog(DxLOG_INFO, "43"); + cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char)); + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT; + } + + snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; + snapshot_left[copy_obj_count] = vLeft; + snapshot_top[copy_obj_count] = vTop; + snapshot_right[copy_obj_count] = vRight; + snapshot_bottom[copy_obj_count] = vBottom; + + snapshot_dst_width[copy_obj_count] = HCP_WIDTH; + snapshot_dst_height[copy_obj_count++] = HCP_HEIGHT; + + } + else if (8 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index <= 6)) + { + //DxAppendLog(DxLOG_INFO, "43.1"); + if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT) + { + //DxAppendLog(DxLOG_INFO, "44"); + cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char)); + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT; + } + + snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; + snapshot_left[copy_obj_count] = vLeft; + snapshot_top[copy_obj_count] = vTop; + snapshot_right[copy_obj_count] = vRight; + snapshot_bottom[copy_obj_count] = vBottom; + + snapshot_dst_width[copy_obj_count] = VEHICLE_WIDTH; + snapshot_dst_height[copy_obj_count++] = VEHICLE_HEIGHT; + + } + else + { + //DxAppendLog(DxLOG_INFO, "45"); + // modified by zsh 220614---------------------------- + int cur_width = vRight - vLeft; + int cur_height = vBottom - vTop; + if (cur_width != 0 && cur_height != 0) { + //---------------------------------------- + cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char)); + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop; + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft; + + //printf("begin partMemCopy: %d %d %d %d %d %d\n", vLeft, vTop, vRight, vBottom, frameWidth, frameHeight); + partMemCopy((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, + (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom); + } + } + + } + } + pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); + } + + } + + //若待抠图的快照数不为0 则进行批量抠图 + if (0 != copy_obj_count) + { + cudaSetDevice(pThreadParam->mgpuid); + PartMemResizeBatch((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, + snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1); + + //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选 + if (pThreadParam->m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) + { + //需要做人脸检测 + int human_count = human_idx.size(); + sy_img *human_img = new sy_img[human_count]; + + sy_point* ori_points = new sy_point[human_count]; + for (int idx = 0; idx < human_count; idx++) + { + int ii = human_idx[idx]; + human_img[idx].set_data(snapshot_dst_width[ii], snapshot_dst_height[ii], 3, snapshot_image_data[ii]); + ori_points[idx].x_ = (snapshot_right[ii] - snapshot_left[ii]); + ori_points[idx].y_ = (snapshot_bottom[ii] - snapshot_top[ii]); + } + + fd_result *face_det_result = new fd_result[human_count]; + for (int fd_i = 0; fd_i < human_count; fd_i++) + { + face_det_result[fd_i].info = new fd_info[10]; //内存由外部申请 + } + + if (pThreadParam->m_face_det_module->face_det_module_process(human_img, human_count, face_det_result, ori_points) == SUCCESS) + { + //printf("finish face_det_module_process: %d\n", human_count); + for (int idx = 0; idx < human_count; idx++) + { + OBJ_KEY cur_obj_key = human_obj_keys[idx]; + fd_result &cur_det_res = face_det_result[idx]; + int face_count = cur_det_res.count; + int face_idx = 0; + int ii = human_idx[idx]; + + if (face_count == 0) continue; + + if (face_count > 1) //检测到多余一个人脸 选最佳 + { + sy_point center_human = { human_img[idx].w_/2, human_img [idx].h_/2}; + float min_distance = INT_MAX; + + for (int c = 0; c < face_count; c++) + { + sy_point face_center = { cur_det_res.info[c].face_position.width_/2, cur_det_res.info[c].face_position.height_/2}; + float distance = fabs(center_human.x_ - face_center.x_) + fabs(center_human.y_ - face_center.y_); + + if (distance < min_distance) + { + min_distance = distance; + face_idx = c; + } + } + } + + fd_info& cur_det_info = cur_det_res.info[face_idx]; + if (pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame == nullptr) + { + sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_ ), + (int)(snapshot_top[ii] + cur_det_info.face_position.top_), + (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; + + int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); + int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); + int new_right = min((int)pThreadParam->tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); + int new_bottom = min((int)pThreadParam->tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); + int new_width = new_right - new_left; + int new_height = new_bottom - new_top; + + sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; + + int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; + + cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); + break; + } + + pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; + pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; + memcpy((void*)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); + + //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 + fd_info& tmp_info = pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; + + for (int p = 0; p < FACIALFEAPOINTSIZE; p++) + { + tmp_info.facial_fea_point[p].x_ = + tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); + tmp_info.facial_fea_point[p].y_ = + tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); + } + + pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = + { (face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_ }; + + + cudacommon::CropImgGpu((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, pThreadParam->tasks[*iter].task_algorithm_data.width, pThreadParam->tasks[*iter].task_algorithm_data.height, + (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); + + //show_gpu_img_func(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace); + } + else + { + sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_), + (int)(snapshot_top[ii] + cur_det_info.face_position.top_), + (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; + + //更新人脸快照条件:① 角度满足条件 ② 面积比之前人脸面积大 + if (validAngle(cur_det_res.info[face_idx].roll, cur_det_res.info[face_idx].yaw, cur_det_res.info[face_idx].pitch, 15.0, 20.0) + && betterArea(face_ori_rect, pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position)) + { + int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); + int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); + int new_right = min((int)pThreadParam->tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); + int new_bottom = min((int)pThreadParam->tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); + int new_width = new_right - new_left; + int new_height = new_bottom - new_top; + + sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; + + //更新快照 + int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; + + cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame); + cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); + break; + } + + pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; + pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; + memcpy((void*)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); + + //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 + fd_info& tmp_info = pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; + + for (int p = 0; p < FACIALFEAPOINTSIZE; p++) + { + tmp_info.facial_fea_point[p].x_ = + tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); + tmp_info.facial_fea_point[p].y_ = + tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); + } + + pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = + {(face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_}; + + cudacommon::CropImgGpu((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, pThreadParam->tasks[*iter].task_algorithm_data.width, pThreadParam->tasks[*iter].task_algorithm_data.height, + (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); + + //show_gpu_image_withfdinfo_(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, cur_det_info); + + //show_gpu_image_withfdinfo_(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info); + } + } + } + } + + if (face_det_result) + { + for (int fd_i = 0; fd_i < human_count; fd_i++) + delete[] face_det_result[fd_i].info; + delete face_det_result; + } + + if (human_img) delete[] human_img; + if (ori_points) delete[] ori_points; + } + } + + //实时查看 绘制目标轨迹 回调函数返回 + if (view) + { + DrawTracker(pThreadParam->VPT_Handle, *iter, &pThreadParam->tasks[*iter].frameImage); + if (pThreadParam->tasks[*iter].taskRealTimeCallbackFunc != nullptr) + pThreadParam->tasks[*iter].taskRealTimeCallbackFunc(pThreadParam->tasks[*iter].frameImage.data, pThreadParam->tasks[*iter].frameImage.rows, pThreadParam->tasks[*iter].frameImage.cols); + } + // pThreadParam->tasks[*iter].taskFrameCount += pThreadParam->skip_frame_; + iter++; + } + +#ifdef LOG_INFO2 + long long result_analysis_time2 = get_cur_time_ms(); + cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; +#endif + + + auto task_iter = pThreadParam->TaskinPlayID.begin(); + + pThreadParam->AttributionAnalysis = false; + + long long second_analysis_time = get_cur_time_ms(); + + for (int i = 0; i < curPlayTaskCount; i++) + { + for (int j = 0; j < deleteObjectID[i].size(); j++) + { + OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; + + if (pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) + continue; + + auto iter = pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj); + iter->second.finishTracker = true; + + pThreadParam->SaveResultInFile(iter->first, iter->second); + } + + task_iter++; + } + + for (int i = 0; i < deleteObjectID.size(); i++) + vector().swap(deleteObjectID[i]); + vector>().swap(deleteObjectID); + + // pThreadParam->m_snaphot_helper.object_attri_analysis(); + +#ifdef LOG_INFO2 + long long second_analysis_time2 = get_cur_time_ms(); + cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl; +#endif + + cudaError_t cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + printf("object_attri_analysis last error: %s\n", cudaGetErrorString(cudaStatus)); + } + + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + + ++total_count; + ++ncount; + +#ifdef LOG_INFO2 + last_time = get_cur_time_ms(); + cout << "process time_using:" << last_time - gather_data_time << endl; + cout << endl; +#endif + } + } + //catch (exception &e) + { + //os << 51 << e.what()<< std::endl; + /* std::cout << e.what() << std::endl; + exit(-1);*/ + } + long long costTime1 = get_cur_time_ms() - begintime1; + std::cout << "==================== Process Thread is Finished: " << std::endl; + printf("total frame cost time = %lld us, process times: %d \n", costTime1, process_times); + + pThreadParam->m_snaphot_helper.snapShotInfo.clear(); + pThreadParam->ProcessFlag = false; + + // printf("1499 set ProcessFlag false\n"); + // if (pThreadParam->FrameTemp) + // { + // cudaFree(pThreadParam->FrameTemp); + // } + + if (batch_img != NULL) + { + delete[] batch_img; + batch_img = NULL; + } + + // cuCtxPopCurrent(nullptr); + // cuCtxDestroy(context); + + return 0; +} + +int CMutliSourceVideoProcess::GetRuningNb() { + int no = 0; + for(int i=0; i < tasks.size(); i++){ + if(tasks[i].taskState == PLAY){ + no ++; + } + } + + return no; +} + +#ifdef AUTHORIZATION +void check_thread(void* handle) +{ + int res = -1; +#ifndef _MSC_VER + char wtime[15]; + memset(wtime, 0, 15); + char * time = wtime; +#endif + + CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)handle; + + while (1) + { + //printf("xxx check status on process...\n"); +#ifdef _MSC_VER + res = sy_licence(productSN); +#else + res = sy_licence(productSN, &time); + //printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status); +#endif + if (res < 0) + { + pThreadParam->licence_status = pThreadParam->licence_status - 1; + } + else + { + if (pThreadParam->licence_status < 0) + { + pThreadParam->licence_status = 0; + } + } + boost::this_thread::sleep(boost::posix_time::seconds(300)); //5min + } +} +#endif \ No newline at end of file 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 38a9049..4c8dd4d 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 @@ -5,7 +5,7 @@ #include #include -#include "../DxDecoder/DxDecoderWrap.h" +#include "../FFNvDecoder/DxDecoderWrap.h" #include "nvml.h" #include "time.h" #include "opencv2/opencv.hpp" @@ -15,7 +15,7 @@ #include #include #include "common.h" -#include "../DxDecoder/ImageSaveGPU.h" +#include "../FFNvDecoder/ImageSaveGPU.h" #include "mvpt_process_assist.h" #include @@ -173,12 +173,13 @@ enum TaskOperator struct Operator{ int changeTaskID; - const char* videoFileName; - const char* resultFolderLittleName; - const char* resultFolderName; - const char* result_folder_face; + char videoFileName[256]; + char resultFolderLittleName[256]; + char resultFolderName[256]; + char result_folder_face[256]; bool on_image_display; - int jpeg_quality; //ͼƬ���������IJ���0-100 --debug by zsh + int jpeg_quality; + int decMode; TaskOperator changeTaskOperator; VIDEO_OBJECT_SNAPSHOT_CALLBACK taskObjCallbackFunc; @@ -220,8 +221,7 @@ public: void AddOperator(int taskID, int taskOper); int AddOperator(task_param tparam); void callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId); - //bool AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc = NULL, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc = NULL); - bool AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, const char* resultFolderface, bool on_image_display, int jpeg_quality, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc = NULL, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc = NULL); //debug by zsh + bool AddTask(task_param tparam); void PauseTask(const int taskID); void RestartTask(const int taskID); void FinishTask(const int taskID); 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 2d9f632..65cd06d 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 @@ -224,18 +224,19 @@ typedef void(*VIDEO_FINISH_CALLBACK)(void * handle, const int task_id); #define __TASK_PARAM__ typedef struct task_param { - const char* video_filename; - const char* result_folder_little; - const char* result_folder; - const char* result_folder_face; + char video_filename[256]; + char result_folder_little[256]; + char result_folder[256]; + char result_folder_face[256]; bool on_image_display; //是否绘制结果框到保存大图 int jpeg_quality; //图片保存质量的参数0-100 --debug by zsh + int decMode; // 解码模式: 0 全解码; 1 关键帧解码 sy_rect minBoxsize[DETECTTYPE]; //自定义的minBoxsize大小 VIDEO_OBJECT_SNAPSHOT_CALLBACK obj_snapshot_callback_func; VIDEO_REALTIME_CALLBACK rt_view_callback_func; //task_param() : video_filename(0), result_folder_little(0), result_folder(0), result_folder_face(0) {} - task_param() : video_filename(0), result_folder_little(0), result_folder(0), result_folder_face(0), jpeg_quality(30) {} //debug by zsh + task_param() : jpeg_quality(30) {} //debug by zsh }task_param; #endif diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h index 194afb7..c06cdbb 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/SnapShotFrameCache.h @@ -1,5 +1,5 @@ #pragma once -#include "../DxDecoder/DxDecoderWrap.h" +#include "../FFNvDecoder/DxDecoderWrap.h" #include #define SHOT_CACHE_SIZE #define VEHICLE_WIDTH 320 diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h index 9893359..a585ccc 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h @@ -1,5 +1,5 @@ #include -#include "../../DxDecoder/DxDecoderWrap.h" +#include "../../FFNvDecoder/DxDecoderWrap.h" #include "common.h" #include #include 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 787fa58..beefbc1 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 @@ -667,9 +667,45 @@ void videoFinishCallback(void * handle, const int taskID) // } } - +//操作句柄 +void *handle; static int total_index = 0; +void create_task(const char * videoFileName, int total_index) { + //指定检测目标视频抽帧图片(保存时显存占用很大) + char resultFolder[256]; + sprintf(resultFolder, "snapshots/res_0308/%d", total_index); + //指定检测目标快照抠图保存路径 + char resultFolderLittle[256]; + sprintf(resultFolderLittle, "snapshots/resLittle_0308/%d", total_index); + + char resultFolderLittleface[256]; + sprintf(resultFolderLittleface, "snapshots/resLittle_face/%d", total_index); + + task_param tparam; + strcpy(tparam.result_folder, resultFolder); + strcpy(tparam.result_folder_little, resultFolderLittle); + strcpy(tparam.result_folder_face, resultFolderLittleface); + strcpy(tparam.video_filename, videoFileName); + tparam.on_image_display = false; + tparam.jpeg_quality = 30; //debug by zsh + tparam.decMode = 1; // 关键帧解码 + + //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; + + for (int tmp = 0; tmp < 10; tmp ++) { + string tmp_path = "results/" + vpt_types[tmp]; + CreateResultFolder((char*)tmp_path.c_str(), ""); + } + + int newTaskID = add_task(handle, tparam); + cout << "==============================开始任务ID: " << newTaskID << " ============================" << endl; + cur_task_status_.insert(make_pair(newTaskID, FALSE)); +} + int main(int argc, char* argv[]) { if (argc<4) @@ -680,26 +716,24 @@ int main(int argc, char* argv[]) const char * videoFileName = argv[1]; addTaskCount = atoi(argv[2]); int gpuID = atoi(argv[3]); - //操作句柄 - void *handle; //初始化参数设置 mvpt_param vptParam; - vptParam.hp_analysis_config = SY_CONFIG_CLOSE; - vptParam.hcp_analysis_config = SY_CONFIG_CLOSE; - vptParam.vehicle_analysis_config = SY_CONFIG_CLOSE; - 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.hp_analysis_config = SY_CONFIG_OPEN; - // vptParam.hcp_analysis_config = SY_CONFIG_OPEN; + // vptParam.hp_analysis_config = SY_CONFIG_CLOSE; + // vptParam.hcp_analysis_config = SY_CONFIG_CLOSE; + // vptParam.vehicle_analysis_config = SY_CONFIG_CLOSE; + // 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.hp_analysis_config = SY_CONFIG_OPEN; + vptParam.hcp_analysis_config = SY_CONFIG_OPEN; vptParam.vehicle_analysis_config = SY_CONFIG_OPEN; - // 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.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.vrdbpath = argv[4]; //vptParam.vrdbpath = "../../db/mvpt.bin"; @@ -730,46 +764,23 @@ int main(int argc, char* argv[]) continue; } + // create_task("/home/cmhu/data/video/duan1.avi", total_index); + + // usleep(40000); + + // create_task("/home/cmhu/data/video/Street.uvf", total_index); + for (int i = 0; i < addTaskCount; i++) { - //指定检测目标视频抽帧图片(保存时显存占用很大) - char resultFolder[260]; - sprintf(resultFolder, "snapshots/res_0308/%d", total_index); - //指定检测目标快照抠图保存路径 - char resultFolderLittle[260]; - sprintf(resultFolderLittle, "snapshots/resLittle_0308/%d", total_index); - - char resultFolderLittleface[260]; - sprintf(resultFolderLittleface, "snapshots/resLittle_face/%d", total_index); - - task_param tparam; - tparam.result_folder = resultFolder; - tparam.result_folder_little = resultFolderLittle; - tparam.result_folder_face = resultFolderLittleface; - tparam.video_filename = videoFileName; - tparam.on_image_display = false; - tparam.jpeg_quality = 30; //debug by zsh - - //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; - - for (int tmp = 0; tmp < 10; tmp ++) { - string tmp_path = "results/" + vpt_types[tmp]; - CreateResultFolder((char*)tmp_path.c_str(), ""); - } + create_task(videoFileName, total_index); + + total_index++ ; - int newTaskID = add_task(handle, tparam); - cout << "==============================开始任务ID: " << newTaskID << " ============================" << endl; - cur_task_status_.insert(make_pair(newTaskID, FALSE)); #ifdef _MSC_VER Sleep(2000); #else usleep(40000); - #endif - - total_index++ ; + #endif } } while(0) ; @@ -843,20 +854,20 @@ int main(int argc, char* argv[]) itor = cur_task_status_.erase(itor); //指定检测目标视频抽帧图片(保存时显存占用很大) - char resultFolder[260]; + char resultFolder[256]; sprintf(resultFolder, "res/%d", total_index); //指定检测目标快照抠图保存路径 - char resultFolderLittle[260]; + char resultFolderLittle[256]; sprintf(resultFolderLittle, "resLittle/%d", total_index); - char resultFolderLittleface[260]; + char resultFolderLittleface[256]; sprintf(resultFolderLittleface, "resLittle_face/%d", total_index++); task_param tparam; - tparam.result_folder = resultFolder; - tparam.result_folder_little = resultFolderLittle; - tparam.result_folder_face = resultFolderLittleface; - tparam.video_filename = videoFileName; + strcpy(tparam.result_folder, resultFolder); + strcpy(tparam.result_folder_little, resultFolderLittle); + strcpy(tparam.result_folder_face, resultFolderLittleface); + strcpy(tparam.video_filename, videoFileName); memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE); tparam.rt_view_callback_func = videoRTViewCallback; tparam.obj_snapshot_callback_func = videoObjSnapshotCallback; -- libgit2 0.21.4