diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp index b1f9ad1..f14fba6 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp @@ -165,7 +165,7 @@ void ImageSaveCache::insert(const OBJ_KEY &snaphot_id, const FRAME_KEY & frame_i fprintf(stderr, "here cudaMemcpy failed! error: %s\n", cudaGetErrorString(cudaStatus)); } - dx_frame.height = frame.height; //�����ͼû���棬����Ҳû�д�ͼ�����ܱ��������ã���ô���½�һ����ͼ���ݣ������ͼvector + dx_frame.height = frame.height; dx_frame.width = frame.width; dx_frame.size = frame.size; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile deleted file mode 100644 index 1ed6513..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile +++ /dev/null @@ -1,93 +0,0 @@ - -CC = gcc -XX = g++ -AR = ar -NVCC=nvcc - -PROJ_HOME = /mnt/data/cmhu/Project_VideoStructure - -TARGET = $(DES_BIN)/libVPT.so - -NVDECODE_ROOT=../DxDecoder -DEPEND_DIR = $(STATIC_RELEASE_ROOT) -#UTOOLS_ROOT = /home/xzhao_aic/MCaffe2/linux/utools -UTOOLS_ROOT=/home/xzhao_aic/lib_video_structure_190123.old/utools/ -UTOOLS_SRC = $(UTOOLS_SSD_ROOT) - -SDK_ROOT = $(PROJ_HOME)/Linux_3rdparty/video_structure_sdk_20220512 - -INCLUDE =-I $(OPENCV_ROOT)/include \ - -I $(OPENCV_ROOT)/include/opencv \ - -I $(OPENCV_ROOT)/include/opencv2 \ - -I /home/xzhao_aic/local/include \ - -I $(BOOST_ROOT)/include \ - -I /usr/local/cuda/include \ - -I $(UTOOLS_SRC) \ - -I $(NVDECODE_ROOT) \ - -I $(NVDECODE_ROOT)/common/inc \ - -I /usr/include/cairo \ - -I $(SDK_ROOT) \ - -#-I $(VPT_ROOT)/vpt \ - -# -I ./MD5 \ - -#CFLAGS =-g -Wall -O3 $(INCLUDE) # -std=c++11 -CFLAGS = $(CFLAGS_LIB) $(INCLUDE) -std=c++11 -NFLAGS = $(NFLAGS_LIB) $(INCLUDE) -std=c++11 - - -LIBSPATH=-L$(UTOOLS_ROOT) -lutools \ - -L$(NVDECODE_ROOT) -lDxDecoder \ - -L$(HP_ROOT) -lhp \ - -L$(HCP_ROOT) -lhcp \ - -L$(VC_ROOT) -lvcolor \ - -L$(VR_ROOT) -lvr \ - -L$(VP_ROOT) -lvp \ - -L/usr/local/cuda/lib64 -lcuda -lcudart -lnvcuvid -lnppi -lnppc -lcurand -lcublas -lcusolver \ - -L/usr/local/lib -ldl -ldl -lm \ - -l:libjasper.so.1 -l:libIlmImf.so.7 \ - -L$(DES_BIN) \ - -LIBS= -ldl -lpthread -lcairo - -#SRCS:=$(wildcard *.cpp) -#OBJS:=$(patsubst %cpp, %o, $(SRCS)) - -SRCS:=$(wildcard *.cpp) $(wildcard $(VPT_ROOT)/sort/*.cpp) $(wildcard $(VPT_ROOT)/MD5/mID.cpp) -DIRS:=$(notdir $(SRCS)) -OBJS:=$(patsubst %cpp, %o, $(DIRS)) - -CU_SOURCES = $(shell ls *.cu) -CU_OBJS=$(CU_SOURCES:.cu=.o) - -STATICLIBS:=$(wildcard $(UTOOLS_ROOT)/*.a) - -all:$(TARGET) - -$(TARGET):$(addprefix $(BUILD_DIR)/, $(OBJS)) $(addprefix $(BUILD_DIR)/, $(CU_OBJS)) - $(XX) $(CFLAGS) -shared -o $@ $^ $(LIBSPATH) $(LIBS) - chmod 777 $(TARGET) - $(STRIP) $(TARGET) - -$(BUILD_DIR)/%.o:%.cpp | $(BUILD_DIR) - @echo "##############################$@##############################" - $(XX) $(CFLAGS) -c $< -o $@ -$(BUILD_DIR)/%.o:$(VPT_ROOT)/sort/%.cpp | $(BUILD_DIR) - @echo "##############################$@###############################" - $(XX) $(CFLAGS) -c $< -o $@ -$(BUILD_DIR)/%.o:$(VPT_ROOT)/MD5/%.cpp | $(BUILD_DIR) - @echo "##############################$@###############################" - $(XX) $(CFLAGS) -c $< -o $@ -$(BUILD_DIR)/%.o:%.cu | $(BUILD_DIR) - @echo "#######################CU_OBJS:$@###############" - $(NVCC) $(NFLAGS) -o $@ $< - -$(BUILD_DIR): - mkdir $@ - -.PHONY:clean -clean: - $(RM) $(BUILD_DIR)/* - $(RM) $(TARGET) - diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile-bin b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile-bin deleted file mode 100644 index 3d96dbd..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile-bin +++ /dev/null @@ -1,68 +0,0 @@ - -CC = gcc -XX = g++ -AR = ar -NVCC=nvcc - -TARGET = vpt_test - -NVDECODE_ROOT=../NvDecode -UTOOLS_ROOT = $(UTOOLS_SSD_ROOT)/utools -UTOOLS_SRC = $(UTOOLS_SSD_ROOT)/../src -VPT_ROOT = . -INCLUDE =-I $(OPENCV_ROOT)/include \ - -I $(OPENCV_ROOT)/include/opencv \ - -I $(OPENCV_ROOT)/include/opencv2 \ - -I $(BOOST_ROOT)/include \ - -I /usr/local/cuda/include \ - -I $(UTOOLS_SRC) \ - -I $(NVDECODE_ROOT) \ - -I $(NVDECODE_ROOT)/common/inc \ - -I $(VPT_ROOT)/sort \ - -#-I $(VPT_ROOT)/vpt \ - -# -I ./MD5 \ - -#CFLAGS =-g -Wall -O3 $(INCLUDE) # -std=c++11 -CFLAGS = $(CFLAGS_APP) $(INCLUDE) -std=c++11 - -LIBSPATH=-L$(UTOOLS_ROOT) -lustools \ - -L$(NVDECODE_ROOT) -lNvDecode \ - -L/usr/local/cuda/lib64 -lcuda -lcudart -lnvcuvid -lnppi -lnppc -lcurand -lcublas -lcusolver \ - -L/usr/local/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice -lyasm -ldl -ldl -lm \ - -LIBS= -ldl -lpthread - -#SRCS:=$(wildcard *.cpp) -#OBJS:=$(patsubst %cpp, %o, $(SRCS)) - -SRCS:=$(wildcard *.cpp) $(wildcard $(VPT_ROOT)/sort/*.cpp) $(wildcard $(VPT_ROOT)/MD5/mID.cpp) -DIRS:=$(notdir $(SRCS)) -OBJS:=$(patsubst %cpp, %o, $(DIRS)) - - -all:$(TARGET) - -$(TARGET):$(OBJS) - $(XX) $(CFLAGS) -Wl,-rpath=./ -o $@ $^ $(LIBSPATH) $(LIBS) - rm -f *.o - cp $(TARGET) $(DES_BIN) -%.o:%.cpp - @echo "##############################$@##############################" - $(XX) $(CFLAGS) -c $< -%.o:$(VPT_ROOT)/sort/%.cpp - @echo "##############################$@###############################" - $(XX) $(CFLAGS) -c $< -%.o:$(VPT_ROOT)/MD5/%.cpp - @echo "##############################$@###############################" - $(XX) $(CFLAGS) -c $< - - -.PHONY:clean -clean: - $(RM) $(OBJS) - $(RM) $(TARGET) - $(RM) $(DES_BIN)/$(TARGET) - $(RM) *~ - diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile-lib b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile-lib deleted file mode 100644 index 2a99cb6..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile-lib +++ /dev/null @@ -1,93 +0,0 @@ - -CC = gcc -XX = g++ -AR = ar -NVCC=nvcc - -TARGET = libVPT.a - -NVDECODE_ROOT=../NvDecode -DEPEND_DIR = $(STATIC_RELEASE_ROOT) -UTOOLS_ROOT = $(UTOOLS_SSD_ROOT)/utools -UTOOLS_SRC = $(UTOOLS_SSD_ROOT)/../src -VPT_ROOT = . -INCLUDE =-I $(OPENCV_ROOT)/include \ - -I $(OPENCV_ROOT)/include/opencv \ - -I $(OPENCV_ROOT)/include/opencv2 \ - -I $(BOOST_ROOT)/include \ - -I /usr/local/cuda/include \ - -I $(UTOOLS_SRC) \ - -I $(NVDECODE_ROOT) \ - -I $(NVDECODE_ROOT)/common/inc \ - -I $(VPT_ROOT)/sort \ - -#-I $(VPT_ROOT)/vpt \ - -# -I ./MD5 \ - -#CFLAGS =-g -Wall -O3 $(INCLUDE) # -std=c++11 -CFLAGS = $(CFLAGS_LIB) $(INCLUDE) -std=c++11 -NFLAGS = $(NFLAGS_LIB) $(INCLUDE) -std=c++11 - - -LIBSPATH=-L $(UTOOLS_ROOT) \ - -L/usr/local/cuda/lib64 -lcudart -lcublas -lcusolver -lcurand - -LIBS=-lustools -ldl -lpthread - -#SRCS:=$(wildcard *.cpp) -#OBJS:=$(patsubst %cpp, %o, $(SRCS)) - -SRCS:=$(wildcard *.cpp) $(wildcard $(VPT_ROOT)/sort/*.cpp) $(wildcard $(VPT_ROOT)/MD5/mID.cpp) -DIRS:=$(notdir $(SRCS)) -OBJS:=$(patsubst %cpp, %o, $(DIRS)) - -CU_SOURCES = $(shell ls *.cu) -CU_OBJS=$(CU_SOURCES:.cu=.o) - -STATICLIBS:=$(wildcard $(UTOOLS_ROOT)/*.a) - -all:$(TARGET) - -$(TARGET):$(OBJS) $(CU_OBJS) - rm -f $(TARGET) - $(AR) crs $@ $(OBJS) $(CU_OBJS) - ranlib $(TARGET) - rm -f *.o - echo create $(TARGET) > script.mri; - echo addlib $(TARGET) >> script.mri; - @for alib in `echo $(STATICLIBS) | cut -d' ' -f 1-`; \ - do \ - echo addlib $$alib >> script.mri; \ - done - echo save >> script.mri; - echo end >> script.mri; - ar -M < script.mri -# $(foreach alib, $(STATICLIBS), $(AR) x $(alib)) -# ar cru $(TARGET) *.o - ranlib $(TARGET) - rm -f *.o - cp $(TARGET) $(DES_LIB) - chmod 777 $(DES_LIB)/$(TARGET) -%.o:%.cpp - @echo "##############################$@##############################" - $(XX) $(CFLAGS) -c $< -%.o:$(VPT_ROOT)/sort/%.cpp - @echo "##############################$@###############################" - $(XX) $(CFLAGS) -c $< -%.o:$(VPT_ROOT)/MD5/%.cpp - @echo "##############################$@###############################" - $(XX) $(CFLAGS) -c $< -$(CU_OBJS):%.o:%.cu - @echo "#######################CU_OBJS###############" - @echo $@ - $(NVCC) $(NFLAGS) -o $@ $< - - -.PHONY:clean -clean: - $(RM) $(OBJS) - $(RM) $(TARGET) - $(RM) $(DES_LIB)/$(TARGET) - $(RM) *~ - 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 deleted file mode 100644 index 90c6dd7..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx +++ /dev/null @@ -1,1851 +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; - } - - 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.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); - 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 bc97514..8deaa68 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 @@ -13,12 +13,10 @@ #include "VPTProcess.h" #include #include -#include #include "common.h" #include "../FFNvDecoder/ImageSaveGPU.h" #include "mvpt_process_assist.h" -#include #include "snapshot_helper.h" #include "FaceDetModule.h" @@ -235,7 +233,7 @@ public: private: //bool ChangeTask; //HANDLE handle_process; - boost::thread ProcessThread; + std::thread ProcessThread; std::mutex _tx_add_task; @@ -246,7 +244,7 @@ private: //cv::Mat objSnapshot; double gpu_total_memory; - boost::thread thrd; + std::thread thrd; void* authority_handle; public: /*��������Ӧ����public�� �������̺߳����л��õ����µ����� ÿ����дһ��get����̫������*/ @@ -282,14 +280,7 @@ public: /*��������Ӧ����public�� ������ queue snapshotProcessQueue; - //CUcontext cuCtx; - //int PROCESSHEIGHT; - //int PROCESSWIDTH; - //int DATASIZE; - bool beginSaveSnapshot; - boost::thread_group saveSnapshotsThreadGroup; - //boost::mutex process_thread_mutex; std::mutex taskMutex; std::condition_variable taskCondVar; bool AttributionAnalysis; //���ڿ��ƣ�ÿ֡����ֻ����һ���������Է��� @@ -305,6 +296,9 @@ public: /*��������Ӧ����public�� ������ sy_command m_vcf_recg_config; //�Ƿ�����������ʶ�� sy_command m_face_det_config; //�Ƿ���������� snapshot_helper m_snaphot_helper; + + bool m_bExit{false}; + bool m_bProcessExit{false}; }; static CMutliSourceVideoProcess mainProcess; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cppbk b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cppbk deleted file mode 100644 index 5a34ada..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cppbk +++ /dev/null @@ -1,733 +0,0 @@ -#include "VPTProcess.h" - -#ifndef _MSC_VER -#include -#endif - -#include -#include -#include "ObjCls.h" -#include -#include "ErrorInfo.h" -#include "fstream" -#include -//#include "mobileshift0.6_mergeBNALL.h" -//#include "ga_mobile_10_SSD10_416x224_416x224_mobile_shift2_mindim06_iter_46107_mergeBNALL.h" - -//#include "test_mergeBNALLGPU.h" -//#include "ga_mobile_10cls_SSD_512x512_mobile_10clsv1_iter_200000_mergeBNALL.h" - -#include "../model/vptModeTrt/ga_vpt_init_net.h" -#include "../model/vptModeTrt/ga_vpt_predict_net.h" -#include "../model/vptModeTrt/ga_trt_fpn_vpt_calibrator.h" -#include "../model/hidemodel_caffe_1108/ga_vpt_init_net_caffe2.h" -#include "../model/hidemodel_caffe_1108/ga_vpt_predict_net_caffe2.h" -#include "vpt_fpn_plugin_factory.h" -//#include "vpt.h" -#include "MutliSourceVideoProcess.h" -//struct vpt_handle -//{ -// void* det_handle; -// vector taskTrackers; -//}; - -typedef struct objDetector { - - void* det_handle; - float threshold; - VPT_FPNPluginFactory tensorrt_plugin_factory; - - int licence_status = -1;//授权相关参数 - int thrd_status = -1; //授权相关参数 - boost::thread thrd; //授权相关参数 - vector taskTrackers; - objDetector() - { - det_handle = NULL; - threshold = 0.6; - } -}objDetector; - - -//int VPT_Init(void *&handle, VPTProcess_PARAM param) -//{ -// int ret = SUCCESS; -////#ifdef AUTHORIZATION -////#ifdef _WIN32 -//// if (SUCCESS == (ret = sy_licence(productSN))) -////#elif __linux__ -//// char* wtime = new char[15]; -//// memset(wtime, 0, 15); -//// if (SUCCESS == (ret = sy_licence(productSN, &wtime))) -////#endif -////#else -//// ret = sy_time_check(2021, 4); -//// if (ret == SUCCESS) -////#endif -//// { -//// cuInit(0); -//// int device_count = 0; -//// cuDeviceGetCount(&device_count); -//// -//// if (param.gpuid >= device_count) -//// { -//// printf("\nGPU_ID PARAM WRONG!\n"); -//// return GPUID_PARAM_ERROR; -//// } -// -// objDetector * tools = new objDetector; -// -// ctools_init_params vpt_param; -// vpt_param.thres_ = param.threshold; -// vpt_param.log_level_ = 0; -// vpt_param.device_type_ = param.mode; -// vpt_param.device_id_ = param.gpuid; -// vpt_param.engine_type_ = param.engine; -// vpt_param.model_type_ = MODEL_FPN; -// -//#ifdef _MSC_VER -// vpt_param.weight_file_ = NULL; -// vpt_param.net_file_ = NULL; -//#else -// vpt_param.weight_file_ = NULL; -// vpt_param.net_file_ = NULL; -//#endif -// -// -// vpt_param.data_process_str_ = param.preprocess_param; -// vpt_param.need_im_info_ = 1; // true -// -// if (vpt_param.engine_type_ == ENGINE_MCAFFE2) -// { -// //caffe2模型预处理参? -// vpt_param.data_process_str_ = -// "CopyData_CPU2GPU_U8;" -// "TypeConvert_U8_F32;" -// "ResizePad_F32_F32,test_size,720,test_max_size,1280,fpn_coarsest_stride,32," -// "submean_b,103.94,submean_g,116.78,submean_r,123.68," -// "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" -// "NHWC2NCHW_F32" -// ; -// -// vpt_param.weight_array_ = (unsigned char*)ga_vpt_init_net_caffe2; -// vpt_param.weight_array_len_ = ga_vpt_init_net_len_caffe2; -// vpt_param.net_array_ = (unsigned char*)ga_vpt_predict_net_caffe2; -// vpt_param.net_array_len_ = ga_vpt_predict_net_len_caffe2; -// } -// else if (vpt_param.engine_type_ == ENGINE_TENSORRT) -// { -// vpt_param.weight_array_ = (uint8_t*)ga_vpt_init_net; -// vpt_param.weight_array_len_ = ga_vpt_init_net_len; -// vpt_param.net_array_ = (uint8_t*)ga_vpt_predict_net; -// vpt_param.net_array_len_ = ga_vpt_predict_net_len; -// -// vpt_param.trt_serialize_file_ = param.serialize_file;// NULL;// "FPN_VPT_ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -// -// //trt版本预处理参? -// param.preprocess_param = -// "CopyData_CPU2GPU_U8;" -// "TypeConvert_U8_F32;" -// "ResizeMaxPad_F32_F32,test_size,720,test_max_size,1280,max_height,736,max_width,1280," -// "submean_b,103.94,submean_g,116.78,submean_r,123.68," -// "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" -// "NHWC2NCHW_F32" -// ; -// -// memset(vpt_param.tensorrt_param_str_, 0, sizeof(vpt_param.tensorrt_param_str_)); -// -// int batch_size = param.max_batch; -// std::string g_data_mode = "FP32"; -// bool g_is_create_calibrator = false; -// -// sprintf(vpt_param.tensorrt_param_str_, "max_batchsize %d," -// "data_mode %s," -// "is_create_calibrator %d," -// "input_names data im_info," -// "output_names cls_prob bbox_pred_final rois_count_each_img", -// batch_size, g_data_mode.c_str(), g_is_create_calibrator); -// -// vpt_param.tensorrt_calibrator_file_ = NULL;// "trt_fpn_vpt_calibrator"; -// vpt_param.tensorrt_calibrator_array_len_ = ga_trt_fpn_vpt_calibrator_len;// "trt_fpn_vpt_calibrator"; -// vpt_param.tensorrt_calibrator_array_ = (unsigned char*)ga_trt_fpn_vpt_calibrator;// "trt_fpn_vpt_calibrator"; -// -// vpt_param.tensorrt_plugin_factory_ptr_ = &(tools->tensorrt_plugin_factory); -// } -// -// tools->threshold = param.threshold; -// -// int flag = ctools_init(&tools->det_handle, &vpt_param); -// -// if (SUCCESS != flag) -// { -// printf("VPT_Init(ERROR): Init failed\n"); -// handle = NULL; -// } -// else -// handle = (void*)tools; -// -// return flag; -//// } -//// else -//// { -//// return AUTHOR_ERROR; -//// } -////#ifdef AUTHORIZATION -////#ifdef __linux__ -//// if (wtime) -//// { -//// delete[] wtime; -//// wtime = NULL; -//// } -////#endif -////#endif -//} - - -int VPT_Init(void *&handle, VPTProcess_PARAM vparam) -{ - objDetector *tools = new objDetector; - - - ctools_init_params param; - param.thres_ = vparam.threshold; - param.log_level_ = 0; - param.device_type_ = vparam.mode; - param.device_id_ = vparam.gpuid; - param.engine_type_ = vparam.engine; - param.model_type_ = MODEL_FPN; - - param.weight_array_ = (uint8_t*)ga_vpt_init_net; - param.weight_array_len_ = ga_vpt_init_net_len; - param.net_array_ = (uint8_t*)ga_vpt_predict_net; - param.net_array_len_ = ga_vpt_predict_net_len; - - param.trt_serialize_file_ = vparam.serialize_file;// NULL;// "FPN_VPT_ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - //trt版本预处理参? - - - memset(param.tensorrt_param_str_, 0, sizeof(param.tensorrt_param_str_)); - - int batch_size = vparam.max_batch; - std::string g_data_mode = "INT8"; - bool g_is_create_calibrator = false; - - sprintf(param.tensorrt_param_str_, "max_batchsize %d," - "data_mode %s," - "is_create_calibrator %d," - "input_names data im_info," - "output_names cls_prob bbox_pred_final rois_count_each_img", - batch_size, g_data_mode.c_str(), g_is_create_calibrator); - - param.tensorrt_calibrator_file_ = NULL;// "trt_fpn_vpt_calibrator"; - param.tensorrt_calibrator_array_len_ = ga_trt_fpn_vpt_calibrator_len;// "trt_fpn_vpt_calibrator"; - param.tensorrt_calibrator_array_ = (unsigned char*)ga_trt_fpn_vpt_calibrator;// "trt_fpn_vpt_calibrator"; - - param.tensorrt_plugin_factory_ptr_ = &(tools->tensorrt_plugin_factory); - - - //param.data_process_str_ = - // "TypeConvert_U8_F32;" - // "ResizePad_F32_F32,test_size,540,test_max_size,1280,fpn_coarsest_stride,32," - // "submean_b,103.94,submean_g,116.78,submean_r,123.68," - // "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" - // "NHWC2NCHW_F32" - // ; - - param.data_process_str_ = - //"CopyData_CPU2GPU_U8;" - "TypeConvert_U8_F32;" - "ResizeMaxPad_F32_F32,test_size,720,test_max_size,1280,max_height,736,max_width,1280," - "submean_b,103.94,submean_g,116.78,submean_r,123.68," - "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" - "NHWC2NCHW_F32" - ; - /* - param.data_process_str_ = - "CopyData_CPU2GPU_U8;" - "TypeConvert_U8_F32;" - "ResizePad_F32_F32,test_size,720,test_max_size,1280,fpn_coarsest_stride,32," - "submean_b,103.94,submean_g,116.78,submean_r,123.68," - "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" - "NHWC2NCHW_F32" - ; - */ - - int flag = ctools_init(&(tools->det_handle), ¶m); - if (SUCCESS != flag) - { - if (tools) - { - delete tools; - tools = NULL; - } - } - else - { - handle = tools; - } - return flag; -} - - -void tmp_test(void * handle) -{ - objDetector *tools = (objDetector*)handle; - -const int batchsize = 5; - sy_img images[batchsize]; - cv::Mat img[batchsize]; - - char strpath[1024]; - memset(strpath, 0, sizeof(strpath)); - for (int b = 0; b < batchsize; b++) - { -#ifdef _MSC_VER - sprintf(strpath, "../../../data/%d.jpg", b);// b); -#else - sprintf(strpath, "0.jpg", b); - -#endif - - img[b] = cv::imread(strpath); - images[b].set_data(img[b].cols, img[b].rows, img[b].channels(), img[b].data); - } - - - //vpt_batch(handle, images, batchsize, &result); - - int count = 1; - while (count--) - { - -printf("begin vpt_batch\n"); - vpt_batch(tools->det_handle, images, batchsize, &result); - - } - - - for (int b = 0; b < batchsize; b++) - { - std::cout << "b: " << b << ", count: " << result[b].obj_count_ << std::endl; - } -} - -int VPT_Process_GPU(void * handle, sy_img * batch_img, int startBatch, int batchsize, vector& result, vector>& deleteObjectID, vector>& unUsedResult) -{ - - - -tmp_test(handle); - - - - - objDetector *tools = (objDetector*)handle; -#ifndef _MSC_VER - struct timeval first_time, second_time; - gettimeofday(&first_time, NULL); -#endif - - bool isUseDet = true; - int channels = 3; - -#ifndef _MSC_VER - if (0) - { - gettimeofday(&second_time, NULL); - double time_val = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; - printf("set data time_val(ms) = %lf\n", time_val / 1000.0); - gettimeofday(&first_time, NULL); - } -#endif - - - ctools_result *detresult; - - sy_img * batch_img_cpu = new sy_img[batchsize]; - for (int i = 0; i < batchsize; ++i) - { - batch_img_cpu[i].data_ = (unsigned char *)malloc(batch_img[i].w_ * batch_img[i].h_ * batch_img[i].c_); - cudaMemcpy(batch_img_cpu[i].data_, batch_img[i].data_, batch_img[i].w_ * batch_img[i].h_ * batch_img[i].c_, cudaMemcpyDeviceToHost); - - cv::Mat newVideoImg(batch_img[i].h_, batch_img[i].w_, CV_8UC3, batch_img_cpu[i].data_); - - char filename[260]; - sprintf(filename, "pic/%d.jpg", i); - cv::imwrite(filename, newVideoImg); - free(batch_img_cpu[i].data_); - - } - - int res_status = ctools_process(tools->det_handle, batch_img, batchsize, &detresult); - //for (int i = 0; i < batchsize; ++i) - //{ - // free(batch_img_cpu[i].data_); - //} - //delete[]batch_img_cpu; - -#ifndef _MSC_VER - - if (0) - { - gettimeofday(&second_time, NULL); - double time_val = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; - printf("process time_val(ms) = %lf\n", time_val / 1000.0); - } - -#endif - - vector >> detectResult(batchsize); //转化为跟踪所需要的输入 - int batch_size = batchsize; - -#ifndef _MSC_VER - - if (0) - { - gettimeofday(&first_time, NULL); - - } - -#endif - - for (int b = 0; b < batch_size; b++) - { - ctools_result &cur_result = detresult[b]; -printf("b=%d, count=%d\n", b, cur_result.obj_count_); - for (int c = 0; c < cur_result.obj_count_ && c < MAX_OBJ_COUNT; c++) - { - - float x1 = cur_result.obj_results_[c].data_[2]; - float y1 = cur_result.obj_results_[c].data_[3]; - float x2 = cur_result.obj_results_[c].data_[4]; - float y2 = cur_result.obj_results_[c].data_[5]; - - float class_id = cur_result.obj_results_[c].data_[0]; - float score = cur_result.obj_results_[c].data_[1]; - - int imgid = b; - if (score >= THRESHOLD) - { - vector obj; - - obj.push_back(x1); - obj.push_back(y1); - obj.push_back(x2); - obj.push_back(y2); - obj.push_back(score); - obj.push_back(class_id); - detectResult[imgid].push_back(obj); - } - } - } - //exit(-1); -#ifndef _MSC_VER - - if (0) - { - gettimeofday(&second_time, NULL); - double time_val = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; - printf("save result time_val(ms) = %lf\n", time_val / 1000.0); - } - -#endif - - int resIndex = startBatch; - int detectIndex = 0; - -#ifndef _MSC_VER - - if (0) - { - gettimeofday(&first_time, NULL); - } -#endif - - for (int i = startBatch; i < tools->taskTrackers.size(); i++) //batch?ֱ????ò?ͬ?ĸ????? - { - printf("i=%d\n", i); - if (!tools->taskTrackers[i].tracker.GetState()) - { - cout << "************************************ " << i << " pause" << endl; - continue; - } - - - // cout << i << " " << taskTrackers[i].TaskID << " " << resIndex << endl; - isUseDet = true; - for (int j = 0; j < FusionInterval; j++) //??֡??????һ֡?????? (FusionInterval - 1)֡ - { - int width = 1920; int height = 1080; - //int objCount = 0; - if (j == 0) - { - int objCount = tools->taskTrackers[i].tracker.update(/*tools->param.w*/width* tools->taskTrackers[i].ratioWidth, /*tools->param.h*/height* tools->taskTrackers[i].ratioHeight, isUseDet, detectResult[detectIndex], result[resIndex].obj, deleteObjectID[detectIndex]); - result[resIndex].objCount = objCount; - vector>().swap(detectResult[detectIndex]); - detectResult[detectIndex].clear(); - isUseDet = false; - } - else - { - VPT_Result unresult; - VPT_ObjInfo obj[MAX_OBJ_COUNT]; - unresult.objCount = tools->taskTrackers[i].tracker.update(/*tools->param.w*/width* tools->taskTrackers[i].ratioWidth, /*tools->param.h*/height* tools->taskTrackers[i].ratioHeight, isUseDet, detectResult[detectIndex], unresult.obj, deleteObjectID[detectIndex]); - unUsedResult[resIndex].push_back(unresult); - } - } - std::cout<<"tracked obj Count : "<>>().swap(detectResult); - -#ifndef _MSC_VER - - if (0) - { - gettimeofday(&second_time, NULL); - double time_val = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; - printf("tracking time_val(ms) = %lf\n", time_val / 1000.0); - } -#endif - - return SUCCESS; -} - - - -void VPT_Release(void * handle) -{ - objDetector *tools = (objDetector*)handle; - - if (tools) - { - if (tools->det_handle) - { - ctools_release(&tools->det_handle); - tools->det_handle = NULL; - } - - vector().swap(tools->taskTrackers); - - delete tools; - tools = NULL; - } -} - -void AddTaskTracker(void * handle, const int taskID, const double rWidth, const double rHeight) -{ - objDetector *tools = (objDetector*)handle; - TaskTracker t; - t.TaskID = taskID; - t.ratioWidth = rWidth; - t.ratioHeight = rHeight; - tools->taskTrackers.push_back(t); -} - -void FinishTaskTracker(void * handle, const int taskID) -{ - objDetector *tools = (objDetector*)handle; - for (int i = 0; i < tools->taskTrackers.size(); i++) - { - if (tools->taskTrackers[i].TaskID == taskID) - { - tools->taskTrackers.erase(tools->taskTrackers.begin() + i); - break; - } - } -} - -void PauseTaskTracker(void * handle, const int taskID) -{ - objDetector *tools = (objDetector*)handle; - for (int i = 0; i < tools->taskTrackers.size(); i++) - { - if (tools->taskTrackers[i].TaskID == taskID) - { - tools->taskTrackers[i].tracker.Pause(); - break; - } - } -} - -void RestartTaskTraker(void * handle, const int taskID) -{ - objDetector *tools = (objDetector*)handle; - for (int i = 0; i < tools->taskTrackers.size(); i++) - { - if (tools->taskTrackers[i].TaskID == taskID) - { - tools->taskTrackers[i].tracker.ReSet(); - break; - } - } -} - -void DrawTracker(void * handle, const int taskID, cv::Mat *img) -{ - objDetector *tools = (objDetector*)handle; - for (int i = 0; i < tools->taskTrackers.size(); i++) - { - if (tools->taskTrackers[i].TaskID == taskID) - { - tools->taskTrackers[i].tracker.addTracker(img); - break; - } - } -} - - - -int VPT_Process(void * handle, unsigned char ** bgr, int batchsize, VPT_Result *result) -{ - // isUseDet = false; - // } - - // } - // resIndex++; - // if (resIndex == batchsize) break; - //} - //vector >>().swap(detectResult); - //vector>().swap(ssdResult); - ///*detectResult.clear(); - //ssdResult.clear();*/ - - return SUCCESS; -} - -//#include - - - - -void permute(float * image, int testWidth, int testHeight) -{ - //cv::Mat host_image; - float * host_image; - //host_image.create(testHeight, testWidth, CV_32FC3); - - host_image = (float *)malloc(testHeight*testWidth * 3 * sizeof(float));; - - float *Host_img = new float[3 * testWidth * testHeight]{};//?????ڴ? - - float* image_data_original = image; - //NPP_CHECK_CUDA(cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyDeviceToHost));//?????Կ???????ͼ???????? - cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyDeviceToHost);//?????Կ???????ͼ???????? - - for (int j = 0; j < testHeight; j++) - { - float *pts = host_image + j * testWidth * 3; - for (int i = 0; i < testWidth; i++) - { - //pts[3 * i] = cv::saturate_cast(Host_img[3 * (j*host_image.cols + i) + 0]); //b - //pts[3 * i + 1] = cv::saturate_cast(Host_img[3 * (j*host_image.cols + i) + 1]); //g - //pts[3 * i + 2] = cv::saturate_cast(Host_img[3 * (j*host_image.cols + i) + 2]); //r - - pts[3 * i] = (Host_img[j * testWidth + i]); //b - pts[3 * i + 1] = (Host_img[testWidth * testHeight + j * testWidth + i]); //g - pts[3 * i + 2] = (Host_img[2 * testWidth * testHeight + j * testWidth + i]); //r - } - } - - cudaMemcpy(image_data_original, host_image, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyHostToDevice); - free(host_image); - //cv::Mat showImg; - //cv::resize(host_image, showImg, cv::Size(640, 480)); - //cv::imshow("image", showImg); - //cv::waitKey(0); -} - -cv::Mat GpuMat2OpencvMat(unsigned char* image, int width, int height) -{ - int testWidth = width; - int testHeight = height; - cv::Mat host_image; - host_image.create(testHeight, testWidth, CV_8UC3); - unsigned char *Host_img = new unsigned char[3 * testWidth * testHeight]{};//?????ڴ? - unsigned char* image_data_original = image; - - cudaError_t code = cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost);//?????Կ???????ͼ???????? - if (code != 0) - { - printf("==========================================================error"); - } - std::ofstream outfile("decode.bin", ios::out | ios::binary); - outfile.write((char*)Host_img, int(sizeof(char) * 1080 * 1920 * 3)); - outfile.close(); - - cudaMemcpy(host_image.data, image_data_original, 1920 * testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost);//?????Կ???????ͼ???????? - - // for (int j = 0; j < host_image.rows; j++) - // { - // uchar *pts = host_image.ptr(j); - // for (int i = 0; i < host_image.cols; i++) - // { - // //pts[3 * i] = cv::saturate_cast(Host_img[3 * (j*host_image.cols + i) + 0]); //b - // //pts[3 * i + 1] = cv::saturate_cast(Host_img[3 * (j*host_image.cols + i) + 1]); //g - // //pts[3 * i + 2] = cv::saturate_cast(Host_img[3 * (j*host_image.cols + i) + 2]); //r - // pts[3 * i] = cv::saturate_cast(Host_img[j* host_image.cols*3 + 3 * i]); //b - // pts[3 * i + 1] = cv::saturate_cast(Host_img[j* host_image.cols*3 + 3 * i + 1]); //g - // pts[3 * i + 2] = cv::saturate_cast(Host_img[j* host_image.cols*3 + 3 * i + 2]); //r - // } - // } - cv::imwrite("input3.jpg", host_image); - return host_image; -} - - -int VPT_ProcessImage(void * handle, unsigned char ** bgr, int batchsize, VPT_Result * result) -{ - //objDetector* tools = (objDetector*)handle; - //if (bgr == NULL) //ͼ?????ݴ??? - // return IMG_DATA_ERROR; - - //vector imgs; - ////int datasize = tools->param.w * tools->param.h * tools->param.c; - //for (int i = 0; i < batchsize; i++) - //{ - // Mat img(tools->param.h, tools->param.w, tools->param.c, bgr[i]); - // imgs.push_back(img); - //} - - //vector> ssdResult; - ////clock_t begin = clock(); - //ssdResult = SSD_Detect(tools->detector, batchsize, imgs); // - //vector >> detectResult(batchsize); //ת??Ϊ????????Ҫ?????? - //for (int i = 0; i < ssdResult.size(); ++i) - //{ - // const vector& d = ssdResult[i];// Detection format: [image_id, label, score, xmin, ymin, xmax, ymax) - // const float score = d[2]; - // int imgid = d[0]; - // if (score >= THRESHOLD) //????Ϊleft top right bottom score id - // { - // vector obj; - // obj.push_back(d[3] * imgs[d[0]].cols); - // obj.push_back(d[4] * imgs[d[0]].rows); - // obj.push_back(d[5] * imgs[d[0]].cols); - // obj.push_back(d[6] * imgs[d[0]].rows); - // obj.push_back(d[2]); - // obj.push_back(d[1]); - // detectResult[imgid].push_back(obj); - // } - //} - //for (int i = 0; i < batchsize; i++) - //{ - // for (int j = 0; j < detectResult[i].size(); j++)//left top right bottom score id - // { - // result[i].obj[j].id = 0; - // result[i].obj[j].left = detectResult[i][j][0]; - // result[i].obj[j].top = detectResult[i][j][1]; - // result[i].obj[j].right = detectResult[i][j][2]; - // result[i].obj[j].bottom = detectResult[i][j][3]; - // result[i].obj[j].confidence = detectResult[i][j][4]; - // result[i].obj[j].index = detectResult[i][j][5] - 1; - // } - // - //} - - return SUCCESS; -} \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/backup.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/backup.h deleted file mode 100644 index 53d4e54..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/backup.h +++ /dev/null @@ -1,22 +0,0 @@ -//QueryPerformanceCounter(&nSnapshotBeginTime); -//int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left * pThreadParam->tasks[*iter].taskHeightWidth.width) - 2); -//int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top * pThreadParam->tasks[*iter].taskHeightWidth.height) - 2); -//int right = min(pThreadParam->tasks[*iter].taskDataToBackup.width, (int)(pThreadParam->VPTResult[i].obj[c].right * pThreadParam->tasks[*iter].taskHeightWidth.width) + 2); -//int bottom = min(pThreadParam->tasks[*iter].taskDataToBackup.height, (int)(pThreadParam->VPTResult[i].obj[c].bottom * pThreadParam->tasks[*iter].taskHeightWidth.height) + 2); -// -// -//pThreadParam->tasks[*iter].taskDataToBackupHost = (float*)malloc(100 * 100 * sizeof(float)); -//cudaMemcpy2D(pThreadParam->tasks[*iter].taskDataToBackupHost, sizeof(float) * 100, pThreadParam->tasks[*iter].taskDataToBackup.data + 100, pitch, sizeof(float) * 100, 100, cudaMemcpyDeviceToHost); -//pThreadParam->SaveSnapshot(pThreadParam->tasks[*iter].taskDataToBackupHost, 100, 100, *iter, pThreadParam->VPTResult[i].obj[c].id, 0, 0, 100, 100); -// -//QueryPerformanceCounter(&nSnapshotEndTime); -//printf("%d %d Copy Image Time: %.2f ms \n", *iter, pThreadParam->tasks[*iter].taskFrameCount, (double)(nSnapshotEndTime.QuadPart - nSnapshotBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart); - - -// GPU -//QueryPerformanceCounter(&nSnapshotBeginTime); -//char snapShotName[260]; -//sprintf(snapShotName, "SnapshotLittle\\%d\\%d.jpg", *iter, pThreadParam->VPTResult[i].obj[c].id); -//saveJPEG(snapShotName, pThreadParam->tasks[*iter].taskDataToBackup.data, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height); -//QueryPerformanceCounter(&nSnapshotEndTime); -//printf("%d %d Copy Image Time: %.2f ms \n", *iter, pThreadParam->tasks[*iter].taskFrameCount, (double)(nSnapshotEndTime.QuadPart - nSnapshotBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.hold b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.hold deleted file mode 100644 index baa95d6..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.hold +++ /dev/null @@ -1,296 +0,0 @@ -#pragma once - -#ifdef _MSC_VER -#include -#else -#include -#endif - -#include "sy_common.h" - -#define DETECTTYPE 9 - -#ifndef VD_INFO_ -#define VD_INFO_ -// -typedef struct vd_info -{ - sy_rect rect; - float score; -}vd_info; -#endif - -#ifndef VCWD_INFO_ -#define VCWD_INFO_ -// -typedef struct vcwd_info -{ - vd_info c_info; //Ϣ - vd_info w_info; //Ϣ -}vcwd_info; -#endif - -#ifndef VCWD_RESULT_ -#define VCWD_RESULT_ -#define VD_MAXDETECTCOUNT 100 //ͷβֵ -#define FEATURESIZE 256 -typedef struct vcwd_result -{ - vcwd_info * vhd_info; //ͷϢ - int h_count; //ͷ - - vcwd_info * vrd_info; //βϢ - int r_count; //β -}vcwd_result; - -#endif - -//Էṹ -#ifndef __HF_OBJ_RESULT__ -#define __HF_OBJ_RESULT__ -const int Hf_FIR_INDEX_SIZE = 1280; -typedef struct hf_result -{ - float res_objs[Hf_FIR_INDEX_SIZE]{}; // -} hf_result; -#endif -//Էṹ -#ifndef __CLASSIFY_OBJ_RESULT__ -#define __CLASSIFY_OBJ_RESULT__ -typedef struct classify_obj_res //ṹ -{ - int res_index; // - float res_prob; //ṹ - classify_obj_res() : res_index(0), res_prob(0) {}; -} classify_obj_res; -#endif - -#ifndef __HF_FEA_RESULT__ -#define __HF_FEA_RESULT__ -const int HF_FEA_SIZE = 576; -#endif - -#ifndef __HP_OBJ_RESULT__ -#define __HP_OBJ_RESULT__ -const int HP_FIR_INDEX_SIZE = 16; -typedef struct hp_res -{ - classify_obj_res res_objs[HP_FIR_INDEX_SIZE]; // - float feature[HF_FEA_SIZE]; // -} hp_res; -#endif - -typedef struct hp_result -{ - hp_res res_objs{}; // - float feature[Hf_FIR_INDEX_SIZE]{}; // -} hp_result; - -#ifndef __HCF_FEA_RES__ -#define __HCF_FEA_RES__ -const int HCF_FEA_SIZE = 1280; -#endif - -#ifndef __HCP_OBJ_RESULT__ -#define __HCP_OBJ_RESULT__ -const int HCP_FIR_INDEX_SIZE = 14; -typedef struct hcp_res -{ - classify_obj_res res_objs[HCP_FIR_INDEX_SIZE]; // - float feature[HCF_FEA_SIZE]; //ﳵ -} hcp_res; -#endif - -typedef struct hcp_result -{ - hcp_res res_objs{}; // - float feature[Hf_FIR_INDEX_SIZE]{}; // -} hcp_result; - -//VEHICLE -#define PLATENUM 8 //ƺλ -#define MAX_PALTE_COUNT 10 //ÿͼƬ10 - -#define SINGLETYPE_BLUE 0 //ɫ -#define SINGLETYPE_YELLOW 1 //Żɫ -#define SINGLETYPE_WHITE 2 //Űɫ -#define SINGLETYPE_BLACK 3 //źɫ -#define DOUBLETYPE_YELLOW 4 //˫Żɫ -#define DOUBLETYPE_WHITE 5 //˫Űɫ -#define NEWENERGYTYPE_YELLOWGREEN 6 //Դɫ -#define NEWENERGYTYPE_WHITEGRA 7 //Դɫ - -//ƺ -#ifndef VPLATENUM_RESULT_ -#define VPLATENUM_RESULT_ -typedef struct vplate_num -{ - char character[4]; //ʶַ - float maxprob; //ʶŶ -}vplate_num; -#endif - -#ifndef VP_RESULT_ -#define VP_RESULT_ -typedef struct vplate_result -{ - sy_rect rect; //λ - float detect_score; //Ŷ - vplate_num recg[PLATENUM]; //ʶ - float num_score; //ʶŶ - int type; // -}vplate_result; -#endif - -#ifndef VR_RESULT_ -#define VR_RESULT_ -typedef struct vr_result // -{ - char vehicle_brand[260]; //Ʒ - char vehicle_subbrand[260]; //Ʒ - char vehicle_issue_year[260]; // - char vehicle_type[260]; // - char freight_ton[260]; //ּ - float name_score; //ʶŶ -}vr_result; -#endif - - - -//2.ɫ -#ifndef VC_RESULT_ -#define VC_RESULT_ -typedef struct vc_result -{ - float score; - int index; -}vc_result; -#endif - - -//#ifndef __VEHICLE_RESULT__ -//#define __VEHICLE_RESULT__ -//typedef struct vehicle_res //Է -//{ -// vr_result vr_res; //ʶ -// vc_result vc_res; //ɫʶ -// vplate_result vp_res; //Ƽ -//} vehicle_res; -// -//#endif -#ifndef __VEHICLE_RESULT__ -#define __VEHICLE_RESULT__ -typedef struct vehicle_result //Է -{ - vr_result vr_res; //ʶ - vc_result vc_res; //ɫʶ - vplate_result vp_res; //Ƽ - float feature[FEATURESIZE]{}; // -} vehicle_result; -#endif -//صļս -#ifndef __VIDEO_OBJECT_SNAPSHOT__ -#define __VIDEO_OBJECT_SNAPSHOT__ -typedef struct video_object_snapshot -{ - int task_id; //ڵID - int object_id; //ID - char video_image_path[256]; //յƵͼ· - char snapshot_image_path[256]; //տͼ· - int object_type_index; // - char obj_type[64]; //ڵ - double progress; //·Ƶļ - - int left; //λõ - int top; //λõ - int right; //λõ - int bottom; //λõ - double confidence; //Ŷ - - void* analysisRes; //Է -} video_object_snapshot; -#endif - -//صļϢ -#ifndef __VIDEO_OBJECT_INFO__ -#define __VIDEO_OBJECT_INFO__ -typedef struct video_object_info -{ - int task_id; //ڵID - int task_frame_count; //嵱ǰֵ֡ - int object_id; //ID - int left; //λõ - int top; //λõ - int right; //λõ - int bottom; //λõ - int index; //ı - double confidence; //Ŷ -} video_object_info; -#endif - -//ص֪ͨƵ,ID -typedef void(*VIDEO_OBJECT_INFO_CALLBACK)(void * handle, video_object_info *obj_info); - - -//صؼĿϢ -typedef void(*VIDEO_OBJECT_SNAPSHOT_CALLBACK)(void * handle, video_object_snapshot *snapshot_info); - - -//صʵʱ鿴ʱƵͼ -typedef void(*VIDEO_REALTIME_CALLBACK)(void * handle, unsigned char *img_data, int img_height, int img_width); - - -//ص֪ͨƵ,ID -typedef void(*VIDEO_FINISH_CALLBACK)(void * handle, const int task_id); - - -//TASKʼ -#ifndef __TASK_PARAM__ -#define __TASK_PARAM__ -typedef struct task_param -{ - const char* video_filename; - const char* result_folder_little; - const char* result_folder; - sy_rect minBoxsize[DETECTTYPE]; //ԶminBoxsizeС - VIDEO_OBJECT_SNAPSHOT_CALLBACK obj_snapshot_callback_func; - VIDEO_REALTIME_CALLBACK rt_view_callback_func; -}task_param; -#endif - - -//VPTʼ -#ifndef __MVPT_PARAM__ -#define __MVPT_PARAM__ -typedef struct mvpt_param -{ - int gpuid; //ָԿid - char* vrdbpath; //ָʶijݿ· - - //㷨ò - sy_command hp_analysis_config; //Ƿ˽ṹʶ - sy_command hcp_analysis_config; //Ƿﳵṹʶ - sy_command vehicle_analysis_config; //Ƿʶ - sy_command hf_recg_config; //Ƿʶ - sy_command hcf_recg_config; //Ƿﳵʶ - sy_command vcf_recg_config; //Ƿʶ - - VIDEO_OBJECT_INFO_CALLBACK task_obj_info_callback_func; //Ŀʵʱػص - VIDEO_FINISH_CALLBACK task_finish_callbackfunc; //ص -}mvpt_param; -#endif - - -#ifndef _MSC_VER -#include - -#define MACRO_COUNT_TIME_START struct timeval macro_tv_start;\ - struct timeval macro_tv_end;\ - gettimeofday(¯o_tv_start,NULL); - -#define MACRO_COUNT_TIME_END(___total_count___) gettimeofday(¯o_tv_end,NULL);\ - if(___total_count___<=0)\ - printf("time cost: %.2f ms \n", ( (double)(macro_tv_end.tv_sec-macro_tv_start.tv_sec)*1000000+(double)(macro_tv_end.tv_usec-macro_tv_start.tv_usec) )/1000);\ - else\ - printf("time cost: %.2f ms \n", ( (double)(macro_tv_end.tv_sec-macro_tv_start.tv_sec)*1000000+(double)(macro_tv_end.tv_usec-macro_tv_start.tv_usec) )/1000/___total_count___); -#endif diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/jpegNPP.hbk b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/jpegNPP.hbk deleted file mode 100644 index 14f906a..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/jpegNPP.hbk +++ /dev/null @@ -1,1174 +0,0 @@ -/* -* Copyright 1993-2015 NVIDIA Corporation. All rights reserved. -* -* NOTICE TO USER: -* -* This source code is subject to NVIDIA ownership rights under U.S. and -* international Copyright laws. -* -* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE -* CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR -* IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH -* REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF -* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. -* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, -* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE -* OR PERFORMANCE OF THIS SOURCE CODE. -* -* U.S. Government End Users. This source code is a "commercial item" as -* that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of -* "commercial computer software" and "commercial computer software -* documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) -* and is provided to the U.S. Government only as a commercial end item. -* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through -* 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the -* source code with only those rights set forth herein. -*/ - -// This sample needs at least CUDA 5.5 and a GPU that has at least Compute Capability 2.0 - -// This sample demonstrates a simple image processing pipeline. -// First, a JPEG file is huffman decoded and inverse DCT transformed and dequantized. -// Then the different planes are resized. Finally, the resized image is quantized, forward -// DCT transformed and huffman encoded. - -#include -#include -#include "EnCode/Exceptions.h" - -#include "EnCode/Endianess.h" -#include - -#include -#include -#include - -#include -#include - -using namespace std; - -struct FrameHeader //֡ͼ -{ - unsigned char nSamplePrecision; //ȣʾÿλ - unsigned short nHeight; //ͼĸ Ϊλ - unsigned short nWidth; //ͼĿ Ϊλ - unsigned char nComponents; //ɫ - unsigned char aComponentIdentifier[3]; //ɫID - unsigned char aSamplingFactors[3]; //ˮƽ/ֱӣ4λˮƽӣ4λֱ - unsigned char aQuantizationTableSelector[3]; //ǰʹõID -}; - -struct ScanHeader -{ - unsigned char nComponents; - unsigned char aComponentSelector[3]; - unsigned char aHuffmanTablesSelector[3]; - unsigned char nSs; - unsigned char nSe; - unsigned char nA; -}; - -struct QuantizationTable -{ - unsigned char nPrecisionAndIdentifier; - unsigned char aTable[64]; -}; - -struct HuffmanTable -{ - unsigned char nClassAndIdentifier; - unsigned char aCodes[16]; - unsigned char aTable[256]; -}; - - -int DivUp(int x, int d) -{ - return (x + d - 1) / d; -} - -template -T readAndAdvance(const unsigned char *&pData) -{ - T nElement = readBigEndian(pData); - pData += sizeof(T); - return nElement; -} - -template -void writeAndAdvance(unsigned char *&pData, T nElement) -{ - writeBigEndian(pData, nElement); - pData += sizeof(T); -} - - -int nextMarker(const unsigned char *pData, int &nPos, int nLength) -{ - unsigned char c = pData[nPos++]; - - do - { - while (c != 0xffu && nPos < nLength) - { - c = pData[nPos++]; - } - - if (nPos >= nLength) - return -1; - - c = pData[nPos++]; - } while (c == 0 || c == 0x0ffu); - - return c; -} - -void writeMarker(unsigned char nMarker, unsigned char *&pData) -{ - *pData++ = 0x0ff; - *pData++ = nMarker; -} - -void writeJFIFTag(unsigned char *&pData) -{ - const char JFIF_TAG[] = - { - 0x4a, 0x46, 0x49, 0x46, 0x00, - 0x01, 0x02, - 0x00, - 0x00, 0x01, 0x00, 0x01, - 0x00, 0x00 - }; - - writeMarker(0x0e0, pData); - writeAndAdvance(pData, sizeof(JFIF_TAG) + sizeof(unsigned short)); - memcpy(pData, JFIF_TAG, sizeof(JFIF_TAG)); - pData += sizeof(JFIF_TAG); -} - -void loadJpeg(const char *input_file, unsigned char *&pJpegData, int &nInputLength) -{ - // Load file into CPU memory - ifstream stream(input_file, ifstream::binary); - - if (!stream.good()) - { - return; - } - - stream.seekg(0, ios::end); - nInputLength = (int)stream.tellg(); - stream.seekg(0, ios::beg); - - pJpegData = new unsigned char[nInputLength] {}; - stream.read(reinterpret_cast(pJpegData), nInputLength); -} - -void readFrameHeader(const unsigned char *pData, FrameHeader &header) -{ - readAndAdvance(pData); - header.nSamplePrecision = readAndAdvance(pData); - header.nHeight = readAndAdvance(pData); - header.nWidth = readAndAdvance(pData); - header.nComponents = readAndAdvance(pData); - - for (int c = 0; c(pData); - header.aSamplingFactors[c] = readAndAdvance(pData); - header.aQuantizationTableSelector[c] = readAndAdvance(pData); - } - -} - -void writeFrameHeader(const FrameHeader &header, unsigned char *&pData) -{ - unsigned char aTemp[128]; - unsigned char *pTemp = aTemp; - - writeAndAdvance(pTemp, header.nSamplePrecision); - writeAndAdvance(pTemp, header.nHeight); - writeAndAdvance(pTemp, header.nWidth); - writeAndAdvance(pTemp, header.nComponents); - - for (int c = 0; c(pTemp, header.aComponentIdentifier[c]); - writeAndAdvance(pTemp, header.aSamplingFactors[c]); - writeAndAdvance(pTemp, header.aQuantizationTableSelector[c]); - } - - unsigned short nLength = (unsigned short)(pTemp - aTemp); - - writeMarker(0x0C0, pData); - writeAndAdvance(pData, nLength + 2); - memcpy(pData, aTemp, nLength); - pData += nLength; -} - - -void readScanHeader(const unsigned char *pData, ScanHeader &header) -{ - readAndAdvance(pData); - - header.nComponents = readAndAdvance(pData); - - for (int c = 0; c(pData); - header.aHuffmanTablesSelector[c] = readAndAdvance(pData); - } - - header.nSs = readAndAdvance(pData); - header.nSe = readAndAdvance(pData); - header.nA = readAndAdvance(pData); -} - - -void writeScanHeader(const ScanHeader &header, unsigned char *&pData) -{ - unsigned char aTemp[128]; - unsigned char *pTemp = aTemp; - - writeAndAdvance(pTemp, header.nComponents); - - for (int c = 0; c(pTemp, header.aComponentSelector[c]); - writeAndAdvance(pTemp, header.aHuffmanTablesSelector[c]); - } - - writeAndAdvance(pTemp, header.nSs); - writeAndAdvance(pTemp, header.nSe); - writeAndAdvance(pTemp, header.nA); - - unsigned short nLength = (unsigned short)(pTemp - aTemp); - - writeMarker(0x0DA, pData); - writeAndAdvance(pData, nLength + 2); - memcpy(pData, aTemp, nLength); - pData += nLength; -} - - -void readQuantizationTables(const unsigned char *pData, QuantizationTable *pTables) -{ - unsigned short nLength = readAndAdvance(pData) -2; - - while (nLength > 0) - { - unsigned char nPrecisionAndIdentifier = readAndAdvance(pData); - int nIdentifier = nPrecisionAndIdentifier & 0x0f; - - pTables[nIdentifier].nPrecisionAndIdentifier = nPrecisionAndIdentifier; - memcpy(pTables[nIdentifier].aTable, pData, 64); - pData += 64; - - nLength -= 65; - } -} - -void writeQuantizationTable(const QuantizationTable &table, unsigned char *&pData) -{ - writeMarker(0x0DB, pData); - writeAndAdvance(pData, sizeof(QuantizationTable) + 2); - memcpy(pData, &table, sizeof(QuantizationTable)); - pData += sizeof(QuantizationTable); -} - -void readHuffmanTables(const unsigned char *pData, HuffmanTable *pTables) -{ - unsigned short nLength = readAndAdvance(pData) -2; - - while (nLength > 0) - { - unsigned char nClassAndIdentifier = readAndAdvance(pData); - int nClass = nClassAndIdentifier >> 4; // AC or DC - int nIdentifier = nClassAndIdentifier & 0x0f; - int nIdx = nClass * 2 + nIdentifier; - pTables[nIdx].nClassAndIdentifier = nClassAndIdentifier; - - // Number of Codes for Bit Lengths [1..16] - int nCodeCount = 0; - - for (int i = 0; i < 16; ++i) - { - pTables[nIdx].aCodes[i] = readAndAdvance(pData); - nCodeCount += pTables[nIdx].aCodes[i]; - } - - memcpy(pTables[nIdx].aTable, pData, nCodeCount); - pData += nCodeCount; - - nLength -= 17 + nCodeCount; - } -} - -void writeHuffmanTable(const HuffmanTable &table, unsigned char *&pData) -{ - writeMarker(0x0C4, pData); - - // Number of Codes for Bit Lengths [1..16] - int nCodeCount = 0; - - for (int i = 0; i < 16; ++i) - { - nCodeCount += table.aCodes[i]; - } - - writeAndAdvance(pData, 17 + nCodeCount + 2); - memcpy(pData, &table, 17 + nCodeCount); - pData += 17 + nCodeCount; -} - - -void readRestartInterval(const unsigned char *pData, int &nRestartInterval) -{ - readAndAdvance(pData); - nRestartInterval = readAndAdvance(pData); -} - -void printHelp() -{ - cout << "jpegNPP usage" << endl; - cout << " -input=srcfile.jpg (input file JPEG image)" << endl; - cout << " -output=destfile.jpg (output file JPEG image)" << endl; - cout << " -scale=1.0 (scale multiplier for width and height)" << endl << endl; -} - -bool printfNPPinfo(int argc, char *argv[], int cudaVerMajor, int cudaVerMinor) -{ - const NppLibraryVersion *libVer = nppGetLibVersion(); - - printf("NPP Library Version %d.%d.%d\n", libVer->major, libVer->minor, libVer->build); - - int driverVersion, runtimeVersion; - cudaDriverGetVersion(&driverVersion); - cudaRuntimeGetVersion(&runtimeVersion); - - printf(" CUDA Driver Version: %d.%d\n", driverVersion / 1000, (driverVersion % 100) / 10); - printf(" CUDA Runtime Version: %d.%d\n", runtimeVersion / 1000, (runtimeVersion % 100) / 10); - - bool bVal = checkCudaCapabilities(cudaVerMajor, cudaVerMinor); - return bVal; -} - -const char *szInputFile; -const char *szOutputFile; -NppiSize aSrcSize[3]; -Npp16s *aphDCT[3] = { 0, 0, 0 }; -Npp16s *apdDCT[3] = { 0, 0, 0 }; -Npp16s *apdDCT_My[3] = { 0, 0, 0 }; -Npp32s aDCTStep[3]; - -Npp8u *apSrcImage[3] = { 0, 0, 0 }; -Npp32s aSrcImageStep[3]; - -Npp8u *apDstImage[3] = { 0, 0, 0 }; -Npp32s aDstImageStep[3]; -NppiSize aDstSize[3]; - -HuffmanTable aHuffmanTables[4]; -HuffmanTable *pHuffmanDCTables = aHuffmanTables; -HuffmanTable *pHuffmanACTables = &aHuffmanTables[2]; - -ScanHeader oScanHeader; -FrameHeader oFrameHeader; -QuantizationTable aQuantizationTables[4]; -Npp8u *pdQuantizationTables; -NppiDCTState *pDCTState; -int nMCUBlocksH = 0; -int nMCUBlocksV = 0; -unsigned char *pJpegData = 0; -int nInputLength = 0; - - - -int DecodeJPEG() -{ - //float nScaleFactor; - - szInputFile = "G:\\TestData\\˳\\18.jpg"; - cout << "Source File: " << szInputFile << endl; - szOutputFile = "scaled.jpg"; - cout << "Output File: " << szOutputFile << endl; - - /*if (checkCmdLineFlag(argc, (const char **)argv, "scale")) - { - nScaleFactor = max(0.0f, min(getCmdLineArgumentFloat(argc, (const char **)argv, "scale"), 1.0f)); - } - else - { - nScaleFactor = 1.0f; - } - - cout << "Scale Factor: " << nScaleFactor << endl;*/ - - - NPP_CHECK_NPP(nppiDCTInitAlloc(&pDCTState)); - - - - // Load Jpeg - loadJpeg(szInputFile, pJpegData, nInputLength); - - if (pJpegData == 0) - { - cerr << "1. Input File Error: " << szInputFile << endl; - return EXIT_FAILURE; - } - - /*************************** - * - * Input - * - ***************************/ - - - // Check if this is a valid JPEG file - int nPos = 0; - int nMarker = nextMarker(pJpegData, nPos, nInputLength); - - if (nMarker != 0x0D8) - { - cerr << "Invalid Jpeg Image" << endl; - return EXIT_FAILURE; - } - - nMarker = nextMarker(pJpegData, nPos, nInputLength); - - // Parsing and Huffman Decoding (on host) - - cudaMalloc(&pdQuantizationTables, 64 * 4); - - - memset(&oFrameHeader, 0, sizeof(FrameHeader)); - memset(aQuantizationTables, 0, 4 * sizeof(QuantizationTable)); - memset(aHuffmanTables, 0, 4 * sizeof(HuffmanTable)); - - int nRestartInterval = -1; - - - - while (nMarker != -1) - { - if (nMarker == 0x0D8) - { - // Embedded Thumbnail, skip it - int nNextMarker = nextMarker(pJpegData, nPos, nInputLength); - - while (nNextMarker != -1 && nNextMarker != 0x0D9) - { - nNextMarker = nextMarker(pJpegData, nPos, nInputLength); - } - } - - if (nMarker == 0x0DD) - { - readRestartInterval(pJpegData + nPos, nRestartInterval); - } - - if ((nMarker == 0x0C0) | (nMarker == 0x0C2)) - { - //Assert Baseline for this Sample - //Note: NPP does support progressive jpegs for both encode and decode - if (nMarker != 0x0C0) - { - cerr << "The sample does only support baseline JPEG images" << endl; - return EXIT_SUCCESS; - } - - // Baseline or Progressive Frame Header - //ȡJPEGļͷ - readFrameHeader(pJpegData + nPos, oFrameHeader); - cout << "Image Size: " << oFrameHeader.nWidth << "x" << oFrameHeader.nHeight << "x" << static_cast(oFrameHeader.nComponents) << endl; - - //Assert 3-Channel Image for this Sample - if (oFrameHeader.nComponents != 3) - { - cerr << "The sample does only support color JPEG images" << endl; - return EXIT_SUCCESS; - } - - // Compute channel sizes as stored in the JPEG (8x8 blocks & MCU block layout) - for (int i = 0; i < oFrameHeader.nComponents; ++i) - { - nMCUBlocksV = max(nMCUBlocksV, oFrameHeader.aSamplingFactors[i] & 0x0f); //2 1 1 - nMCUBlocksH = max(nMCUBlocksH, oFrameHeader.aSamplingFactors[i] >> 4); //2 1 1 - } - - for (int i = 0; i < oFrameHeader.nComponents; ++i) - { - NppiSize oBlocks; - NppiSize oBlocksPerMCU = { oFrameHeader.aSamplingFactors[i] >> 4, oFrameHeader.aSamplingFactors[i] & 0x0f }; //ˮƽ ֱ - - cout << "oBlocksPerMCU Size: " << oBlocksPerMCU.width << " " << oBlocksPerMCU.height << endl; - - oBlocks.width = (int)ceil((oFrameHeader.nWidth + 7) / 8 * - static_cast(oBlocksPerMCU.width) / nMCUBlocksH); - oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width; // ȡ ȷеMCU BlockĴС - - oBlocks.height = (int)ceil((oFrameHeader.nHeight + 7) / 8 * - static_cast(oBlocksPerMCU.height) / nMCUBlocksV); - oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height; - - aSrcSize[i].width = oBlocks.width * 8; - aSrcSize[i].height = oBlocks.height * 8; - - cout << "oBlock Size: " << oBlocks.width << " " << oBlocks.height << endl; - - // Allocate Memory - size_t nPitch; //طһеڴС - NPP_CHECK_CUDA(cudaMallocPitch(&apdDCT[i], &nPitch, oBlocks.width * 64 * sizeof(Npp16s), oBlocks.height)); - NPP_CHECK_CUDA(cudaMallocPitch(&apdDCT_My[i], &nPitch, oBlocks.width * 64 * sizeof(Npp16s), oBlocks.height)); - aDCTStep[i] = static_cast(nPitch); - - NPP_CHECK_CUDA(cudaMallocPitch(&apSrcImage[i], &nPitch, aSrcSize[i].width, aSrcSize[i].height)); - aSrcImageStep[i] = static_cast(nPitch); - - NPP_CHECK_CUDA(cudaHostAlloc(&aphDCT[i], aDCTStep[i] * oBlocks.height, cudaHostAllocDefault)); - } - } - - //ѹжȡ - if (nMarker == 0x0DB) - { - // Quantization Tables - readQuantizationTables(pJpegData + nPos, aQuantizationTables); - } - - //ѹжȡ ر - if (nMarker == 0x0C4) - { - // Huffman Tables - readHuffmanTables(pJpegData + nPos, aHuffmanTables); - } - - if (nMarker == 0x0DA) - { - // Scan - readScanHeader(pJpegData + nPos, oScanHeader); - nPos += 6 + oScanHeader.nComponents * 2; - - int nAfterNextMarkerPos = nPos; - int nAfterScanMarker = nextMarker(pJpegData, nAfterNextMarkerPos, nInputLength); - - if (nRestartInterval > 0) - { - while (nAfterScanMarker >= 0x0D0 && nAfterScanMarker <= 0x0D7) - { - // This is a restart marker, go on - nAfterScanMarker = nextMarker(pJpegData, nAfterNextMarkerPos, nInputLength); - } - } - - NppiDecodeHuffmanSpec *apHuffmanDCTable[3]; - NppiDecodeHuffmanSpec *apHuffmanACTable[3]; - - for (int i = 0; i < 3; ++i) - { - nppiDecodeHuffmanSpecInitAllocHost_JPEG(pHuffmanDCTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, nppiDCTable, &apHuffmanDCTable[i]); - nppiDecodeHuffmanSpecInitAllocHost_JPEG(pHuffmanACTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f)].aCodes, nppiACTable, &apHuffmanACTable[i]); - } - - //ָͼ - NPP_CHECK_NPP(nppiDecodeHuffmanScanHost_JPEG_8u16s_P3R(pJpegData + nPos, nAfterNextMarkerPos - nPos - 2, - nRestartInterval, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, - aphDCT, aDCTStep, - apHuffmanDCTable, - apHuffmanACTable, - aSrcSize)); - - for (int i = 0; i < 3; ++i) - { - nppiDecodeHuffmanSpecFreeHost_JPEG(apHuffmanDCTable[i]); - nppiDecodeHuffmanSpecFreeHost_JPEG(apHuffmanACTable[i]); - } - } - - nMarker = nextMarker(pJpegData, nPos, nInputLength); - } - - // Copy DCT coefficients and Quantization Tables from host to device - for (int i = 0; i < 4; ++i) - { - NPP_CHECK_CUDA(cudaMemcpyAsync(pdQuantizationTables + i * 64, aQuantizationTables[i].aTable, 64, cudaMemcpyHostToDevice)); - } - - for (int i = 0; i < 3; ++i) - { - - cout << aDCTStep[i] << " " << aSrcSize[i].height << " " << aDCTStep[i] * aSrcSize[i].height / 8 << endl; - NPP_CHECK_CUDA(cudaMemcpyAsync(apdDCT[i], aphDCT[i], aDCTStep[i] * aSrcSize[i].height / 8, cudaMemcpyHostToDevice)); - } - - /* Inverse DCT - úʵ˽jpegͼ YUV*/ - for (int i = 0; i < 3; ++i) - { - NPP_CHECK_NPP(nppiDCTQuantInv8x8LS_JPEG_16s8u_C1R_NEW(apdDCT[i], aDCTStep[i], - apSrcImage[i], aSrcImageStep[i], - pdQuantizationTables + oFrameHeader.aQuantizationTableSelector[i] * 64, - aSrcSize[i], - pDCTState)); - } - - //Npp16s -} - -int EncodeJPEG(char* SaveFileName) -{ - - - /*Npp8u *apSrcImageTest[3]; - - - for (int i = 0; i < 3; i++) - { - size_t nPitch; - NPP_CHECK_CUDA(cudaMalloc(&apSrcImageTest[i], 1920 * 1080 * sizeof(Npp8u))); - NPP_CHECK_CUDA(cudaMemcpy(apSrcImageTest[i], imgData[i], 1920 * 1080 * sizeof(Npp8u), cudaMemcpyDeviceToDevice)); - } -*/ - for (int i = 0; i < 3; i++) - { - NPP_CHECK_NPP(nppiDCTQuantFwd8x8LS_JPEG_8u16s_C1R_NEW(apSrcImage[i], aSrcImageStep[i], - apdDCT_My[i], aDCTStep[i], - pdQuantizationTables + oFrameHeader.aQuantizationTableSelector[i] * 64, - aSrcSize[i], - pDCTState - )); - } - - //Ĵǹͼ - /*************************** - * - * Processing - * - ***************************/ - - // Compute channel sizes as stored in the output JPEG (8x8 blocks & MCU block layout) - /*************** 1. ͼĴС********************/ - NppiSize oDstImageSize; - float frameWidth = floor((float)oFrameHeader.nWidth); //ԭͼС * - float frameHeight = floor((float)oFrameHeader.nHeight); - - oDstImageSize.width = (int)max(1.0f, frameWidth); - oDstImageSize.height = (int)max(1.0f, frameHeight); - - //cout << "Output Size: " << oDstImageSize.width << "x" << oDstImageSize.height << "x" << static_cast(oFrameHeader.nComponents) << endl; - - - /*************** 2. aDstSizeĴС********************/ - for (int i = 0; i < oFrameHeader.nComponents; ++i) //3 - { - NppiSize oBlocks; - NppiSize oBlocksPerMCU = { oFrameHeader.aSamplingFactors[i] & 0x0f, oFrameHeader.aSamplingFactors[i] >> 4 }; - - oBlocks.width = (int)ceil((oDstImageSize.width + 7) / 8 * - static_cast(oBlocksPerMCU.width) / nMCUBlocksH); - oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width; - - oBlocks.height = (int)ceil((oDstImageSize.height + 7) / 8 * - static_cast(oBlocksPerMCU.height) / nMCUBlocksV); - oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height; - - aDstSize[i].width = oBlocks.width * 8; - aDstSize[i].height = oBlocks.height * 8; - - //cout << "***********" << aDstSize[i].width << " " << aDstSize[i].height << "***********" << endl; - ////Ӱ챣 Dzȷܲɾ - //Allocate Memory - size_t nPitch; - NPP_CHECK_CUDA(cudaMallocPitch(&apDstImage[i], &nPitch, aDstSize[i].width, aDstSize[i].height)); - aDstImageStep[i] = static_cast(nPitch); - } - - /*************** 3. Huffman Encoding********************/ - // Huffman Encoding - Npp8u *pdScan; - Npp32s nScanLength; - NPP_CHECK_CUDA(cudaMalloc(&pdScan, 4 << 20)); - - Npp8u *pJpegEncoderTemp; - Npp32s nTempSize; - NPP_CHECK_NPP(nppiEncodeHuffmanGetSize(aSrcSize[0], 3, &nTempSize)); - NPP_CHECK_CUDA(cudaMalloc(&pJpegEncoderTemp, nTempSize)); - - NppiEncodeHuffmanSpec *apHuffmanDCTable[3]; - NppiEncodeHuffmanSpec *apHuffmanACTable[3]; - - for (int i = 0; i < 3; ++i) - { - nppiEncodeHuffmanSpecInitAlloc_JPEG(pHuffmanDCTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, nppiDCTable, &apHuffmanDCTable[i]); - nppiEncodeHuffmanSpecInitAlloc_JPEG(pHuffmanACTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f)].aCodes, nppiACTable, &apHuffmanACTable[i]); - } - - //Npp16s *apdDCT1[3] = { 0, 0, 0 }; - //Huffman Encode - //apdDCT = (Npp16s*)(img); - NPP_CHECK_NPP(nppiEncodeHuffmanScan_JPEG_8u16s_P3R(apdDCT_My, aDCTStep, - 0, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, - pdScan, &nScanLength, - apHuffmanDCTable, //֮ǰ ֮ͷ - apHuffmanACTable, //֮ǰ ֮ͷ - aDstSize, - pJpegEncoderTemp)); - - for (int i = 0; i < 3; ++i) - { - nppiEncodeHuffmanSpecFree_JPEG(apHuffmanDCTable[i]); - nppiEncodeHuffmanSpecFree_JPEG(apHuffmanACTable[i]); - } - - //Write JPEG - unsigned char *pDstJpeg = new unsigned char[4 << 20]{}; - unsigned char *pDstOutput = pDstJpeg; - - oFrameHeader.nWidth = oDstImageSize.width; - oFrameHeader.nHeight = oDstImageSize.height; - - writeMarker(0x0D8, pDstOutput); - writeJFIFTag(pDstOutput); - writeQuantizationTable(aQuantizationTables[0], pDstOutput); - writeQuantizationTable(aQuantizationTables[1], pDstOutput); - writeFrameHeader(oFrameHeader, pDstOutput); - writeHuffmanTable(pHuffmanDCTables[0], pDstOutput); - writeHuffmanTable(pHuffmanACTables[0], pDstOutput); - writeHuffmanTable(pHuffmanDCTables[1], pDstOutput); - writeHuffmanTable(pHuffmanACTables[1], pDstOutput); - writeScanHeader(oScanHeader, pDstOutput); - NPP_CHECK_CUDA(cudaMemcpy(pDstOutput, pdScan, nScanLength, cudaMemcpyDeviceToHost)); - pDstOutput += nScanLength; - writeMarker(0x0D9, pDstOutput); - - { - // Write result to file. - std::ofstream outputFile(SaveFileName, ios::out | ios::binary); - outputFile.write(reinterpret_cast(pDstJpeg), static_cast(pDstOutput - pDstJpeg)); - } - - // Cleanup - cudaFree(pJpegEncoderTemp); - cudaFree(pdScan); - //delete[] pJpegData; - delete[] pDstJpeg; -/* - - cudaFree(pdQuantizationTables); - - - nppiDCTFree(pDCTState); - */ - for (int i = 0; i < 3; ++i) - { - /* cudaFree(apdDCT[i]); - cudaFree(apdDCT_My[i]); - cudaFreeHost(aphDCT[i]); - cudaFree(apSrcImage[i]);*/ - cudaFree(apDstImage[i]); - } - - return EXIT_SUCCESS; -} - - - -// -//int main(int argc, char **argv) -//{ -// // Min spec is SM 2.0 devices -// if (printfNPPinfo(argc, argv, 2, 0) == false) -// { -// cerr << "jpegNPP requires a GPU with Compute Capability 2.0 or higher" << endl; -// return EXIT_SUCCESS; -// } -// -// const char *szInputFile; -// const char *szOutputFile; -// //float nScaleFactor; -// -// if ((argc == 1) || checkCmdLineFlag(argc, (const char **)argv, "help")) -// { -// printHelp(); -// } -// -// if (checkCmdLineFlag(argc, (const char **)argv, "input")) -// { -// getCmdLineArgumentString(argc, (const char **)argv, "input", (char **)&szInputFile); -// } -// else -// { -// szInputFile = sdkFindFilePath("18.jpg", argv[0]); -// } -// -// cout << "Source File: " << szInputFile << endl; -// -// if (checkCmdLineFlag(argc, (const char **)argv, "output")) -// { -// getCmdLineArgumentString(argc, (const char **)argv, "output", (char **)&szOutputFile); -// } -// else -// { -// szOutputFile = "scaled.jpg"; -// } -// -// cout << "Output File mm: " << szOutputFile << endl; -// -// /*if (checkCmdLineFlag(argc, (const char **)argv, "scale")) -// { -// nScaleFactor = max(0.0f, min(getCmdLineArgumentFloat(argc, (const char **)argv, "scale"), 1.0f)); -// } -// else -// { -// nScaleFactor = 1.0f; -// } -// -// cout << "Scale Factor: " << nScaleFactor << endl;*/ -// -// NppiDCTState *pDCTState; -// NPP_CHECK_NPP(nppiDCTInitAlloc(&pDCTState)); -// -// unsigned char *pJpegData = 0; -// int nInputLength = 0; -// -// // Load Jpeg -// loadJpeg(szInputFile, pJpegData, nInputLength); -// -// if (pJpegData == 0) -// { -// cerr << "Input File Error: " << szInputFile << endl; -// return EXIT_FAILURE; -// } -// -// /*************************** -// * -// * Input -// * -// ***************************/ -// -// -// // Check if this is a valid JPEG file -// int nPos = 0; -// int nMarker = nextMarker(pJpegData, nPos, nInputLength); -// -// if (nMarker != 0x0D8) -// { -// cerr << "Invalid Jpeg Image" << endl; -// return EXIT_FAILURE; -// } -// -// nMarker = nextMarker(pJpegData, nPos, nInputLength); -// -// // Parsing and Huffman Decoding (on host) -// FrameHeader oFrameHeader; -// QuantizationTable aQuantizationTables[4]; -// Npp8u *pdQuantizationTables; -// cudaMalloc(&pdQuantizationTables, 64 * 4); -// -// HuffmanTable aHuffmanTables[4]; -// HuffmanTable *pHuffmanDCTables = aHuffmanTables; -// HuffmanTable *pHuffmanACTables = &aHuffmanTables[2]; -// ScanHeader oScanHeader; -// memset(&oFrameHeader, 0, sizeof(FrameHeader)); -// memset(aQuantizationTables, 0, 4 * sizeof(QuantizationTable)); -// memset(aHuffmanTables, 0, 4 * sizeof(HuffmanTable)); -// int nMCUBlocksH = 0; -// int nMCUBlocksV = 0; -// -// int nRestartInterval = -1; -// -// NppiSize aSrcSize[3]; -// Npp16s *aphDCT[3] = { 0, 0, 0 }; -// Npp16s *apdDCT[3] = { 0, 0, 0 }; -// Npp32s aDCTStep[3]; -// -// Npp8u *apSrcImage[3] = { 0, 0, 0 }; -// Npp32s aSrcImageStep[3]; -// -// Npp8u *apDstImage[3] = { 0, 0, 0 }; -// Npp32s aDstImageStep[3]; -// NppiSize aDstSize[3]; -// -// while (nMarker != -1) -// { -// if (nMarker == 0x0D8) -// { -// // Embedded Thumbnail, skip it -// int nNextMarker = nextMarker(pJpegData, nPos, nInputLength); -// -// while (nNextMarker != -1 && nNextMarker != 0x0D9) -// { -// nNextMarker = nextMarker(pJpegData, nPos, nInputLength); -// } -// } -// -// if (nMarker == 0x0DD) -// { -// readRestartInterval(pJpegData + nPos, nRestartInterval); -// } -// -// if ((nMarker == 0x0C0) | (nMarker == 0x0C2)) -// { -// //Assert Baseline for this Sample -// //Note: NPP does support progressive jpegs for both encode and decode -// if (nMarker != 0x0C0) -// { -// cerr << "The sample does only support baseline JPEG images" << endl; -// return EXIT_SUCCESS; -// } -// -// // Baseline or Progressive Frame Header -// readFrameHeader(pJpegData + nPos, oFrameHeader); -// cout << "Image Size: " << oFrameHeader.nWidth << "x" << oFrameHeader.nHeight << "x" << static_cast(oFrameHeader.nComponents) << endl; -// -// //Assert 3-Channel Image for this Sample -// if (oFrameHeader.nComponents != 3) -// { -// cerr << "The sample does only support color JPEG images" << endl; -// return EXIT_SUCCESS; -// } -// -// // Compute channel sizes as stored in the JPEG (8x8 blocks & MCU block layout) -// for (int i = 0; i < oFrameHeader.nComponents; ++i) -// { -// nMCUBlocksV = max(nMCUBlocksV, oFrameHeader.aSamplingFactors[i] & 0x0f); -// nMCUBlocksH = max(nMCUBlocksH, oFrameHeader.aSamplingFactors[i] >> 4); -// } -// -// for (int i = 0; i < oFrameHeader.nComponents; ++i) -// { -// NppiSize oBlocks; -// NppiSize oBlocksPerMCU = { oFrameHeader.aSamplingFactors[i] >> 4, oFrameHeader.aSamplingFactors[i] & 0x0f }; -// -// oBlocks.width = (int)ceil((oFrameHeader.nWidth + 7) / 8 * -// static_cast(oBlocksPerMCU.width) / nMCUBlocksH); -// oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width; -// -// oBlocks.height = (int)ceil((oFrameHeader.nHeight + 7) / 8 * -// static_cast(oBlocksPerMCU.height) / nMCUBlocksV); -// oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height; -// -// aSrcSize[i].width = oBlocks.width * 8; -// aSrcSize[i].height = oBlocks.height * 8; -// -// // Allocate Memory -// size_t nPitch; -// NPP_CHECK_CUDA(cudaMallocPitch(&apdDCT[i], &nPitch, oBlocks.width * 64 * sizeof(Npp16s), oBlocks.height)); -// aDCTStep[i] = static_cast(nPitch); -// -// NPP_CHECK_CUDA(cudaMallocPitch(&apSrcImage[i], &nPitch, aSrcSize[i].width, aSrcSize[i].height)); -// aSrcImageStep[i] = static_cast(nPitch); -// -// NPP_CHECK_CUDA(cudaHostAlloc(&aphDCT[i], aDCTStep[i] * oBlocks.height, cudaHostAllocDefault)); -// } -// } -// -// if (nMarker == 0x0DB) -// { -// // Quantization Tables -// readQuantizationTables(pJpegData + nPos, aQuantizationTables); -// } -// -// if (nMarker == 0x0C4) -// { -// // Huffman Tables -// readHuffmanTables(pJpegData + nPos, aHuffmanTables); -// } -// -// if (nMarker == 0x0DA) -// { -// // Scan -// readScanHeader(pJpegData + nPos, oScanHeader); -// nPos += 6 + oScanHeader.nComponents * 2; -// -// int nAfterNextMarkerPos = nPos; -// int nAfterScanMarker = nextMarker(pJpegData, nAfterNextMarkerPos, nInputLength); -// -// if (nRestartInterval > 0) -// { -// while (nAfterScanMarker >= 0x0D0 && nAfterScanMarker <= 0x0D7) -// { -// // This is a restart marker, go on -// nAfterScanMarker = nextMarker(pJpegData, nAfterNextMarkerPos, nInputLength); -// } -// } -// -// NppiDecodeHuffmanSpec *apHuffmanDCTable[3]; -// NppiDecodeHuffmanSpec *apHuffmanACTable[3]; -// -// for (int i = 0; i < 3; ++i) -// { -// nppiDecodeHuffmanSpecInitAllocHost_JPEG(pHuffmanDCTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, nppiDCTable, &apHuffmanDCTable[i]); -// nppiDecodeHuffmanSpecInitAllocHost_JPEG(pHuffmanACTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f)].aCodes, nppiACTable, &apHuffmanACTable[i]); -// } -// -// NPP_CHECK_NPP(nppiDecodeHuffmanScanHost_JPEG_8u16s_P3R(pJpegData + nPos, nAfterNextMarkerPos - nPos - 2, -// nRestartInterval, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, -// aphDCT, aDCTStep, -// apHuffmanDCTable, -// apHuffmanACTable, -// aSrcSize)); -// -// for (int i = 0; i < 3; ++i) -// { -// nppiDecodeHuffmanSpecFreeHost_JPEG(apHuffmanDCTable[i]); -// nppiDecodeHuffmanSpecFreeHost_JPEG(apHuffmanACTable[i]); -// } -// } -// -// nMarker = nextMarker(pJpegData, nPos, nInputLength); -// } -// -// // Copy DCT coefficients and Quantization Tables from host to device -// for (int i = 0; i < 4; ++i) -// { -// NPP_CHECK_CUDA(cudaMemcpyAsync(pdQuantizationTables + i * 64, aQuantizationTables[i].aTable, 64, cudaMemcpyHostToDevice)); -// } -// -// for (int i = 0; i < 3; ++i) -// { -// NPP_CHECK_CUDA(cudaMemcpyAsync(apdDCT[i], aphDCT[i], aDCTStep[i] * aSrcSize[i].height / 8, cudaMemcpyHostToDevice)); -// } -// -// // Inverse DCT -// //úʵ˽jpegͼ YUV -// //for (int i = 0; i < 3; ++i) -// //{ -// // NPP_CHECK_NPP(nppiDCTQuantInv8x8LS_JPEG_16s8u_C1R_NEW(apdDCT[i], aDCTStep[i], -// // apSrcImage[i], aSrcImageStep[i], -// // pdQuantizationTables + oFrameHeader.aQuantizationTableSelector[i] * 64, -// // aSrcSize[i], -// // pDCTState)); -// //} -// -// //Ĵǹͼ -// /*************************** -// * -// * Processing -// * -// ***************************/ -// -// // Compute channel sizes as stored in the output JPEG (8x8 blocks & MCU block layout) -// /*************** 1. ͼĴС********************/ -// NppiSize oDstImageSize; -// float frameWidth = floor((float)oFrameHeader.nWidth); //ԭͼС * -// float frameHeight = floor((float)oFrameHeader.nHeight); -// -// oDstImageSize.width = (int)max(1.0f, frameWidth); -// oDstImageSize.height = (int)max(1.0f, frameHeight); -// -// cout << "Output Size: " << oDstImageSize.width << "x" << oDstImageSize.height << "x" << static_cast(oFrameHeader.nComponents) << endl; -// -// -// /*************** 2. aDstSizeĴС********************/ -// for (int i = 0; i < oFrameHeader.nComponents; ++i) //3 -// { -// NppiSize oBlocks; -// NppiSize oBlocksPerMCU = { oFrameHeader.aSamplingFactors[i] & 0x0f, oFrameHeader.aSamplingFactors[i] >> 4 }; -// -// oBlocks.width = (int)ceil((oDstImageSize.width + 7) / 8 * -// static_cast(oBlocksPerMCU.width) / nMCUBlocksH); -// oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width; -// -// oBlocks.height = (int)ceil((oDstImageSize.height + 7) / 8 * -// static_cast(oBlocksPerMCU.height) / nMCUBlocksV); -// oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height; -// -// aDstSize[i].width = oBlocks.width * 8; -// aDstSize[i].height = oBlocks.height * 8; -// -// cout << "***********" << aDstSize[i].width << " " << aDstSize[i].height << "***********" << endl; -// ////Ӱ챣 Dzȷܲɾ -// //Allocate Memory -// /*size_t nPitch; -// NPP_CHECK_CUDA(cudaMallocPitch(&apDstImage[i], &nPitch, aDstSize[i].width, aDstSize[i].height)); -// aDstImageStep[i] = static_cast(nPitch);*/ -// } -// -// /*************** 3. Huffman Encoding********************/ -// // Huffman Encoding -// Npp8u *pdScan; -// Npp32s nScanLength; -// NPP_CHECK_CUDA(cudaMalloc(&pdScan, 4 << 20)); -// -// Npp8u *pJpegEncoderTemp; -// Npp32s nTempSize; -// NPP_CHECK_NPP(nppiEncodeHuffmanGetSize(aSrcSize[0], 3, &nTempSize)); -// NPP_CHECK_CUDA(cudaMalloc(&pJpegEncoderTemp, nTempSize)); -// -// NppiEncodeHuffmanSpec *apHuffmanDCTable[3]; -// NppiEncodeHuffmanSpec *apHuffmanACTable[3]; -// -// for (int i = 0; i < 3; ++i) -// { -// nppiEncodeHuffmanSpecInitAlloc_JPEG(pHuffmanDCTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, nppiDCTable, &apHuffmanDCTable[i]); -// nppiEncodeHuffmanSpecInitAlloc_JPEG(pHuffmanACTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f)].aCodes, nppiACTable, &apHuffmanACTable[i]); -// } -// -// //Npp16s *apdDCT1[3] = { 0, 0, 0 }; -// //Huffman Encode -// NPP_CHECK_NPP(nppiEncodeHuffmanScan_JPEG_8u16s_P3R(apdDCT, aDCTStep, -// 0, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, -// pdScan, &nScanLength, -// apHuffmanDCTable, //֮ǰ ֮ͷ -// apHuffmanACTable, //֮ǰ ֮ͷ -// aDstSize, -// pJpegEncoderTemp)); -// -// for (int i = 0; i < 3; ++i) -// { -// nppiEncodeHuffmanSpecFree_JPEG(apHuffmanDCTable[i]); -// nppiEncodeHuffmanSpecFree_JPEG(apHuffmanACTable[i]); -// } -// -// //Write JPEG -// unsigned char *pDstJpeg = new unsigned char[4 << 20]; -// unsigned char *pDstOutput = pDstJpeg; -// -// oFrameHeader.nWidth = oDstImageSize.width; -// oFrameHeader.nHeight = oDstImageSize.height; -// -// writeMarker(0x0D8, pDstOutput); -// writeJFIFTag(pDstOutput); -// writeQuantizationTable(aQuantizationTables[0], pDstOutput); -// writeQuantizationTable(aQuantizationTables[1], pDstOutput); -// writeFrameHeader(oFrameHeader, pDstOutput); -// writeHuffmanTable(pHuffmanDCTables[0], pDstOutput); -// writeHuffmanTable(pHuffmanACTables[0], pDstOutput); -// writeHuffmanTable(pHuffmanDCTables[1], pDstOutput); -// writeHuffmanTable(pHuffmanACTables[1], pDstOutput); -// writeScanHeader(oScanHeader, pDstOutput); -// NPP_CHECK_CUDA(cudaMemcpy(pDstOutput, pdScan, nScanLength, cudaMemcpyDeviceToHost)); -// pDstOutput += nScanLength; -// writeMarker(0x0D9, pDstOutput); -// -// { -// // Write result to file. -// std::ofstream outputFile(szOutputFile, ios::out | ios::binary); -// outputFile.write(reinterpret_cast(pDstJpeg), static_cast(pDstOutput - pDstJpeg)); -// } -// -// // Cleanup -// delete[] pJpegData; -// delete[] pDstJpeg; -// -// cudaFree(pJpegEncoderTemp); -// cudaFree(pdQuantizationTables); -// cudaFree(pdScan); -// -// nppiDCTFree(pDCTState); -// -// for (int i = 0; i < 3; ++i) -// { -// cudaFree(apdDCT[i]); -// cudaFreeHost(aphDCT[i]); -// cudaFree(apSrcImage[i]); -// cudaFree(apDstImage[i]); -// } -// -// return EXIT_SUCCESS; -//} diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/putText.cpp-- b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/putText.cpp-- deleted file mode 100644 index 5a19850..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/putText.cpp-- +++ /dev/null @@ -1,137 +0,0 @@ -#include "putText.h" - -void GetStringSize(HDC hDC, const char* str, int* w, int* h) -{ - SIZE size; - GetTextExtentPoint32A(hDC, str, strlen(str), &size); - if (w != 0) *w = size.cx; - if (h != 0) *h = size.cy; -} - -void putTextZH(Mat &dst, const char* str, Point org, Scalar color, int fontSize, const char* fn, bool italic, bool underline) -{ - CV_Assert(dst.data != 0 && (dst.channels() == 1 || dst.channels() == 3)); - - int x, y, r, b; - if (org.x > dst.cols || org.y > dst.rows) return; - x = org.x < 0 ? -org.x : 0; - y = org.y < 0 ? -org.y : 0; - - LOGFONTA lf; - lf.lfHeight = -fontSize; - lf.lfWidth = 0; - lf.lfEscapement = 0; - lf.lfOrientation = 0; - lf.lfWeight = 5; - lf.lfItalic = italic; //б - lf.lfUnderline = underline; //» - lf.lfStrikeOut = 0; - lf.lfCharSet = DEFAULT_CHARSET; - lf.lfOutPrecision = 0; - lf.lfClipPrecision = 0; - lf.lfQuality = PROOF_QUALITY; - lf.lfPitchAndFamily = 0; - strcpy_s(lf.lfFaceName, fn); - - HFONT hf = CreateFontIndirectA(&lf); - HDC hDC = CreateCompatibleDC(0); - HFONT hOldFont = (HFONT)SelectObject(hDC, hf); - - int strBaseW = 0, strBaseH = 0; - int singleRow = 0; - char buf[1 << 12]; - strcpy_s(buf, str); - char *bufT[1 << 12]; // ڷַָʣַܻᳬ - // - { - int nnh = 0; - int cw, ch; - - const char* ln = strtok_s(buf, "\n", bufT); - while (ln != 0) - { - GetStringSize(hDC, ln, &cw, &ch); - strBaseW = max(strBaseW, cw); - strBaseH = max(strBaseH, ch); - - ln = strtok_s(0, "\n", bufT); - nnh++; - } - singleRow = strBaseH; - strBaseH *= nnh; - } - - if (org.x + strBaseW < 0 || org.y + strBaseH < 0) - { - SelectObject(hDC, hOldFont); - DeleteObject(hf); - DeleteObject(hDC); - return; - } - - r = org.x + strBaseW > dst.cols ? dst.cols - org.x - 1 : strBaseW - 1; - b = org.y + strBaseH > dst.rows ? dst.rows - org.y - 1 : strBaseH - 1; - org.x = org.x < 0 ? 0 : org.x; - org.y = org.y < 0 ? 0 : org.y; - - BITMAPINFO bmp = { 0 }; - BITMAPINFOHEADER& bih = bmp.bmiHeader; - int strDrawLineStep = strBaseW * 3 % 4 == 0 ? strBaseW * 3 : (strBaseW * 3 + 4 - ((strBaseW * 3) % 4)); - - bih.biSize = sizeof(BITMAPINFOHEADER); - bih.biWidth = strBaseW; - bih.biHeight = strBaseH; - bih.biPlanes = 1; - bih.biBitCount = 24; - bih.biCompression = BI_RGB; - bih.biSizeImage = strBaseH * strDrawLineStep; - bih.biClrUsed = 0; - bih.biClrImportant = 0; - - void* pDibData = 0; - HBITMAP hBmp = CreateDIBSection(hDC, &bmp, DIB_RGB_COLORS, &pDibData, 0, 0); - - CV_Assert(pDibData != 0); - HBITMAP hOldBmp = (HBITMAP)SelectObject(hDC, hBmp); - - //color.val[2], color.val[1], color.val[0] - SetTextColor(hDC, RGB(255, 255, 255)); - SetBkColor(hDC, 0); - //SetStretchBltMode(hDC, COLORONCOLOR); - - strcpy_s(buf, str); - const char* ln = strtok_s(buf, "\n", bufT); - int outTextY = 0; - while (ln != 0) - { - TextOutA(hDC, 0, outTextY, ln, strlen(ln)); - outTextY += singleRow; - ln = strtok_s(0, "\n", bufT); - } - uchar* dstData = (uchar*)dst.data; - int dstStep = dst.step / sizeof(dstData[0]); - unsigned char* pImg = (unsigned char*)dst.data + org.x * dst.channels() + org.y * dstStep; - unsigned char* pStr = (unsigned char*)pDibData + x * 3; - for (int tty = y; tty <= b; ++tty) - { - unsigned char* subImg = pImg + (tty - y) * dstStep; - unsigned char* subStr = pStr + (strBaseH - tty - 1) * strDrawLineStep; - for (int ttx = x; ttx <= r; ++ttx) - { - for (int n = 0; n < dst.channels(); ++n){ - double vtxt = subStr[n] / 255.0; - int cvv = vtxt * color.val[n] + (1 - vtxt) * subImg[n]; - subImg[n] = cvv > 255 ? 255 : (cvv < 0 ? 0 : cvv); - } - - subStr += 3; - subImg += dst.channels(); - } - } - - SelectObject(hDC, hOldBmp); - SelectObject(hDC, hOldFont); - DeleteObject(hf); - DeleteObject(hBmp); - DeleteDC(hDC); -} \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/putText.h- b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/putText.h- deleted file mode 100644 index 863ad6c..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/putText.h- +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PUTTEXT_H_ -#define PUTTEXT_H_ - -#include -#include -#include - -using namespace cv; - -void GetStringSize(HDC hDC, const char* str, int* w, int* h); -void putTextZH(Mat &dst, const char* str, Point org, Scalar color, int fontSize, - const char *fn = "Arial", bool italic = false, bool underline = false); - -#endif // PUTTEXT_H_ \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/script.mri b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/script.mri deleted file mode 100644 index 156db32..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/script.mri +++ /dev/null @@ -1,5 +0,0 @@ -create libVPT.a -addlib libVPT.a -addlib /home/dyq/0/nlpr/20170707_ProductView/nlpr-vpt-platform/../../20170730_USTools-SSD/0git/v4.0.0/linux/utools/libustools.a -save -end diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/FaceDetModule.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/FaceDetModule.cpp index 0d73b33..4f67bb3 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/FaceDetModule.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/FaceDetModule.cpp @@ -35,40 +35,29 @@ int face_det_module::face_det_module_init(int gpuid, char* auth_license) { m_face_det_handle = nullptr; - //��������ʼ�� - fd_param fd_param_; - fd_param_.thresld = 0.7; - fd_param_.gpuid = gpuid; - fd_param_.mode = DEVICE_GPU; - fd_param_.log = SY_CONFIG_OPEN; - fd_param_.facial_fea_point_config = SY_CONFIG_OPEN; - fd_param_.pose_config = SY_CONFIG_OPEN; - fd_param_.quality_config = SY_CONFIG_OPEN; - fd_param_.score_config = SY_CONFIG_OPEN; - fd_param_.max_result_count = 100; - fd_param_.max_batch_size_detect = 10; - fd_param_.max_batch_size_ldmk = 10; - fd_param_.max_batch_size_pose = 10; - fd_param_.max_batch_size_score = 10; - fd_param_.max_batch_size_blurglass = 10; - fd_param_.max_batch_size_occlusion = 10; - fd_param_.serialize_file = "./serialize_file/FD"; - fd_param_.auth_license = "sy_tsl_aiplatform_sdk_2021"; - - // fd_param param; - // param.thresld = 0.6; - // param.gpuid = gpuid; - // param.mode = DEVICE_GPU; - // param.log = SY_CONFIG_OPEN; - // param.facial_fea_point_config = SY_CONFIG_OPEN; //�Ƿ������ؼ����� - // param.pose_config = SY_CONFIG_OPEN; //�Ƿ�������̬�� - // param.quality_config = SY_CONFIG_OPEN; //�Ƿ������������ - // param.score_config = SY_CONFIG_OPEN; //�Ƿ������������Ŷ� //SY_CONFIG_OPEN SY_CONFIG_CLOSE - // param.max_result_count = 100; - // param.auth_license = "sy_tsl_aiplatform_sdk_2021"; - - // if (SUCCESS != fd_init(&m_face_det_handle, fd_param_, "")) - if (SUCCESS != fd_init(&m_face_det_handle, fd_param_)) // 220512 + fd_param param; + param.thresld = 0.6; + param.gpuid = 0; + param.mode = DEVICE_GPU; + param.log = SY_CONFIG_OPEN; + param.facial_fea_point_config = SY_CONFIG_OPEN; //�Ƿ������ؼ����� + param.pose_config = SY_CONFIG_OPEN; //�Ƿ�������̬�� + param.quality_config = SY_CONFIG_OPEN; //�Ƿ������������ + param.score_config = SY_CONFIG_OPEN; //�Ƿ������������Ŷ� //SY_CONFIG_OPEN SY_CONFIG_CLOSE + param.max_result_count = 100; + param.auth_license = "sy_va_sub_sdk_2023"; + // param.max_batch_size_detect = 10; + // param.max_batch_size_ldmk = 10; + // param.max_batch_size_pose = 10; + // param.max_batch_size_score = 10; + // param.max_batch_size_blurglass = 10; + // //param.max_batch_size_hat = 4; + // param.max_batch_size_occlusion = 10; + param.serialize_file = "./serialize_file/FD"; + + + int flagFD = fd_init(&m_face_det_handle, param); + if(flagFD != 0) { printf("fd_init failed\n"); return FAILED; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp index cfd1090..53643ce 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp @@ -4,42 +4,44 @@ #include "opencv2/opencv.hpp" #include "opencv2/highgui/highgui.hpp" -//string up[12] = { "T", "//", "", "", "ë", "Ƥ/п", "޷", "/", "", "ȹ", "", "" }; -//string up_color[12] = { "", "", "", "", "", "", "", "", "", "", "ɫ", "" }; -//string down[6] = { "", "̿", "ȹ", "ȹ", "ȹ", "" }; -//string down_color[12] = { "", "", "", "", "", "", "", "", "", "", "ɫ", "" }; -//string bao[5] = { "ް", "", "˫", "", "Ǯ" }; -//string bag_color[12] = { "", "", "", "", "", "", "", "", "", "", "ɫ", "" }; -//string head[6] = { "", "̷", "ͷ", "ñ", "ͷ", "" }; -//string clothing_text[5] = { "ɫ", "黨", "", "", "" }; -//string sex[3] = { "", "Ů", "" }; -//string figure[3] = { "", "", "" }; -//string nationality[5] = { "", "ά", "", "", "" }; -//string age[6] = { "׶", "ͯ", "", "", "", "" }; -//string eye[4] = { "۾", "۾", "ī", "" }; -//string mouth[3] = { "", "", "" }; -//string weibo[3] = { "Χ", "ͨΧ", "ͷΧ" }; +#include "../../FFNvDecoder/logger.hpp" + +//string up[12] = { "T恤", "马甲/吊带/背心", "衬衫", "西服", "毛衣", "皮衣/夹克", "羽绒服", "大衣/风衣", "外套", "连衣裙", "无上衣", "其他" }; +//string up_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" }; +//string down[6] = { "长裤", "短裤", "长裙", "短裙", "连衣裙", "其他" }; +//string down_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" }; +//string bao[5] = { "无包", "单肩包", "双肩包", "其他", "钱包" }; +//string bag_color[12] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他" }; +//string head[6] = { "长发", "短发", "光头", "帽子", "头盔", "其他" }; +//string clothing_text[5] = { "纯色", "碎花", "条纹", "格子", "其他" }; +//string sex[3] = { "男", "女", "不明" }; +//string figure[3] = { "胖", "瘦", "中" }; +//string nationality[5] = { "汉族", "维族", "黑人", "白人", "其他" }; +//string age[6] = { "幼儿", "儿童", "青年", "中年", "老年", "不明" }; +//string eye[4] = { "正常眼睛", "眼镜", "墨镜", "其他" }; +//string mouth[3] = { "正常嘴", "戴口罩", "其他" }; +//string weibo[3] = { "无围巾", "普通围巾", "包头围巾" }; // -//string carColor[13] = { "", "", "", "", "", "", "", "", "", "", "ɫ", "", "" }; -//string orient[3] = { "", "", "" }; -//string drivenum[4] = { "0", "1", "2", "" }; -//string dasan[2] = { "", "" }; -//string take[2] = { "", "Ʒ" }; - -//static std::string hcp_head[] = { "", "̷", "ͷ", "" }; -//static std::string hcp_eye[] = { "δ۾", "۾" }; -//static std::string hcp_mouth[] = { "δ", "" }; -//static std::string hcp_weibo[] = { "δΧ", "Χ" }; -//static std::string hcp_up[] = { "T/", "", "ë", "", "ȹ", "" }; -//static std::string hcp_up_color[] = { "", "", "", "", "", "", "", "ɫ", "" }; -//static std::string hcp_clothing_text[] = { "ɫ", "黨", "Ƹ", "" }; -//static std::string hcp_bao[] = { "ް", "" }; -//static std::string hcp_sex[] = { "", "Ů", "" }; -//static std::string hcp_age[] = { "С", "", "" }; -//static std::string hcp_carColor[] = { "", "", "", "" }; -//static std::string hcp_orient[] = { "", "", "" }; -//static std::string hcp_dasan[] = { "", "" }; -//static std::string hcp_take[] = { "", "" }; +//string carColor[13] = { "黑", "白", "红", "黄", "蓝", "绿", "紫", "棕", "灰", "橙", "多色", "其他", "银" }; +//string orient[3] = { "正面", "背面", "侧面" }; +//string drivenum[4] = { "0人", "1人", "2人", "更多人" }; +//string dasan[2] = { "无", "有" }; +//string take[2] = { "无", "物品" }; + +//static std::string hcp_head[] = { "长发", "短发", "头盔", "其他" }; +//static std::string hcp_eye[] = { "未戴眼镜", "戴眼镜" }; +//static std::string hcp_mouth[] = { "未戴口罩", "戴口罩" }; +//static std::string hcp_weibo[] = { "未带围巾", "带围巾" }; +//static std::string hcp_up[] = { "T恤/背心", "衬衫", "毛衣", "外套", "连衣裙", "其他" }; +//static std::string hcp_up_color[] = { "黑", "白", "灰", "红", "蓝", "黄", "绿", "多色", "不明" }; +//static std::string hcp_clothing_text[] = { "纯色", "碎花", "条纹格子", "其他" }; +//static std::string hcp_bao[] = { "无包", "背包" }; +//static std::string hcp_sex[] = { "男", "女", "不明" }; +//static std::string hcp_age[] = { "小孩", "成人", "不明" }; +//static std::string hcp_carColor[] = { "黑", "白", "红", "其他" }; +//static std::string hcp_orient[] = { "正面", "背面", "侧面" }; +//static std::string hcp_dasan[] = { "无", "有" }; +//static std::string hcp_take[] = { "无", "有" }; const int FIR_INDEX_SIZE = 14; const int SEC_INDEX_SIZE[FIR_INDEX_SIZE] = {4,2,2,2,6,9,4,2,3,3,4,3,2,2 }; @@ -64,15 +66,42 @@ int HumanCarParsing_Init(void *&handle, int gpuid, char* auth_license) #include int HumanCarParsing_Process(void * handle, sy_img * batch_img, int batch_size, hcp_analysis_result *&result) { - //ctools_result *result=NULL; + // vector vec_batch_img(batch_size); + // for (int i = 0; i < batch_size; i++) + // { + // if (batch_img[i].data_ == NULL) { + // cout << i << " data null" << endl; + // return -1; + // } + // int data_size = batch_img[i].c_ * batch_img[i].h_ * batch_img[i].w_ ; + // cout << "data size:" << data_size << endl; + // unsigned char *snapshotDataHost = new unsigned char[data_size] {}; + // cudaMemcpy(snapshotDataHost, batch_img[i].data_, data_size * sizeof(unsigned char), cudaMemcpyDeviceToHost); + + // sy_img tmp_img = batch_img[i]; + // tmp_img.data_ = snapshotDataHost; + + // vec_batch_img.push_back(tmp_img); + // } + + sy_img cpu_batch_img[batch_size]; for (int i = 0; i < batch_size; i++) { if (batch_img[i].data_ == NULL) + { cout << i << " data null" << endl; + LOG_ERROR("") + return FAILED; + } + cpu_batch_img[i].data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char)); + cudaMemcpy(cpu_batch_img[i].data_, batch_img[i].data_, batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char), cudaMemcpyDeviceToHost); + cpu_batch_img[i].w_ = batch_img[i].w_; + cpu_batch_img[i].h_ = batch_img[i].h_; + cpu_batch_img[i].c_ = batch_img[i].c_; } //cout << "begin hcp ProcessBatch" << endl; - hcp_batch(handle, batch_img, batch_size, result); + hcp_batch(handle, cpu_batch_img, batch_size, result); for (int b = 0; b < batch_size; b++) { @@ -93,6 +122,8 @@ int HumanCarParsing_Process(void * handle, sy_img * batch_img, int batch_size, //printf("HumanCarParsing_Process ERROR!!!!!!!!!!!! %d %d %d\n", i, cur_result.res_objs[i].res_index, SEC_INDEX_SIZE[i]); } } + + free(cpu_batch_img[b].data_) ; } //cout << "end hcp ProcessBatch" << endl; @@ -124,7 +155,7 @@ int HumanCarParsing_Process(void * handle, sy_img * batch_img, int batch_size, // //int resIndex = result[j][i].index; // int resIndex = index_score.data_[i * 2]; //cout << "resIndex" << endl; - // // + // //������ // switch (i) // { // case 0: diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFeatures.cppbk b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFeatures.cppbk deleted file mode 100644 index d304c4f..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFeatures.cppbk +++ /dev/null @@ -1,37 +0,0 @@ -#include "HumanFeatures.h" -#include -#include "sy_errorinfo.h" -using namespace std; - -int human_features_init(void *&handle, char*dbpath, int gpuid) -{ - hf_param params; - params.gpuid = gpuid; - params.mode = DEVICE_GPU; -// params.db_path = dbpath; - if (hf_init(&handle, params) !=0) - { - cout << "Init HF Failed!" << endl; - return FAILED; - - } - return SUCCESS; -} - -int human_features_process(void * handle, sy_img * batch_img, int batch_size, hf_result*& result) -{ - for (int i = 0; i < batch_size; i++) - { - if (batch_img[i].data_ == NULL) - cout << i << " data null" << endl; - } - - hf_feature_batch(handle, batch_img, batch_size, result); - return SUCCESS; -} - -int human_feature_release(void *& handle) -{ - hf_release(&handle); - return SUCCESS; -} diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFeatures.hbk b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFeatures.hbk deleted file mode 100644 index 341ed2e..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFeatures.hbk +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _HUMANFEATURES_H_ -#define _HUMANFEATURES_H_ -#include "human_features.h" - -int human_features_init(void *&handle, char*dbpath, int gpuid); - -int human_features_process(void * handle, sy_img * batch_img, int batch_size, hf_result*& result); - -int human_feature_release(void *& handle); -#endif diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/CycleQueue.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/CycleQueue.h deleted file mode 100644 index d614ba6..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/CycleQueue.h +++ /dev/null @@ -1,111 +0,0 @@ -#include - -using namespace std; - -#define MAX_LENGTH 100 - -typedef struct TRACK_POINT -{ - int x; - int y; -}TRACK_POINT; - -//template -class cycleQueue -{ -private: - unsigned int m_size; - int m_front; - int m_rear; - TRACK_POINT m_data[MAX_LENGTH]; - - bool firstPush; - bool full_size; - -public: - - cycleQueue() {} - - cycleQueue(unsigned size) - :m_size(size), - m_front(0), - m_rear(0) - { - //m_data = new TRACK_POINT[size]; - full_size = false; - firstPush = true; - } - - void set_param(unsigned size) - { - m_size = size; - //m_data = new TRACK_POINT[size]; - full_size = false; - firstPush = true; - m_front = 0; - m_rear = 0; - } - - ~cycleQueue() - { - //delete[] m_data; - } - - bool isEmpty() - { - return m_front == m_rear; - } - - bool isFull() - { - return m_front == (m_rear + 1) % m_size; - } - - int getFront() - { - return m_front; - } - - int getRear() - { - return m_rear; - } - - int size() - { - if (full_size) return m_size; - else if (m_rear == m_front && firstPush == false) return m_size; - else return m_rear - m_front; - } - - void push(TRACK_POINT ele)throw(bad_exception) - { - if (m_front == m_rear && firstPush==false) - { - m_front = (m_front + 1) % m_size; - full_size = true; - //cout << "full_size" << endl; - } - - m_data[m_rear] = ele; - m_rear = (m_rear + 1) % m_size; - firstPush = false; - } - - TRACK_POINT pop() throw(bad_exception) - { - if (isEmpty()) - { - throw bad_exception(); - } - TRACK_POINT tmp = m_data[m_front]; - m_front = (m_front + 1) % m_size; - return tmp; - } - - TRACK_POINT& get(int i) - { - //T tmp = m_data[i]; - return m_data[i]; - } -}; \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/HungarianAlgorithm.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/HungarianAlgorithm.cpp deleted file mode 100644 index 4df7e69..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/HungarianAlgorithm.cpp +++ /dev/null @@ -1,407 +0,0 @@ -#include -#include -#include "HungarianAlgorithm.h" - -using namespace std; - - -// B = A( extractRows, extractCols ) -// Require: -// extractRows.size()==A.rows, extractCols.size()==A.cols -// sum(extractRows)==B.rows, sum(extractCols)==B.cols -void extractGrids(const cv::Mat &A, const vector &extractRows, const vector &extractCols, cv::Mat &B) -{ - typedef float ValueType; - ValueType *pt1 = (ValueType*)A.data, *pt2 = (ValueType*)B.data, *pt3, *pt4; - const int step1 = A.step1(), rows = A.rows, cols = A.cols, step2 = B.step1(); - vector::const_iterator it1, it2, it3 = extractRows.end(), it4 = extractCols.end(); - for (it1 = extractRows.begin(); it1 != it3; pt1 += step1){ - pt3 = pt1; - if (*(it1++)){ - pt4 = pt2; - for (it2 = extractCols.begin(); it2 != it4; pt3++) - if (*(it2++)) - *(pt4++) = *pt3; - pt2 += step2; - } - } -} - -// B = A( extract ) -// Require: -// min(A.rows,A.cols) ==1 -// if(A.rows)==1, then require: A.cols==extract.size(), B.rows==1, sum(extract)==B.cols -// if(A.cols)==1, then require: A.rows==extract.size(), B.cols==1, sum(extract)==B.rows -void extractDots(const cv::Mat &A, const vector &extract, cv::Mat &B) -{ - assert(A.rows == 1 || A.cols == 1); - typedef float ValueType; - ValueType *pt1 = (ValueType*)A.data, *pt2 = (ValueType*)B.data; - vector::const_iterator it = extract.begin(), it2 = extract.end(); - if (A.rows == 1){ - for (; it != it2; pt1++) - if (*(it++)) - *(pt2++) = *pt1; - } - else{ - int step1 = A.step1(), step2 = B.step1(); - for (; it != it2; pt1 += step1) - if (*(it++)){ - *pt2 = *pt1; - pt2 += step2; - } - } -} - - -/* Initial Matlab code comes from: -http://www.mathworks.com/matlabcentral/fileexchange/20652-hungarian-algorithm-for-linear-assignment-problems--v2-3- - -Hungarian algorithm for matrix assignment problem. -costMat: there are (rows) works and (cols) jobs. costMat(i,j) means the cost of assigning job (j) to worker (i). -The problem is to solve a holistic optimization problem of assigning each worker a job! -The algorithm allows partial assignment - if there is no proper job for worker (i) we would set assignment(i) to -1, meaning no assignment for worker (i). - -Negatives in costMat means the corresponding assignments are forbidden. -*/ -void munkres(cv::Mat &IoUMat, vector &assignment) -{ - assert(IoUMat.type() == CV_32FC1); - const int rows = IoUMat.rows, cols = IoUMat.cols; - assignment.assign(rows, -1); - // modify input port O - IoU = cost - cv::Mat O = cv::Mat::ones(rows, cols, CV_32FC1); - cv::Mat costMat(rows, cols, CV_32FC1); - absdiff(O, IoUMat, costMat); - - cv::Mat validMat(rows, cols, CV_8UC1); - compare(costMat, cv::Scalar(0), validMat, cv::CMP_GE); - - float *ptF, *ptF2; - uchar *ptU, *ptU2; - int stepGap; - int r, c, i; - unsigned j; - vector::iterator it1, it2; - vector::iterator it3, it4; - - // validCol & validRow - vector validRow(rows, false); - ptU = validMat.data; - for (r = 0; r validCol(cols, false); - ptU = validMat.data; - for (c = 0; cnCols ? nRows : nCols; - if (!n) - return; - - // sumValid & maxValid - float sumValid = 0, maxValid = -1.f; - ptF = (float*)costMat.data; - ptU = validMat.data; - stepGap = validMat.step - validMat.cols; - r = 0; while (r++maxValid) maxValid = v; - } - else ptF++; - } ptU += stepGap; - } - - // bigM & maxValid - maxValid *= 10.f; - float bigM = log10f(sumValid); - int power = (int)ceilf(bigM) + 1; - bigM = 1.f; //bigM = pow( 10, power ); - for (i = 0; i starZ(n, -1); - ptU = zP.data; - for (r = 0; r noncoverColumn(n, true); - for (it3 = starZ.begin(); it3 != starZ.end(); it3++){ - if (*it3<0) continue; - noncoverColumn[*it3] = false; - } - vector noncoverRow(n, true); - vector primeZ(n, -1); - - // minC_uncovered & minR_uncovered - int cnt1 = 0, cnt2 = 0; - it1 = noncoverColumn.begin(), it2 = noncoverRow.begin(); - i = 0; while (i++ rIdx, cIdx; // [rIdx,cIdx] = find(temp4); - ptU = temp4.data; - stepGap = temp4.step - temp4.cols; - for (r = 0; r cR, cC; - for (j = 0; j rIdx2, cIdx2; - for (it3 = rIdx.begin(), it4 = cIdx.begin(); it3 != rIdx.end(); it3++, it4++) - if (*it3 != uZr){ - rIdx2.push_back(*it3); - cIdx2.push_back(*it4); - } - rIdx = rIdx2, cIdx = cIdx2; - // cR = find(~coverRow); - cR.clear(); - for (j = 0; j(stz)); - temp1 = tmp1(cv::Rect(0, 0, 1, sz)); - extractDots(dMat.col(stz), noncoverRow, temp1); - temp4 = tmp4(cv::Rect(0, 0, 1, sz)); - compare(temp1, minR_uncovered, temp4, cv::CMP_EQ); - // rIdx = [rIdx(:);cR(z)]; - for (i = 0, ptU = temp4.data; i= 0){ - starZ[rowZ1] = -1; - uZc = primeZ[rowZ1]; - uZr = rowZ1; - for (j = 0; j rowIdx(nRows), colIdx(nCols); - it1 = validRow.begin(), it2 = validCol.begin(); - for (i = 0, it3 = rowIdx.begin(); i vIdx(nRows, false); - it1 = vIdx.begin(), it3 = starZ.begin(); - i = 0; while (i++-1){ - uchar isInvalid = validMat.at(j, job); // validMat is now "invalidMat" - if (isInvalid) - assignment[j] = -1; - } - } -} \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/HungarianAlgorithm.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/HungarianAlgorithm.h deleted file mode 100644 index 55de472..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/HungarianAlgorithm.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef HUNGARIANALGORITHM_H_ -#define HUNGARIANALGORITHM_H_ - -#include -#ifdef _MSC_VER - #include -#else - #include - #include - #include -#endif - -#include -#include - -using namespace std; - - - -void extractGrids(const cv::Mat &A, const vector &extractRows, const vector &extractCols, cv::Mat &B); -void extractDots(const cv::Mat &A, const vector &extract, cv::Mat &B); -void munkres(cv::Mat &IoUMat, vector &assignment); - -#endif diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/KalmanBoxTracker.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/KalmanBoxTracker.cpp deleted file mode 100644 index 81585ac..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/KalmanBoxTracker.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#include "KalmanBoxTracker.h" - - -float IoU(vector &bb_test, vector &bb_gt) -{ - float xx1, yy1, xx2, yy2, w, h, wh, o; - xx1 = max(bb_test[0], bb_gt[0]); - yy1 = max(bb_test[1], bb_gt[1]); - xx2 = min(bb_test[2], bb_gt[2]); - yy2 = min(bb_test[3], bb_gt[3]); - w = max(float(0), (xx2 - xx1)); - h = max(float(0), (yy2 - yy1)); - wh = w * h; - o = wh / ((bb_test[2] - bb_test[0])*(bb_test[3] - bb_test[1]) - + (bb_gt[2] - bb_gt[0])*(bb_gt[3] - bb_gt[1]) - wh); - return o; -} - -void convert_bbox_to_z(vector &bbox, vector &z) -{ - float w, h, x, y, s, r; - w = bbox[2] - bbox[0]; - h = bbox[3] - bbox[1]; - x = bbox[0] + w / 2; - y = bbox[1] + h / 2; - s = w * h; //scale is just area - r = w / h; - z.push_back(x); - z.push_back(y); - z.push_back(s); - z.push_back(r); - -} - -void convert_x_to_bbox(cv::Mat &x, vector &bbox) -{ - float w, h; - w = sqrt(x.at(2) * x.at(3)); - h = x.at(2) / w; - //bbox[x1,y1,x2,y2]; - bbox.push_back(x.at(0) - w / 2); - bbox.push_back(x.at(1) - h / 2); - bbox.push_back(x.at(0) + w / 2); - bbox.push_back(x.at(1) + h / 2); -} - - - -KalmanBoxTracker::KalmanBoxTracker(vector &bbox, int trackLength) -{ - KF.init(7, 4, 0); //初始化卡尔曼滤波器对象KF - state = cv::Mat::zeros(7, 1, CV_32F); - processNoise = cv::Mat::zeros(7, 1, CV_32F); - measurement = cv::Mat::zeros(4, 1, CV_32F); //定义测量值 - - KF.transitionMatrix = (cv::Mat_(7, 7) << \ - 1, 0, 0, 0, 1, 0, 0, \ - 0, 1, 0, 0, 0, 1, 0, \ - 0, 0, 1, 0, 0, 0, 1, \ - 0, 0, 0, 1, 0, 0, 0, \ - 0, 0, 0, 0, 1, 0, 0, \ - 0, 0, 0, 0, 0, 1, 0, \ - 0, 0, 0, 0, 0, 0, 1); //状态转移矩阵A - - KF.measurementMatrix = (cv::Mat_(4, 7) << \ - 1, 0, 0, 0, 0, 0, 0, \ - 0, 1, 0, 0, 0, 0, 0, \ - 0, 0, 1, 0, 0, 0, 0, \ - 0, 0, 0, 1, 0, 0, 0); //测量矩阵H - - KF.measurementNoiseCov = (cv::Mat_(4, 4) << \ - 1, 0, 0, 0, \ - 0, 1, 0, 0, \ - 0, 0, 10, 0, \ - 0, 0, 0, 10); //测量噪声方差矩阵R - - KF.errorCovPost = (cv::Mat_(7, 7) << \ - 10, 0, 0, 0, 0, 0, 0, \ - 0, 10, 0, 0, 0, 0, 0, \ - 0, 0, 10, 0, 0, 0, 0, \ - 0, 0, 0, 10, 0, 0, 0, \ - 0, 0, 0, 0, 10000, 0, 0, \ - 0, 0, 0, 0, 0, 10000, 0, \ - 0, 0, 0, 0, 0, 0, 10000); //后验错误估计协方差矩阵P - - KF.processNoiseCov = (cv::Mat_(7, 7) << \ - 1, 0, 0, 0, 0, 0, 0, \ - 0, 1, 0, 0, 0, 0, 0, \ - 0, 0, 1, 0, 0, 0, 0, \ - 0, 0, 0, 1, 0, 0, 0, \ - 0, 0, 0, 0, 0.01, 0, 0, \ - 0, 0, 0, 0, 0, 0.01, 0, \ - 0, 0, 0, 0, 0, 0, 0.0001); //系统噪声方差矩阵Q - - vector z; - convert_bbox_to_z(bbox, z); - KF.statePost = (cv::Mat_(7, 1) << z[0], z[1], z[2], z[3], 0, 0, 0); //corrected state - state = (cv::Mat_(7, 1) << z[0], z[1], z[2], z[3], 0, 0, 0); - time_since_update = 0; - cls = bbox[5]; - //history - //hits = 0; - hit_streak = 0; - age = 0; - - m_trackLength = trackLength; - //history = new cycleQueue>(trackLength); - history.set_param(trackLength); -} - -KalmanBoxTracker::~KalmanBoxTracker() -{ - - /*int trackerSize = history.size(); - - for (int i = 0; i < trackerSize; i++) - { - history.get(i).clear(); - vector().swap(history.get(i)); - - }*/ - - /*if (history != NULL) - { - delete history; - history = NULL; - }*/ -} - -void KalmanBoxTracker::update(vector &bbox) -{ - time_since_update = 0; - //history - //hits += 1; - hit_streak += 1; - vector z; - convert_bbox_to_z(bbox, z); - measurement = (cv::Mat_(4, 1) << z[0], z[1], z[2], z[3]); - KF.correct(measurement); -} - -vector KalmanBoxTracker::predict(bool isUseDet) -{ - if ((KF.statePost.at(6) + KF.statePost.at(2)) <= 0) - KF.statePost.at(6) *= 0.0; - - KF.predict(); - - age += 1; - //cout << "33333FusionInterval:" << FusionInterval << endl; - if (time_since_update >= FusionInterval) - hit_streak = 0; - if (isUseDet) - time_since_update += 1; - vector bbox; - convert_x_to_bbox(KF.statePost, bbox); - //history.push_back(bbox); - - TRACK_POINT tmp_point; - tmp_point.x = bbox[0] + (bbox[2] - bbox[0]) / 2; - tmp_point.y = bbox[1] + (bbox[3] - bbox[1]) / 2; - history.push(tmp_point); - - return bbox; -} - -vector KalmanBoxTracker::get_state() -{ - vector bbox; - convert_x_to_bbox(KF.statePost, bbox); - return bbox; -} - diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/KalmanBoxTracker.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/KalmanBoxTracker.h deleted file mode 100644 index 3a7af89..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/KalmanBoxTracker.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef KALMANBOXTRACKER_H_ -#define KALMANBOXTRACKER_H_ - -#include -#include -#include -#include -#include -#include -#include "CycleQueue.h" - -using namespace std; - -//#define FusionInterval 5 //控制算法跳帧 -class KalmanBoxTracker -{ -public: - //int count = 0; - int time_since_update = 0; - int FusionInterval = 5; // 221007 - int id = 0; - int cls = 0; - float score = 0.00; - //vector< vector > history; - - cycleQueue history; //固定大小的轨迹 - - //int hits; - int hit_streak = 0; - int age = 0; - int m_trackLength = 0; - -public: - KalmanBoxTracker(vector &bbox, int trackLength); - ~KalmanBoxTracker(); - void update(vector &bbox); - vector predict(bool isUseDet); - vector get_state(); -private: - cv::KalmanFilter KF; //创建卡尔曼滤波器对象KF - cv::Mat measurement; - cv::Mat state;// (7, 1, CV_32F); //state = x - cv::Mat processNoise; -}; - -float IoU(vector &bb_test, vector &bb_gt); -void convert_bbox_to_z(vector &bbox, vector &z); -void convert_x_to_bbox(cv::Mat &x, vector &bbox); - - -#endif \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/Sort.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/Sort.cpp deleted file mode 100644 index 4248df5..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/Sort.cpp +++ /dev/null @@ -1,581 +0,0 @@ -#include "Sort.h" -#include -#include "../../DxDecoder/ImageSaveGPU.h" - -#ifdef _MSC_VER -#include -#include -#define _ACCESS _access -#define _MKDIR(a) _mkdir((a)) -#else -#include -#include -#include -#define _ACCESS access -#define _MKDIR(a) mkdir((a),0755) -#endif -#include - -const int color[11][3] = { { 255, 0, 0 }, { 255, 128, 255 }, { 255, 128, 0 }, { 255, 215, 0 }, { 154, 205, 50 }, { 0, 128, 0 }, \ - {0, 128, 255}, { 186, 85, 211 }, { 91, 46, 0 }, { 0, 0, 0 }, { 255, 255, 255 } }; - - -Sort::Sort() -{ - // max_age = 10; - max_lost_times = 1; - min_hits = 1; - input_det_count = 0; - WORK = true; - //-----------------by zl---------------------// - istraffic = false; //by zl 不统计交通量 - trackcount = 0; - //-----------------by zl---------------------// - - max_track_length = MAX_LENGTH; - trackers.clear(); -} - - -int Sort::update(int width, int height, bool isUseDet, vector< vector > &dets, VPT_ObjInfo *result, vector &deleteObjectID) -{ - //get predicted locations from existing trackers. - vector< vector > trks; - vector pos; - int ObjCount = 0; //by zl 本帧图像中的有效前景个数 - vector bbox; - - //cout << "trackers size: " << trackers.size() << endl; - for (int i = 0; i < trackers.size(); i++ ) - { - pos = trackers[i].predict(isUseDet); - pos.push_back(1); - pos.push_back(trackers[i].cls); - trks.push_back(pos); - pos.clear(); - } - - if (isUseDet == true) - { - vector< vector > matched; - vector unmatched_dets; - vector unmatched_trks; - - Sort::associate_detections_to_trackers(matched, unmatched_dets, unmatched_trks, dets, trks, 0.3); - - //update matched trackers with assigned detections - for (int matched_number = 0; matched_number < matched.size(); matched_number++) - { - trackers[matched[matched_number][1]].update(dets[matched[matched_number][0]]); - trackers[matched[matched_number][1]].score = dets[matched[matched_number][0]][4]; - trackers[matched[matched_number][1]].cls = dets[matched[matched_number][0]][5]; - } - - //create and initialise new trackers for unmatched detections - for (int unmatched_dets_number = 0; unmatched_dets_number < unmatched_dets.size(); unmatched_dets_number++) - { - KalmanBoxTracker tracker = KalmanBoxTracker(dets[unmatched_dets[unmatched_dets_number]], max_track_length); - tracker.id = -1; - // tracker.FusionInterval = FusionInterval; //221007 - trackers.push_back(tracker); - trackers[trackers.size() - 1].score = dets[unmatched_dets[unmatched_dets_number]][4];//by zl 20170525 解决第一次检测时置信度为0问题 - // cout << "trackers size: " << trackers.size() << endl; - } - - for (int trackers_number = 0; trackers_number < trackers.size();) - { - //cout << trackers[trackers_number].id << " " < max_age) - if (trackers[trackers_number].time_since_update > max_lost_times) - { - if (trackers[trackers_number].id != -1) - { - deleteObjectID.push_back(trackers[trackers_number].id); - } - trackcount++; - trackers.erase(trackers.begin() + trackers_number); - continue; - } - //cout << "22222FusionInterval:" << trackers[trackers_number].FusionInterval << endl; - if ((ObjCount < MAX_OBJ_COUNT && (trackers[trackers_number].time_since_update < max_lost_times)) && ((trackers[trackers_number].hit_streak >= min_hits) || (input_det_count <= min_hits))) - // if (ObjCount < MAX_OBJ_COUNT && (trackers[trackers_number].time_since_update < trackers[trackers_number].FusionInterval) && ((trackers[trackers_number].hit_streak >= min_hits) || (frame_count <= (min_hits*trackers[trackers_number].FusionInterval)))) //221007 - { - - if (trackers[trackers_number].id == -1) - trackers[trackers_number].id = trackcount++; - result[ObjCount].id = trackers[trackers_number].id; - bbox = trackers[trackers_number].get_state(); - result[ObjCount].left = bbox[0]; // bbout[i][0]; - result[ObjCount].top = bbox[1]; //bbout[i][1]; - result[ObjCount].right = bbox[2]; //bbout[i][2]; - result[ObjCount].bottom = bbox[3]; //bbout[i][3]; - result[ObjCount].confidence = trackers[trackers_number].score; // bbout[i][4]; - // result[ObjCount].index = trackers[trackers_number].cls - 1; //针对FPN检测模型 id底层给出的值大了1 所以此处-1 - result[ObjCount].index = trackers[trackers_number].cls; // 针对检测模型 底层库给出正确的index值 此处无须特殊处理 - RectboundCheck(width, height, &result[ObjCount]); - result[ObjCount].center_x = result[ObjCount].left + (result[ObjCount].right - result[ObjCount].left) * 0.5; // 中心点 add by 20170227 - result[ObjCount].center_y = result[ObjCount].top + (result[ObjCount].bottom - result[ObjCount].top) * 0.5; // 中心点 - //if(trackers[trackers_number].age==2*FusionInterval) - if (trackers[trackers_number].age == 2 * trackers[trackers_number].FusionInterval) //221007 - { - result[ObjCount].snap_flag = 1; // 中心点 - } - else - { - result[ObjCount].snap_flag = 0; // 中心点 - } - -#if _Debug - printf("trackers_number = %d, trackers.size() = %d, update: index = %d, id = %d, (%d, %d), (%d, %d)\n", trackers_number, trackers.size(), result[ObjCount].index, result[ObjCount].id, result[ObjCount].left, result[ObjCount].top, result[ObjCount].right, result[ObjCount].bottom); -#endif - ObjCount++; - } - trackers_number++;//共多少条轨迹 - - } - - input_det_count += 1; //帧数加一 - } - else - { - for (int trackers_number = 0; trackers_number < trackers.size() && ObjCount < MAX_OBJ_COUNT; trackers_number++) - { - // printf("trackers_number: %d\n", trackers_number); - //cout << "44444FusionInterval:" << trackers[trackers_number].FusionInterval << endl; - if (trackers[trackers_number].id == -1) - trackers[trackers_number].id = trackcount++; - bbox = trackers[trackers_number].get_state(); - result[trackers_number].id = trackers[trackers_number].id; - result[trackers_number].left = bbox[0]; // bbout[i][0]; - result[trackers_number].top = bbox[1]; //bbout[i][1]; - result[trackers_number].right = bbox[2]; //bbout[i][2]; - result[trackers_number].bottom = bbox[3]; //bbout[i][3]; - result[trackers_number].confidence = trackers[trackers_number].score; // bbout[i][4]; - // result[trackers_number].index = trackers[trackers_number].cls - 1;//bbox[5] - 1;// trackers[trackers_number].cls - 1; // bbout[i][5] - 1; - result[trackers_number].index = trackers[trackers_number].cls;//bbox[5] - 1;// trackers[trackers_number].cls - 1; // bbout[i][5] - 1; - RectboundCheck(width, height, &result[trackers_number]); - result[trackers_number].center_x = (int)(result[trackers_number].left + (result[trackers_number].right - result[trackers_number].left) * 0.5); // 中心点 add by 20170227 - result[trackers_number].center_y = (int)(result[trackers_number].top + (result[trackers_number].bottom - result[trackers_number].top) * 0.5); // 中心点 - - result[ObjCount].snap_flag = 0; // 中心点 - - ObjCount++; - } - } - - //---------------------------注释掉了这步操作 用了新的绘制轨迹的函数 需要绘制调用addTracker(Mat *img)方法 by lm---------------------------------------------/ - //addTracker(result, ObjCount); - - - return ObjCount; - -} - -// -////---------------------------by zl ---------------------------------------------/ -//int Sort::addTracker(VPT_ObjInfo *result, int resultcount) -//{ -// for (int i = 0; i < resultcount; i++) -// { -// bool flag = false; -// for (int j = 0; j < tracker.size(); j++) -// { -// if (result[i].id == tracker[j].id) //若有匹配的 则更新 -// { -// tracker[j].listinfo.push_back(result[i]); -// tracker[j].lost = 0; -// tracker[j].isupdate = true; -// tracker[j].num++; //每个ID的计数 -// result[i].num = tracker[j].num; -// -// if (tracker[j].istraffic == false && istraffic) -// { -// int listmax = tracker[j].listinfo.size() - 1; -// } -// flag = true; -// break; -// } -// } -// if (!flag) //没有找到匹配项 新添加 -// { -// mylist m_list; -// m_list.listinfo.push_back(result[i]); -// m_list.isupdate = true; -// m_list.lost = 0; -// m_list.id = result[i].id; -// m_list.index = result[i].index;; -// m_list.istraffic = false; -// m_list.num = 0; //20170306 -// result[i].num = 0; -// m_list.startframe = frame_count; -//#if _Debug -// printf("addTracker_pushback :index = %d, id = %d, (%d, %d), (%d, %d)\n", m_list.index, m_list.id, result[i].left, result[i].top, result[i].right, result[i].bottom); -//#endif -// tracker.push_back(m_list); -// } -// } -// //绘制轨迹部分 -// -// for (vector ::iterator iter = tracker.begin(); iter != tracker.end();) -// { -// if (iter->isupdate == false) //未更新的不绘制轨迹 -// { -// iter->lost++; -// if (iter->lost > LOSTMAXFRAMECCOUNT) //若丢失太多 则删除该轨迹 -// { -// iter->endframe = frame_count; //结束帧 -// iter = tracker.erase(iter);//删除 -// continue; -// } -// } -// else //只对更新后的绘制轨迹 -// { -// ; -// } -// iter->isupdate = false; -// iter++; -// } -// -// return 1; -//} - - -//---------------------------利用trackers中的history 绘制路径 -by lm ---------------------------------------------/ -//固定长度的轨迹,采用循环队列,仅保存目前最前N length的轨迹,避免对于停留在画面中目标 导致的内存一直增长 -int Sort::addTracker(cv::Mat *img) -{ - map> tracker; - vector bbox; - - - int x_1, y_1, x_2, y_2; - for (auto iter : trackers) - { - //if (iter.time_since_update < FusionInterval) - //cout << "55555FusionInterval:" << iter.FusionInterval << endl; - if (iter.time_since_update < iter.FusionInterval) //221007 - { - int index = iter.history.getFront(); - int trackerSize = iter.history.size(); - - for (int i = 0; i < trackerSize; i++) - { - if (i == 0) - { - x_1 = iter.history.get(index).x; - y_1 = iter.history.get(index).y; - } - else - { - x_2 = iter.history.get(index).x; - y_2 = iter.history.get(index).y; - int colorIndex = iter.id % 11; - cv::line(*img, cv::Point(x_1, y_1), cv::Point(x_2, y_2), cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 1); - - //drawLineOnGPU() - - x_1 = x_2; - y_1 = y_2; - } - - //if (i == 0) - //{ - // x_1 = iter.history.get(index)[0] + (iter.history.get(index)[2] - iter.history.get(index)[0]) / 2; - // y_1 = iter.history.get(index)[1] + (iter.history.get(index)[3] - iter.history.get(index)[1]) / 2; - //} - //else - //{ - // x_2 = iter.history.get(index)[0] + (iter.history.get(index)[2] - iter.history.get(index)[0]) / 2; - // y_2 = iter.history.get(index)[1] + (iter.history.get(index)[3] - iter.history.get(index)[1]) / 2; - // int colorIndex = iter.id % 11; - // cv::line(*img, cvPoint(x_1, y_1), cvPoint(x_2, y_2), cvScalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 1); - - // //drawLineOnGPU() - - // x_1 = x_2; - // y_1 = y_2; - //} - - index = (index + 1) % trackerSize; - } - - //int index = iter.history->getFront(); - //int trackerSize = iter.history->size(); - - //for (int i = 0; i < trackerSize; i++) - //{ - // if (i == 0) - // { - // x_1 = iter.history->get(index)[0] + (iter.history->get(index)[2] - iter.history->get(index)[0]) / 2; - // y_1 = iter.history->get(index)[1] + (iter.history->get(index)[3] - iter.history->get(index)[1]) / 2; - // } - // else - // { - // x_2 = iter.history->get(index)[0] + (iter.history->get(index)[2] - iter.history->get(index)[0]) / 2; - // y_2 = iter.history->get(index)[1] + (iter.history->get(index)[3] - iter.history->get(index)[1]) / 2; - // int colorIndex = iter.id % 11; - // cv::line(*img, cvPoint(x_1, y_1), cvPoint(x_2, y_2), cvScalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 1); - - // //drawLineOnGPU() - - // x_1 = x_2; - // y_1 = y_2; - // } - - // index = (index + 1) % trackerSize; - //} - } - - } - - return 1; -} - -//不固定长度的轨迹版本 采用vector,轨迹一直保留,对于停留在画面中的物体,会有内存一直增长的隐患 -//int Sort::addTracker(cv::Mat *img) -//{ -// map> tracker; -// vector bbox; -// -// -// int x_1, y_1, x_2, y_2; -// for (auto iter : trackers) -// { -// if (iter.time_since_update < FusionInterval) -// { -// for (int i = 0; i < iter.history.size(); i++) -// { -// -// if (i == 0) -// { -// x_1 = iter.history[i][0] + (iter.history[i][2] - iter.history[i][0]) / 2; -// y_1 = iter.history[i][1] + (iter.history[i][3] - iter.history[i][1]) / 2; -// } -// else -// { -// x_2 = iter.history[i][0] + (iter.history[i][2] - iter.history[i][0]) / 2; -// y_2 = iter.history[i][1] + (iter.history[i][3] - iter.history[i][1]) / 2; -// int colorIndex = iter.id % 11; -// cv::line(*img, cvPoint(x_1, y_1), cvPoint(x_2, y_2), cvScalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 1); -// -// //drawLineOnGPU() -// -// x_1 = x_2; -// y_1 = y_2; -// } -// } -// } -// -// } -// -// return 1; -//} - -void Sort::Release() -{ - //tracker.clear(); - //vector ().swap(tracker); - trackers.clear(); - vector().swap(trackers); -} -bool Sort::GetState() -{ - return WORK; -} - -void Sort::Pause() -{ - WORK = false; -} - -void Sort::ReSet() -{ - WORK = true; - //Release(); - //max_age = 1; - //min_hits = 3; - //frame_count = 0; - - ////-----------------by zl---------------------// - //istraffic = false; //by zl 不统计交通量 - //trackcount = 0; - ////-----------------by zl---------------------// -} - -//---------------------------by zl ---------------------------------------------/ -bool line_rect_intersection(cv::Point start_p, cv::Point end_p, int left, int top, int right, int bottom) -{ - int a = start_p.y - end_p.y; - int b = end_p.x - start_p.x; - int c = start_p.x* end_p.y - end_p.x* start_p.y; - - ////思路:先看线段所在直线是否与矩形相交,如果不相交则必为 “F”, - ////如果相交,则看线段的两个点是否在矩形的同一边(即两点的 x(y) 坐标都比矩形的小 x(y) 坐标小,或者大), - ////若在同一边则为“F”,否则就是相交的情况。 - if ((a* left + b*top + c >= 0 && a* right + b* bottom + c <= 0) || - (a* left + b*top + c <= 0 && a* right + b* bottom + c >= 0) || - (a* left + b*bottom + c >= 0 && a* right + b* top + c <= 0) || - (a* left + b*bottom + c >= 0 && a* right + b* top + c <= 0)) - { - if (left > right) - { - swap(left, right); - } - if (top < bottom) - { - swap(top, bottom); - } - if ((start_p.x < left && end_p.x < left) || - (start_p.x > right && end_p.x < left) || - (start_p.y > top && end_p.y > top) || - (start_p.y < bottom && end_p.y < bottom)) ///判断线段是否在矩形一侧 - { - return false; - } - else - { - return true; - } - } - else - { - return false; - } -} -void RectboundCheck(int Width, int Height, VPT_ObjInfo * result) //防止坐标越界 by zl -{ - if (result->left < 0) - result->left = 0; - if (result->left >= Width) - result->left = Width; - - if (result->top < 0) - result->top = 0; - if (result->top >= Height) - result->top = Height; - - if (result->right <= result->left) - result->right = result->left + 1; - if (result->right >= Width) - result->right = Width; - - if (result->bottom < result->top) - result->bottom = result->top + 1; - if (result->bottom >= Height) - result->bottom = Height; - - -} -//------------------------------------其他函数----------------------------------------// -void Sort::associate_detections_to_trackers(vector< vector > &matched, vector &unmatched_dets, vector &unmatched_trks, vector< vector > &dets, vector< vector > &trks, float iou_threshold) -{ - - if (0 == trks.size()) - { - for (int x = 0; x < dets.size(); x++) - { - unmatched_dets.push_back(x); - } - } - else if (0 == dets.size()) - { - for (int x = 0; x < trks.size(); x++) - { - unmatched_trks.push_back(x); - } - } - else - { - cv::Mat IoUMat(dets.size(), trks.size(), CV_32FC1); - for (int i = 0; i < dets.size(); i++) - for (int j = 0; j < trks.size(); j++) - { - //cls区分 - if (1) - //if (dets[i][5] == trks[j][5]) - { - IoUMat.at(i, j) = IoU(dets[i], trks[j]); - } - else - { - IoUMat.at(i, j) = 0; - } - - } - - //匈牙利算法 - vector assignment; - munkres(IoUMat, assignment); - - vector::iterator iter; - for (int trackers_indices = 0; trackers_indices < trks.size(); trackers_indices++) - { - iter = find(assignment.begin(), assignment.end(), trackers_indices); - if (iter == assignment.end()) - { - //assignment中不存在trackers_indices值 - unmatched_trks.push_back(trackers_indices); - } - } - - vector matched_row_col; - for (int detections_indices = 0; detections_indices < assignment.size(); detections_indices++) - { - if (assignment[detections_indices] == -1) - { - unmatched_dets.push_back(detections_indices); - } - else if (IoUMat.at(detections_indices, assignment[detections_indices]) > iou_threshold) - { - matched_row_col.push_back(detections_indices); - matched_row_col.push_back(assignment[detections_indices]); - matched.push_back(matched_row_col); - matched_row_col.clear(); - } - else - { - unmatched_dets.push_back(detections_indices); - unmatched_trks.push_back(assignment[detections_indices]); - } - } - } -} -//判断两条线是否相交 - -///------------alg 2------------ -//叉积 -double mult(cv::Point a, cv::Point b, cv::Point c) -{ - return (a.x - c.x)*(b.y - c.y) - (b.x - c.x)*(a.y - c.y); -} - -//aa, bb为一条线段两端点 cc, dd为另一条线段的两端点 相交返回true, 不相交返回false -bool intersect(cv::Point aa, cv::Point bb, cv::Point cc, cv::Point dd) -{ - if (max(aa.x, bb.x) -#include -#include -#include -#include -#include -#include "../VPTProcess.h" - - -using namespace std; - - -#define LOSTMAXFRAMECCOUNT 5 //by zl -#define SNAPSHOTFRAMECOUNT 24 //下标从0开始 取第十帧为快照帧 - -struct TrackerResult -{ - vector< vector > trackers_box; - vector< vector< vector > > trackers_history; -}; - - -typedef struct mylist -{ - vector listinfo; - int lost; //丢失的帧数 >LOSTMAXFRAMECCOUNT 则认为彻底丢失目标 - long id; - bool isupdate; - bool istraffic; - int index;// 行人类别 - int num; // 该ID序列下的第num帧 20170306 从0开始计数 - int startframe; //轨迹开始帧 - int endframe; //轨迹结束帧 -}mylist; - - - -class Sort -{ -public: - Sort(); - int update(int width, int height, bool isUseDet, vector< vector > &dets, VPT_ObjInfo *result, vector &deleteObjectID); - void Release(); - void ReSet(); - void Pause(); - bool GetState(); - int addTracker(cv::Mat *img); -public: - vector trackers; - //int FusionInterval = 5; // 221007 - //int max_age = 0; - int max_lost_times = 3; - int min_hits = 0; - int input_det_count =0; - int trackcount = 0; - int max_track_length = 0; - -private: - int linecount = 0; - bool istraffic = 0; //by zl 是否统计交通量 - //vector tracker; - bool WORK = false; - -private: - void associate_detections_to_trackers(vector< vector > &matched, vector &unmatched_dets, vector &unmatched_trks, vector< vector > &dets, vector< vector > &trks, float iou_threshold = 0.3); - //int addTracker(VPT_ObjInfo *result, int resultcount); - int Traffic(); -}; -//辅助函数 -void RectboundCheck(int Width, int Height, VPT_ObjInfo * result); //防止坐标越界 by zl -bool intersect(cv::Point aa, cv::Point bb, cv::Point cc, cv::Point dd); //判断两个线条是否相交 暂时未用到 -bool line_rect_intersection(cv::Point start_p, cv::Point end_p, int left, int top, int right, int bottom); //判断矩形框与线条是否相交 -#endif \ No newline at end of file