Commit cefa38a2f691ec3884a5c11ce95faa67578b7b34
1 parent
922efde7
重新编译子库;
删除无用代码
Showing
24 changed files
with
98 additions
and
6042 deletions
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 |
165 | 165 | fprintf(stderr, "here cudaMemcpy failed! error: %s\n", cudaGetErrorString(cudaStatus)); |
166 | 166 | } |
167 | 167 | |
168 | - dx_frame.height = frame.height; //�����ͼû���棬����Ҳû�д�ͼ�����ܱ��������ã���ô���½�һ����ͼ���ݣ������ͼvector | |
168 | + dx_frame.height = frame.height; | |
169 | 169 | dx_frame.width = frame.width; |
170 | 170 | dx_frame.size = frame.size; |
171 | 171 | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile deleted
1 | - | |
2 | -CC = gcc | |
3 | -XX = g++ | |
4 | -AR = ar | |
5 | -NVCC=nvcc | |
6 | - | |
7 | -PROJ_HOME = /mnt/data/cmhu/Project_VideoStructure | |
8 | - | |
9 | -TARGET = $(DES_BIN)/libVPT.so | |
10 | - | |
11 | -NVDECODE_ROOT=../DxDecoder | |
12 | -DEPEND_DIR = $(STATIC_RELEASE_ROOT) | |
13 | -#UTOOLS_ROOT = /home/xzhao_aic/MCaffe2/linux/utools | |
14 | -UTOOLS_ROOT=/home/xzhao_aic/lib_video_structure_190123.old/utools/ | |
15 | -UTOOLS_SRC = $(UTOOLS_SSD_ROOT) | |
16 | - | |
17 | -SDK_ROOT = $(PROJ_HOME)/Linux_3rdparty/video_structure_sdk_20220512 | |
18 | - | |
19 | -INCLUDE =-I $(OPENCV_ROOT)/include \ | |
20 | - -I $(OPENCV_ROOT)/include/opencv \ | |
21 | - -I $(OPENCV_ROOT)/include/opencv2 \ | |
22 | - -I /home/xzhao_aic/local/include \ | |
23 | - -I $(BOOST_ROOT)/include \ | |
24 | - -I /usr/local/cuda/include \ | |
25 | - -I $(UTOOLS_SRC) \ | |
26 | - -I $(NVDECODE_ROOT) \ | |
27 | - -I $(NVDECODE_ROOT)/common/inc \ | |
28 | - -I /usr/include/cairo \ | |
29 | - -I $(SDK_ROOT) \ | |
30 | - | |
31 | -#-I $(VPT_ROOT)/vpt \ | |
32 | - | |
33 | -# -I ./MD5 \ | |
34 | - | |
35 | -#CFLAGS =-g -Wall -O3 $(INCLUDE) # -std=c++11 | |
36 | -CFLAGS = $(CFLAGS_LIB) $(INCLUDE) -std=c++11 | |
37 | -NFLAGS = $(NFLAGS_LIB) $(INCLUDE) -std=c++11 | |
38 | - | |
39 | - | |
40 | -LIBSPATH=-L$(UTOOLS_ROOT) -lutools \ | |
41 | - -L$(NVDECODE_ROOT) -lDxDecoder \ | |
42 | - -L$(HP_ROOT) -lhp \ | |
43 | - -L$(HCP_ROOT) -lhcp \ | |
44 | - -L$(VC_ROOT) -lvcolor \ | |
45 | - -L$(VR_ROOT) -lvr \ | |
46 | - -L$(VP_ROOT) -lvp \ | |
47 | - -L/usr/local/cuda/lib64 -lcuda -lcudart -lnvcuvid -lnppi -lnppc -lcurand -lcublas -lcusolver \ | |
48 | - -L/usr/local/lib -ldl -ldl -lm \ | |
49 | - -l:libjasper.so.1 -l:libIlmImf.so.7 \ | |
50 | - -L$(DES_BIN) \ | |
51 | - | |
52 | -LIBS= -ldl -lpthread -lcairo | |
53 | - | |
54 | -#SRCS:=$(wildcard *.cpp) | |
55 | -#OBJS:=$(patsubst %cpp, %o, $(SRCS)) | |
56 | - | |
57 | -SRCS:=$(wildcard *.cpp) $(wildcard $(VPT_ROOT)/sort/*.cpp) $(wildcard $(VPT_ROOT)/MD5/mID.cpp) | |
58 | -DIRS:=$(notdir $(SRCS)) | |
59 | -OBJS:=$(patsubst %cpp, %o, $(DIRS)) | |
60 | - | |
61 | -CU_SOURCES = $(shell ls *.cu) | |
62 | -CU_OBJS=$(CU_SOURCES:.cu=.o) | |
63 | - | |
64 | -STATICLIBS:=$(wildcard $(UTOOLS_ROOT)/*.a) | |
65 | - | |
66 | -all:$(TARGET) | |
67 | - | |
68 | -$(TARGET):$(addprefix $(BUILD_DIR)/, $(OBJS)) $(addprefix $(BUILD_DIR)/, $(CU_OBJS)) | |
69 | - $(XX) $(CFLAGS) -shared -o $@ $^ $(LIBSPATH) $(LIBS) | |
70 | - chmod 777 $(TARGET) | |
71 | - $(STRIP) $(TARGET) | |
72 | - | |
73 | -$(BUILD_DIR)/%.o:%.cpp | $(BUILD_DIR) | |
74 | - @echo "##############################$@##############################" | |
75 | - $(XX) $(CFLAGS) -c $< -o $@ | |
76 | -$(BUILD_DIR)/%.o:$(VPT_ROOT)/sort/%.cpp | $(BUILD_DIR) | |
77 | - @echo "##############################$@###############################" | |
78 | - $(XX) $(CFLAGS) -c $< -o $@ | |
79 | -$(BUILD_DIR)/%.o:$(VPT_ROOT)/MD5/%.cpp | $(BUILD_DIR) | |
80 | - @echo "##############################$@###############################" | |
81 | - $(XX) $(CFLAGS) -c $< -o $@ | |
82 | -$(BUILD_DIR)/%.o:%.cu | $(BUILD_DIR) | |
83 | - @echo "#######################CU_OBJS:$@###############" | |
84 | - $(NVCC) $(NFLAGS) -o $@ $< | |
85 | - | |
86 | -$(BUILD_DIR): | |
87 | - mkdir $@ | |
88 | - | |
89 | -.PHONY:clean | |
90 | -clean: | |
91 | - $(RM) $(BUILD_DIR)/* | |
92 | - $(RM) $(TARGET) | |
93 | - |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile-bin deleted
1 | - | |
2 | -CC = gcc | |
3 | -XX = g++ | |
4 | -AR = ar | |
5 | -NVCC=nvcc | |
6 | - | |
7 | -TARGET = vpt_test | |
8 | - | |
9 | -NVDECODE_ROOT=../NvDecode | |
10 | -UTOOLS_ROOT = $(UTOOLS_SSD_ROOT)/utools | |
11 | -UTOOLS_SRC = $(UTOOLS_SSD_ROOT)/../src | |
12 | -VPT_ROOT = . | |
13 | -INCLUDE =-I $(OPENCV_ROOT)/include \ | |
14 | - -I $(OPENCV_ROOT)/include/opencv \ | |
15 | - -I $(OPENCV_ROOT)/include/opencv2 \ | |
16 | - -I $(BOOST_ROOT)/include \ | |
17 | - -I /usr/local/cuda/include \ | |
18 | - -I $(UTOOLS_SRC) \ | |
19 | - -I $(NVDECODE_ROOT) \ | |
20 | - -I $(NVDECODE_ROOT)/common/inc \ | |
21 | - -I $(VPT_ROOT)/sort \ | |
22 | - | |
23 | -#-I $(VPT_ROOT)/vpt \ | |
24 | - | |
25 | -# -I ./MD5 \ | |
26 | - | |
27 | -#CFLAGS =-g -Wall -O3 $(INCLUDE) # -std=c++11 | |
28 | -CFLAGS = $(CFLAGS_APP) $(INCLUDE) -std=c++11 | |
29 | - | |
30 | -LIBSPATH=-L$(UTOOLS_ROOT) -lustools \ | |
31 | - -L$(NVDECODE_ROOT) -lNvDecode \ | |
32 | - -L/usr/local/cuda/lib64 -lcuda -lcudart -lnvcuvid -lnppi -lnppc -lcurand -lcublas -lcusolver \ | |
33 | - -L/usr/local/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice -lyasm -ldl -ldl -lm \ | |
34 | - | |
35 | -LIBS= -ldl -lpthread | |
36 | - | |
37 | -#SRCS:=$(wildcard *.cpp) | |
38 | -#OBJS:=$(patsubst %cpp, %o, $(SRCS)) | |
39 | - | |
40 | -SRCS:=$(wildcard *.cpp) $(wildcard $(VPT_ROOT)/sort/*.cpp) $(wildcard $(VPT_ROOT)/MD5/mID.cpp) | |
41 | -DIRS:=$(notdir $(SRCS)) | |
42 | -OBJS:=$(patsubst %cpp, %o, $(DIRS)) | |
43 | - | |
44 | - | |
45 | -all:$(TARGET) | |
46 | - | |
47 | -$(TARGET):$(OBJS) | |
48 | - $(XX) $(CFLAGS) -Wl,-rpath=./ -o $@ $^ $(LIBSPATH) $(LIBS) | |
49 | - rm -f *.o | |
50 | - cp $(TARGET) $(DES_BIN) | |
51 | -%.o:%.cpp | |
52 | - @echo "##############################$@##############################" | |
53 | - $(XX) $(CFLAGS) -c $< | |
54 | -%.o:$(VPT_ROOT)/sort/%.cpp | |
55 | - @echo "##############################$@###############################" | |
56 | - $(XX) $(CFLAGS) -c $< | |
57 | -%.o:$(VPT_ROOT)/MD5/%.cpp | |
58 | - @echo "##############################$@###############################" | |
59 | - $(XX) $(CFLAGS) -c $< | |
60 | - | |
61 | - | |
62 | -.PHONY:clean | |
63 | -clean: | |
64 | - $(RM) $(OBJS) | |
65 | - $(RM) $(TARGET) | |
66 | - $(RM) $(DES_BIN)/$(TARGET) | |
67 | - $(RM) *~ | |
68 | - |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/Makefile-lib deleted
1 | - | |
2 | -CC = gcc | |
3 | -XX = g++ | |
4 | -AR = ar | |
5 | -NVCC=nvcc | |
6 | - | |
7 | -TARGET = libVPT.a | |
8 | - | |
9 | -NVDECODE_ROOT=../NvDecode | |
10 | -DEPEND_DIR = $(STATIC_RELEASE_ROOT) | |
11 | -UTOOLS_ROOT = $(UTOOLS_SSD_ROOT)/utools | |
12 | -UTOOLS_SRC = $(UTOOLS_SSD_ROOT)/../src | |
13 | -VPT_ROOT = . | |
14 | -INCLUDE =-I $(OPENCV_ROOT)/include \ | |
15 | - -I $(OPENCV_ROOT)/include/opencv \ | |
16 | - -I $(OPENCV_ROOT)/include/opencv2 \ | |
17 | - -I $(BOOST_ROOT)/include \ | |
18 | - -I /usr/local/cuda/include \ | |
19 | - -I $(UTOOLS_SRC) \ | |
20 | - -I $(NVDECODE_ROOT) \ | |
21 | - -I $(NVDECODE_ROOT)/common/inc \ | |
22 | - -I $(VPT_ROOT)/sort \ | |
23 | - | |
24 | -#-I $(VPT_ROOT)/vpt \ | |
25 | - | |
26 | -# -I ./MD5 \ | |
27 | - | |
28 | -#CFLAGS =-g -Wall -O3 $(INCLUDE) # -std=c++11 | |
29 | -CFLAGS = $(CFLAGS_LIB) $(INCLUDE) -std=c++11 | |
30 | -NFLAGS = $(NFLAGS_LIB) $(INCLUDE) -std=c++11 | |
31 | - | |
32 | - | |
33 | -LIBSPATH=-L $(UTOOLS_ROOT) \ | |
34 | - -L/usr/local/cuda/lib64 -lcudart -lcublas -lcusolver -lcurand | |
35 | - | |
36 | -LIBS=-lustools -ldl -lpthread | |
37 | - | |
38 | -#SRCS:=$(wildcard *.cpp) | |
39 | -#OBJS:=$(patsubst %cpp, %o, $(SRCS)) | |
40 | - | |
41 | -SRCS:=$(wildcard *.cpp) $(wildcard $(VPT_ROOT)/sort/*.cpp) $(wildcard $(VPT_ROOT)/MD5/mID.cpp) | |
42 | -DIRS:=$(notdir $(SRCS)) | |
43 | -OBJS:=$(patsubst %cpp, %o, $(DIRS)) | |
44 | - | |
45 | -CU_SOURCES = $(shell ls *.cu) | |
46 | -CU_OBJS=$(CU_SOURCES:.cu=.o) | |
47 | - | |
48 | -STATICLIBS:=$(wildcard $(UTOOLS_ROOT)/*.a) | |
49 | - | |
50 | -all:$(TARGET) | |
51 | - | |
52 | -$(TARGET):$(OBJS) $(CU_OBJS) | |
53 | - rm -f $(TARGET) | |
54 | - $(AR) crs $@ $(OBJS) $(CU_OBJS) | |
55 | - ranlib $(TARGET) | |
56 | - rm -f *.o | |
57 | - echo create $(TARGET) > script.mri; | |
58 | - echo addlib $(TARGET) >> script.mri; | |
59 | - @for alib in `echo $(STATICLIBS) | cut -d' ' -f 1-`; \ | |
60 | - do \ | |
61 | - echo addlib $$alib >> script.mri; \ | |
62 | - done | |
63 | - echo save >> script.mri; | |
64 | - echo end >> script.mri; | |
65 | - ar -M < script.mri | |
66 | -# $(foreach alib, $(STATICLIBS), $(AR) x $(alib)) | |
67 | -# ar cru $(TARGET) *.o | |
68 | - ranlib $(TARGET) | |
69 | - rm -f *.o | |
70 | - cp $(TARGET) $(DES_LIB) | |
71 | - chmod 777 $(DES_LIB)/$(TARGET) | |
72 | -%.o:%.cpp | |
73 | - @echo "##############################$@##############################" | |
74 | - $(XX) $(CFLAGS) -c $< | |
75 | -%.o:$(VPT_ROOT)/sort/%.cpp | |
76 | - @echo "##############################$@###############################" | |
77 | - $(XX) $(CFLAGS) -c $< | |
78 | -%.o:$(VPT_ROOT)/MD5/%.cpp | |
79 | - @echo "##############################$@###############################" | |
80 | - $(XX) $(CFLAGS) -c $< | |
81 | -$(CU_OBJS):%.o:%.cu | |
82 | - @echo "#######################CU_OBJS###############" | |
83 | - @echo $@ | |
84 | - $(NVCC) $(NFLAGS) -o $@ $< | |
85 | - | |
86 | - | |
87 | -.PHONY:clean | |
88 | -clean: | |
89 | - $(RM) $(OBJS) | |
90 | - $(RM) $(TARGET) | |
91 | - $(RM) $(DES_LIB)/$(TARGET) | |
92 | - $(RM) *~ | |
93 | - |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx deleted
1 | -#include "MutliSourceVideoProcess.h" | |
2 | - | |
3 | -#ifdef _MSC_VER | |
4 | -#include <io.h> | |
5 | -#include <direct.h> | |
6 | -#include "../putText.h" | |
7 | -#endif | |
8 | -#include <fstream> | |
9 | -#include <algorithm> | |
10 | -#include <thread> | |
11 | -#include <future> | |
12 | - | |
13 | -#include "face_detect.h" | |
14 | -#include "CropImg.h" | |
15 | -//#include <strsafe.h> | |
16 | -//#include <shlwapi.h> | |
17 | -//#include <DbgHelp.h> | |
18 | -//#pragma comment(lib, "DbgHelp.Lib") | |
19 | -//#pragma comment(lib, "ShLwApi.lib") | |
20 | -//********************************************************// | |
21 | -//1.Ϊʲô��ʱ�ص�index=2��ȴδ�����ﳵ�ķ�������Ϊindex�ں�����Ϊ��2�����Ǵ�ʱ�Ŀ��ղ�������֮ǰ�Ŀ��գ����Կ���δ���£�����ͼ���С����Ϊ112*224 | |
22 | - | |
23 | -#define AUTHORIZATION | |
24 | -//#define DQ_AUTHORIZATION | |
25 | - | |
26 | -#include<boost/thread.hpp> | |
27 | - | |
28 | -#ifdef DQ_AUTHORIZATION | |
29 | -#include "license_validator.h" | |
30 | -#ifdef _MSC_VER | |
31 | -#define productSN "2AC69C4638EF46c884BD2BF132FF41D9" //��ǧ����-������ȨID | |
32 | -#else | |
33 | -#define productSN "683E9D5E56474da5A4C2D3EA9A00568E" //��ǧ����-������ȨID | |
34 | -#endif | |
35 | -#endif | |
36 | - | |
37 | -#ifdef AUTHORIZATION | |
38 | -#include "authority.h" | |
39 | -#ifdef _MSC_VER | |
40 | -#define productSN "4ACFCBE67EF645AB8F0B4CFCDD1926F1" //WINDOWS�����Ʒϵ�к� | |
41 | -#else | |
42 | -#define productSN "4FD45501D5104F0C8C4BE530FC872F46" //LINUX�����Ʒϵ�к� | |
43 | -//#define productSN "7CF8B4797F9E441686145BED07F662DE" //LINUX�����Ʒϵ�к� | |
44 | -#endif | |
45 | -#endif | |
46 | - | |
47 | -#include "../DxDecoder/ColorSpace.h" | |
48 | - | |
49 | -//#define LOG_INFO //�Ƿ������ٴ�ӡ | |
50 | -// #define SKIP_FRMAE 5 //��֡֡�� | |
51 | -#define EXTIME 500 | |
52 | - | |
53 | -static int TaskID = 0; | |
54 | - | |
55 | -auto show_gpu_syimage_ = [](sy_img& cur_frame) { | |
56 | - | |
57 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.w_ * cur_frame.h_]; | |
58 | - cudaMemcpy(cpu_data, cur_frame.data_, 3 * cur_frame.w_ * cur_frame.h_ * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
59 | - cv::Mat img(cur_frame.h_, cur_frame.w_, CV_8UC3, cpu_data); | |
60 | - | |
61 | - cv::imshow("img", img); | |
62 | - cv::waitKey(0); | |
63 | - delete[] cpu_data; | |
64 | -}; | |
65 | - | |
66 | -auto show_gpu_image_ = [](DxGPUFrame& cur_frame) { | |
67 | - | |
68 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; | |
69 | - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
70 | - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); | |
71 | - | |
72 | - cv::imshow("img2", img); | |
73 | - cv::waitKey(0); | |
74 | - delete[] cpu_data; | |
75 | -}; | |
76 | - | |
77 | -auto show_gpu_image_withrect_ = [](DxGPUFrame& cur_frame, sy_rect &rect) { | |
78 | - | |
79 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; | |
80 | - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
81 | - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); | |
82 | - cv::rectangle(img, cv::Rect(rect.left_, rect.top_, rect.width_, rect.height_), cv::Scalar(25, 25, 250), 2, 8, 0); | |
83 | - cv::imshow("ori", img); | |
84 | - cv::waitKey(0); | |
85 | - delete[] cpu_data; | |
86 | -}; | |
87 | - | |
88 | -auto show_gpu_image_withfdinfo_ = [](DxGPUFrame& cur_frame, fd_info &face_info) { | |
89 | - | |
90 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; | |
91 | - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
92 | - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); | |
93 | - | |
94 | - printf("%d %d\n", cur_frame.width , cur_frame.height); | |
95 | - for (int ii = 0; ii < 25; ii++) | |
96 | - { | |
97 | - printf("(%d %d) ", face_info.facial_fea_point[ii].x_, face_info.facial_fea_point[ii].y_); | |
98 | - 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)); | |
99 | - | |
100 | - } | |
101 | - //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); | |
102 | - | |
103 | - cv::Mat big_img; | |
104 | - cv::resize(img, big_img, cv::Size(400, 400)); | |
105 | - | |
106 | - | |
107 | - cv::imshow("ori33", img); | |
108 | - cv::imshow("ori44", big_img); | |
109 | - cv::waitKey(0); | |
110 | - delete[] cpu_data; | |
111 | -}; | |
112 | - | |
113 | -auto show_gpu_image_with2rect_ = [](DxGPUFrame& cur_frame, sy_rect &rect, sy_rect &rect2) { | |
114 | - | |
115 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; | |
116 | - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
117 | - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); | |
118 | - cv::rectangle(img, cv::Rect(rect.left_, rect.top_, rect.width_, rect.height_), cv::Scalar(25, 25, 250), 1, 8, 0); | |
119 | - cv::rectangle(img, cv::Rect(rect2.left_, rect2.top_, rect2.width_, rect2.height_), cv::Scalar(25, 250, 25), 1, 8, 0); | |
120 | - cv::imshow("ori2", img); | |
121 | - cv::waitKey(0); | |
122 | - delete[] cpu_data; | |
123 | -}; | |
124 | - | |
125 | -static long long get_cur_time_ms(){ | |
126 | - chrono::time_point<chrono::system_clock, chrono::milliseconds> tpMicro | |
127 | - = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now()); | |
128 | - | |
129 | - return tpMicro.time_since_epoch().count(); | |
130 | -} | |
131 | - | |
132 | -std::function<void(DxGPUFrame&)> show_gpu_img_func = show_gpu_image_; | |
133 | - | |
134 | -void check_thread(void* handle); | |
135 | -DWORD ThreadProcess(LPVOID param); | |
136 | - | |
137 | - | |
138 | -//std::ofstream g_os("./cudaMem.txt", std::ofstream::out | std::ofstream::trunc); | |
139 | -CMutliSourceVideoProcess::CMutliSourceVideoProcess() | |
140 | -{ | |
141 | -} | |
142 | - | |
143 | -// dump�ļ� | |
144 | -//static LONG WINAPI CustomExceptionCrashHandler(_In_ EXCEPTION_POINTERS *CONST pException) | |
145 | -//{ | |
146 | -// char dumpPath[MAX_PATH]; | |
147 | -// | |
148 | -// BOOL tempDump = FALSE; | |
149 | -// do { | |
150 | -// | |
151 | -// if (0 == GetTempPath(_countof(dumpPath), dumpPath)) | |
152 | -// break; | |
153 | -// | |
154 | -// // %temp%Ŀ¼���½�dump�ļ��� | |
155 | -// if (!PathAppend(dumpPath, "dump")) | |
156 | -// break; | |
157 | -// CreateDirectory(dumpPath, NULL); | |
158 | -// // dump�ļ�����dump�ļ��ļ��� ���Զ����� | |
159 | -// if (!PathAppend(dumpPath, "HSTProcessor")) | |
160 | -// break; | |
161 | -// | |
162 | -// SYSTEMTIME lclTm; | |
163 | -// GetLocalTime(&lclTm); | |
164 | -// char ext[29]; | |
165 | -// // dump�ļ�������ʱ���� | |
166 | -// 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))) | |
167 | -// break; | |
168 | -// if (FAILED(StringCchCat(dumpPath, _countof(dumpPath), ext))) | |
169 | -// break; | |
170 | -// | |
171 | -// tempDump = TRUE; | |
172 | -// } while (FALSE); | |
173 | -// HANDLE CONST dumpFile = CreateFile(dumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | |
174 | -// if (INVALID_HANDLE_VALUE == dumpPath) | |
175 | -// { | |
176 | -// return EXCEPTION_EXECUTE_HANDLER; | |
177 | -// } | |
178 | -// | |
179 | -// MINIDUMP_EXCEPTION_INFORMATION dumpInfo; | |
180 | -// dumpInfo.ThreadId = GetCurrentThreadId(); | |
181 | -// dumpInfo.ExceptionPointers = pException; | |
182 | -// dumpInfo.ClientPointers = TRUE; | |
183 | -// | |
184 | -// if (FAILED(MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL))) | |
185 | -// { | |
186 | -// CloseHandle(dumpFile); | |
187 | -// } | |
188 | -// CloseHandle(dumpFile); | |
189 | -// | |
190 | -// return EXCEPTION_EXECUTE_HANDLER; | |
191 | -//} | |
192 | - | |
193 | - | |
194 | -CMutliSourceVideoProcess::~CMutliSourceVideoProcess() | |
195 | -{ | |
196 | - //��־����ʼ�� | |
197 | - //DxUninitializeLog(); | |
198 | -} | |
199 | - | |
200 | -int CMutliSourceVideoProcess::FinishProcessThread() | |
201 | -{ | |
202 | - if (thrd_status == 0) | |
203 | - { | |
204 | - thrd.interrupt(); | |
205 | - thrd.join(); | |
206 | - thrd_status = -1; | |
207 | - } | |
208 | - | |
209 | - ProcessThread.interrupt(); //interrupt thread | |
210 | - ProcessThread.join(); //waiting thread finish | |
211 | - | |
212 | - VPT_Release(VPT_Handle); | |
213 | - m_face_det_module->face_det_module_release(); | |
214 | - | |
215 | - m_snaphot_helper.snapshot_helper_release(); | |
216 | - | |
217 | - return 1; | |
218 | -} | |
219 | - | |
220 | -int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc, VIDEO_FINISH_CALLBACK tFinishCallbackFunc) | |
221 | -{ | |
222 | - // checkGpuMem(); | |
223 | - licence_status = -1; | |
224 | - thrd_status = -1; | |
225 | - //SetUnhandledExceptionFilter(CustomExceptionCrashHandler); | |
226 | - | |
227 | - int ret = SUCCESS; | |
228 | - /*DxLogConfig sCfg = { 0 }; | |
229 | - sCfg.serviceID = vptParam.serviceID; | |
230 | - sCfg.limitSize = vptParam.limitSize; | |
231 | - strcpy(sCfg.name, vptParam.name); | |
232 | - strcpy(sCfg.path, vptParam.path); | |
233 | - DxInitializeLog(&sCfg);*/ | |
234 | - | |
235 | - /*printf("=====================��ȨERROR==================\n"); | |
236 | - printf("=====================��ȨERROR==================\n"); | |
237 | - printf("=====================��ȨERROR==================\n");*/ | |
238 | -#ifdef AUTHORIZATION | |
239 | -#ifdef _WIN32 | |
240 | - if (SUCCESS == (ret = sy_licence(productSN))) | |
241 | -#elif __linux__ | |
242 | - char wtime[15]; | |
243 | - memset(wtime, 0, 15); | |
244 | - char * time = wtime; | |
245 | - if (SUCCESS == (ret = sy_licence(productSN, &time))) | |
246 | -#endif | |
247 | -#else | |
248 | - ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2); | |
249 | - if (ret == SUCCESS) | |
250 | -#endif | |
251 | - { | |
252 | - cuInit(0); | |
253 | - int device_count = 0; | |
254 | - cuDeviceGetCount(&device_count); | |
255 | - | |
256 | - if (vptParam.gpuid >= device_count) | |
257 | - { | |
258 | - printf("\nGPU_ID PARAM WRONG, gpuid: %d device_count: %d\n", vptParam.gpuid, device_count); | |
259 | - return GPUID_PARAM_ERROR; | |
260 | - } | |
261 | - | |
262 | - CUdevice dev = 0; | |
263 | - size_t memSize = 0; | |
264 | - dev = vptParam.gpuid; | |
265 | - | |
266 | - CUresult rlt = CUDA_SUCCESS; | |
267 | - rlt = cuDeviceTotalMem(&memSize, dev); | |
268 | - | |
269 | - gpu_total_memory = (float)memSize / (1024 * 1024); | |
270 | - | |
271 | - if (gpu_total_memory < 9000) //8G�Դ棬С�ڴ淽�� | |
272 | - section_batch_size = 10; | |
273 | - else | |
274 | - section_batch_size = 20; | |
275 | - | |
276 | - if(vptParam.skip_frame > 0){ | |
277 | - // 默认值为5 | |
278 | - skip_frame_ = vptParam.skip_frame; | |
279 | - } | |
280 | - | |
281 | - VPTProcess_PARAM param{}; | |
282 | - //param.c = 3; | |
283 | - param.mode = DEVICE_GPU; | |
284 | - param.gpuid = vptParam.gpuid; | |
285 | - //param.threshold = 0.6; | |
286 | - param.threshold = 0.5; | |
287 | - param.engine = ENGINE_TENSORRT; | |
288 | - param.max_batch = section_batch_size; | |
289 | - param.serialize_file = "./serialize_file/VPT"; | |
290 | - param.auth_license = vptParam.auth_license; | |
291 | - mgpuid = vptParam.gpuid; | |
292 | - VPT_Handle = NULL; | |
293 | - ret = VPT_Init(VPT_Handle, param); | |
294 | - if (0 != ret) | |
295 | - return ret; | |
296 | - | |
297 | - m_face_det_module = nullptr; | |
298 | - if (vptParam.face_det_config == SY_CONFIG_OPEN) | |
299 | - { | |
300 | - m_face_det_module = new face_det_module(); | |
301 | - printf("begin init face det\n"); | |
302 | - m_face_det_module->face_det_module_init(vptParam.gpuid, vptParam.auth_license); | |
303 | - } | |
304 | - | |
305 | - viewTaskID = -1; | |
306 | - TaskinPlay = 0; | |
307 | - TotalTask = 0; | |
308 | - capacity = 20; | |
309 | - VPTResult.resize(capacity); | |
310 | - //dwThreadID = 0; | |
311 | - ProcessFlag = false; | |
312 | - SourceFlag = false; | |
313 | - | |
314 | - mModeSnapshotVideo = "cpu"; | |
315 | - mModeSnapshotLittle = "cpu"; | |
316 | - | |
317 | - taskFinishCallbackFunc = nullptr; | |
318 | - if (tFinishCallbackFunc != nullptr) | |
319 | - taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1); | |
320 | - | |
321 | - taskObjInfoCallbackFunc = nullptr; | |
322 | - if (tObjInfoCallbackFunc != nullptr) | |
323 | - taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1); | |
324 | - | |
325 | - minDistance[0] = minDistance[2] = 35; //left right | |
326 | - minDistance[1] = minDistance[3] = 50; //top bottom | |
327 | - | |
328 | - m_hp_analysis_config = vptParam.hp_analysis_config; | |
329 | - m_hcp_analysis_config = vptParam.hcp_analysis_config; | |
330 | - m_vehicle_analysis_config = vptParam.vehicle_analysis_config; | |
331 | - m_hf_recg_config = vptParam.hf_recg_config; | |
332 | - m_hcf_recg_config = vptParam.hcf_recg_config; | |
333 | - m_vcf_recg_config = vptParam.vcf_recg_config; | |
334 | - m_face_det_config = vptParam.face_det_config; | |
335 | - | |
336 | - m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, vptParam.auth_license, vptParam.wait_framecount, m_hp_analysis_config, \ | |
337 | - 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); | |
338 | - if (ret == SUCCESS) //�ɹ� | |
339 | - { | |
340 | - licence_status = 0; | |
341 | -#ifdef AUTHORIZATION | |
342 | - thrd = boost::thread(check_thread, this); | |
343 | -#endif | |
344 | - thrd_status = 0; | |
345 | - } | |
346 | - | |
347 | - } | |
348 | - else | |
349 | - { | |
350 | - return AUTHOR_ERROR; | |
351 | - } | |
352 | -/* | |
353 | -#ifdef AUTHORIZATION | |
354 | -#ifdef __linux__ | |
355 | - if (wtime) | |
356 | - { | |
357 | - delete[] wtime; | |
358 | - wtime = NULL; | |
359 | - } | |
360 | -#endif | |
361 | -#endif */ // debug by zsh | |
362 | - return ret; | |
363 | -} | |
364 | - | |
365 | -void CMutliSourceVideoProcess::FinishDecode(const int taskID) | |
366 | -{ | |
367 | - boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(400)); | |
368 | - | |
369 | - for (int i = 0; i < tasks.size(); i++) | |
370 | - { | |
371 | - if (tasks[i].taskID == taskID && tasks[taskID].taskTcuvid != NULL) | |
372 | - { | |
373 | - tasks[taskID].taskState == FINISH; | |
374 | - tasks[taskID].taskTcuvid->DxCloseDecoder(); | |
375 | - delete tasks[taskID].taskTcuvid; | |
376 | - tasks[taskID].taskTcuvid = NULL; | |
377 | - printf("-----------------------finish task: %d-----------------------\n", taskID); | |
378 | - break; | |
379 | - } | |
380 | - } | |
381 | - | |
382 | -} | |
383 | - | |
384 | -void CMutliSourceVideoProcess::FinishTask(const int taskID) | |
385 | -{ | |
386 | - for (int i = 0; i < tasks.size(); i++) | |
387 | - { | |
388 | - if (tasks[i].taskID == taskID) | |
389 | - { | |
390 | - //printf("first begin finish\n"); | |
391 | - if (tasks[i].taskState == PLAY) TaskinPlay--; | |
392 | - tasks[i].taskState = FINISH; | |
393 | - tasks[i].taskFileSource = nullptr; | |
394 | - tasks[i].taskObjCallbackFunc = nullptr; | |
395 | - tasks[i].taskRealTimeCallbackFunc = nullptr; | |
396 | - | |
397 | - | |
398 | - 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); //�Ƿ�����������ʶ��); | |
399 | - | |
400 | - if (tasks[i].folderName) | |
401 | - { | |
402 | - delete tasks[i].folderName; | |
403 | - tasks[i].folderName = nullptr; | |
404 | - } | |
405 | - | |
406 | - | |
407 | - if (tasks[i].folderNameLittle) | |
408 | - { | |
409 | - delete tasks[i].folderNameLittle; | |
410 | - tasks[i].folderNameLittle = nullptr; | |
411 | - } | |
412 | - | |
413 | - tasks[i].frameImage.release(); | |
414 | - | |
415 | - | |
416 | - if (tasks[i].task_algorithm_data.frame) | |
417 | - { | |
418 | - cudaFree(tasks[i].task_algorithm_data.frame); | |
419 | - tasks[i].task_algorithm_data.frame = nullptr; | |
420 | - } | |
421 | - | |
422 | - FinishTaskTracker(VPT_Handle, taskID); | |
423 | - | |
424 | - if (viewTaskID == taskID) viewTaskID = -1; | |
425 | - | |
426 | - | |
427 | - break; | |
428 | - } | |
429 | - } | |
430 | -} | |
431 | - | |
432 | -void CMutliSourceVideoProcess::PauseTask(const int taskID) | |
433 | -{ | |
434 | - for (int i = 0; i < tasks.size(); i++) | |
435 | - { | |
436 | - if (tasks[i].taskID == taskID) | |
437 | - { | |
438 | - if (tasks[i].taskState == PLAY) TaskinPlay--; | |
439 | - tasks[i].taskState = PAUSE; | |
440 | - PauseTaskTracker(VPT_Handle, taskID); | |
441 | - tasks[i].taskTcuvid->PauseDecoder(); | |
442 | - if (viewTaskID == taskID) viewTaskID = -1; | |
443 | - printf("-----------------------pasue task: %d-----------------------\n", taskID); | |
444 | - break; | |
445 | - } | |
446 | - } | |
447 | -} | |
448 | - | |
449 | -void CMutliSourceVideoProcess::RestartTask(const int taskID) | |
450 | -{ | |
451 | - for (int i = 0; i < tasks.size(); i++) | |
452 | - { | |
453 | - if (tasks[i].taskID == taskID) | |
454 | - { | |
455 | - tasks[i].taskState = PLAY; | |
456 | - TaskinPlay++; | |
457 | - RestartTaskTraker(VPT_Handle, taskID); | |
458 | - tasks[i].taskTcuvid->ResumeDecoder(); | |
459 | - printf("-----------------------restart task: %d-----------------------\n", taskID); | |
460 | - break; | |
461 | - } | |
462 | - } | |
463 | -} | |
464 | - | |
465 | -//ʵʱ�鿴�ӿ� �ɿ���һ·��ʵʱ�鿴������·�ķ������OSD��Ȼ����ͨ���ص��������ظ��û� | |
466 | -void CMutliSourceVideoProcess::ViewTask(const int taskID) | |
467 | -{ | |
468 | - if (tasks.size() > taskID && tasks[taskID].taskState == PLAY) | |
469 | - { | |
470 | - viewTaskID = taskID; | |
471 | - printf("-----------------------view task: %d-----------------------\n", taskID); | |
472 | - } | |
473 | - else | |
474 | - printf("Only can view playing task!"); | |
475 | -} | |
476 | - | |
477 | -//����ʵʱ�鿴�ӿڣ��ر�ʵʱ����ķ��� | |
478 | -void CMutliSourceVideoProcess::FinishViewTask() | |
479 | -{ | |
480 | - viewTaskID = -1; | |
481 | - printf("-----------------------finish view task-----------------------\n"); | |
482 | -} | |
483 | - | |
484 | - | |
485 | -//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*/) | |
486 | -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 | |
487 | -{ | |
488 | - //checkGpuMem(); | |
489 | - std::lock_guard<std::mutex> l(_tx_add_task); | |
490 | - using std::placeholders::_1; | |
491 | - // printf("begin real add task\n"); | |
492 | - if (TaskinPlay >= capacity) | |
493 | - { | |
494 | - //cout << "********************** resize capacity *************************" << endl; | |
495 | - capacity *= 2; | |
496 | - VPTResult.resize(capacity); | |
497 | - } | |
498 | - | |
499 | - string sVideoFileName = videoFileName; | |
500 | - | |
501 | - string target = "file://"; | |
502 | - int pos = sVideoFileName.find(target); | |
503 | - if (pos == 0) { | |
504 | - int n = target.size(); | |
505 | - sVideoFileName = sVideoFileName.erase(pos, n); | |
506 | - } | |
507 | - pos = sVideoFileName.find_first_of('?'); | |
508 | - if (pos != string::npos) { | |
509 | - sVideoFileName = sVideoFileName.substr(0, pos); | |
510 | - } | |
511 | - | |
512 | - Task new_task = {}; | |
513 | - new_task.taskID = TotalTask; | |
514 | - new_task.taskFileSource = videoFileName; | |
515 | - memcpy(new_task.task_min_boxsize, minBoxsize, sizeof(sy_rect)* DETECTTYPE); | |
516 | - | |
517 | - | |
518 | - DxConfig cfg = { 0 }; | |
519 | - cfg.devId = mgpuid; | |
520 | - cfg.decMode = 0; | |
521 | - cfg.colorFmt = 0; | |
522 | - cfg.forceTcp = false; | |
523 | - cfg.type = DX_DECODER_TYPE_SFXLAB; | |
524 | - new_task.taskTcuvid = new DxDecoderWrap(&cfg); | |
525 | - if (NULL == new_task.taskTcuvid) | |
526 | - { | |
527 | - printf("Add New DxDecoder Failed!"); | |
528 | - AddTaskSucFlag = -1; | |
529 | - return false; | |
530 | - } | |
531 | - | |
532 | - if (new_task.taskTcuvid->DxOpenDecoder(new_task.taskFileSource, skip_frame_) != 0) | |
533 | - { | |
534 | - cout << "Add Task Failed! Please check you video file name!" << endl; | |
535 | - delete new_task.taskTcuvid; | |
536 | - new_task.taskTcuvid = NULL; | |
537 | - AddTaskSucFlag = -1; | |
538 | - return false; | |
539 | - } | |
540 | - | |
541 | - int tmp_total_frame = new_task.taskTcuvid->DxGetFrameCount(); | |
542 | - | |
543 | - printf("finish add codec. tmp_total_frame: %d \n", tmp_total_frame); | |
544 | - | |
545 | - new_task.taskState = PLAY; | |
546 | - new_task.task_algorithm_data.frame = NULL; | |
547 | - new_task.taskFrameCount = 0; | |
548 | - new_task.taskLastFrameCount = 0; | |
549 | - | |
550 | - new_task.taskObjCallbackFunc = nullptr; | |
551 | - if (objCallbackFunc != nullptr) | |
552 | - new_task.taskObjCallbackFunc = std::bind(objCallbackFunc, this, std::placeholders::_1); | |
553 | - | |
554 | - new_task.taskRealTimeCallbackFunc = nullptr; | |
555 | - if (realTimeCallbackFunc != nullptr) | |
556 | - new_task.taskRealTimeCallbackFunc = std::bind(realTimeCallbackFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); | |
557 | - | |
558 | - new_task.taskTotalFrameCount = tmp_total_frame; | |
559 | - if (resultFolderLittle == NULL) | |
560 | - { | |
561 | - new_task.folderNameLittle = NULL; | |
562 | - } | |
563 | - else | |
564 | - { | |
565 | - new_task.folderNameLittle = new char[strlen(resultFolderLittle) + 2]{}; | |
566 | - strcpy(new_task.folderNameLittle, resultFolderLittle); | |
567 | - | |
568 | - int length = strlen(new_task.folderNameLittle); | |
569 | - if (new_task.folderNameLittle[length - 1] != '\\' && new_task.folderNameLittle[length - 1] != '/') | |
570 | - { | |
571 | - new_task.folderNameLittle[length] = '/'; | |
572 | - new_task.folderNameLittle[length + 1] = '\0'; | |
573 | - } | |
574 | - | |
575 | - CreateResultFolder(new_task.folderNameLittle, ""); | |
576 | - } | |
577 | - | |
578 | - | |
579 | - if (resultFolder == NULL) | |
580 | - { | |
581 | - new_task.folderName = NULL; | |
582 | - } | |
583 | - else | |
584 | - { | |
585 | - new_task.folderName = new char[strlen(resultFolder) + 2]{}; | |
586 | - strcpy(new_task.folderName, resultFolder); | |
587 | - | |
588 | - int length = strlen(new_task.folderName); | |
589 | - if (new_task.folderName[length - 1] != '\\' && new_task.folderName[length - 1] != '/') | |
590 | - { | |
591 | - new_task.folderName[length] = '/'; | |
592 | - new_task.folderName[length + 1] = '\0'; | |
593 | - } | |
594 | - | |
595 | - CreateResultFolder(new_task.folderName, ""); | |
596 | - } | |
597 | - | |
598 | - if (resultFolderface == NULL) | |
599 | - { | |
600 | - new_task.folderNameFace = NULL; | |
601 | - } | |
602 | - else | |
603 | - { | |
604 | - new_task.folderNameFace = new char[strlen(resultFolderface) + 2]{}; | |
605 | - strcpy(new_task.folderNameFace, resultFolderface); | |
606 | - | |
607 | - int length = strlen(new_task.folderNameFace); | |
608 | - if (new_task.folderNameFace[length - 1] != '\\' && new_task.folderNameFace[length - 1] != '/') | |
609 | - { | |
610 | - new_task.folderNameFace[length] = '/'; | |
611 | - new_task.folderNameFace[length + 1] = '\0'; | |
612 | - } | |
613 | - | |
614 | - CreateResultFolder(new_task.folderNameFace, ""); | |
615 | - } | |
616 | - | |
617 | - // printf("finish create folder\n"); | |
618 | - | |
619 | - //Sleep(10); | |
620 | - //std::cout << "CreateResultFolder" << std::endl; | |
621 | - TASK_INFO new_task_info = {}; | |
622 | - new_task_info.image_folder = new_task.folderName; | |
623 | - new_task_info.snapshot_folder = new_task.folderNameLittle; | |
624 | - new_task_info.snapshot_folder_face = new_task.folderNameFace; | |
625 | - new_task_info.task_total_framecount = new_task.taskTotalFrameCount; | |
626 | - new_task_info._on_image_display = on_image_display; | |
627 | - new_task_info.jpeg_quality_ = jpeg_quality; //debug by zsh | |
628 | - new_task_info.obj_callback = new_task.taskObjCallbackFunc; | |
629 | - m_snaphot_helper.add_task_info(new_task.taskID, new_task_info); | |
630 | - | |
631 | - TotalTask++; | |
632 | - TaskinPlay++; | |
633 | - tasks.push_back(new_task); | |
634 | - | |
635 | - // printf("finish push tasks\n"); | |
636 | - | |
637 | - //return 1; | |
638 | - //std::cout<<__LINE__<<"of"<<__FILE__<<"debug\n"; | |
639 | - if (!ProcessFlag) | |
640 | - { | |
641 | - /*for (int num = 0; num < 5; ++num) | |
642 | - {*/ | |
643 | - //create_thread()��һ���������������Դ���thead���������̣߳�ͬʱ�����ڲ���list | |
644 | - // group.create_thread(boost::bind(&runchild , num)) ; | |
645 | - //saveSnapshotsThreadGroup.create_thread(boost::bind(SnapshotThreadProcess, this, 0)); | |
646 | - //} | |
647 | - ProcessThread = boost::thread(ThreadProcess, this); | |
648 | - //std::cout << "begin algorithm" << std::endl; | |
649 | - ProcessFlag = true; | |
650 | - } | |
651 | - | |
652 | - printf("-----------------------add task: %d-----------------------\n", tasks.size() - 1); | |
653 | - AddTaskSucFlag = 1; | |
654 | - return true; | |
655 | -} | |
656 | - | |
657 | -int CMutliSourceVideoProcess::AddOperator(task_param tparam) | |
658 | -{ | |
659 | - //boost::mutex::scoped_lock lock(process_thread_mutex); | |
660 | - | |
661 | - if (!ProcessFlag) | |
662 | - { | |
663 | - //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); | |
664 | - 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 | |
665 | - boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(500)); | |
666 | - } | |
667 | - else | |
668 | - { | |
669 | - // printf("add first task in operator queue\n"); | |
670 | - std::unique_lock<std::mutex> l(taskMutex); | |
671 | - AddTaskSucFlag = 0; | |
672 | - Operator newOper; | |
673 | - newOper.changeTaskID = 0; | |
674 | - newOper.changeTaskOperator = ADDTASK; | |
675 | - newOper.videoFileName = tparam.video_filename; | |
676 | - newOper.resultFolderLittleName = tparam.result_folder_little; | |
677 | - newOper.result_folder_face = tparam.result_folder_face; | |
678 | - newOper.resultFolderName = tparam.result_folder; | |
679 | - newOper.on_image_display = tparam.on_image_display; | |
680 | - newOper.jpeg_quality = tparam.jpeg_quality; //debug by zsh | |
681 | - newOper.taskObjCallbackFunc = tparam.obj_snapshot_callback_func; | |
682 | - newOper.taskRealTimeCallbackFunc = tparam.rt_view_callback_func; | |
683 | - memcpy(newOper.minBoxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); | |
684 | - TaskOperatorQ.push_back(newOper); | |
685 | - taskCondVar.wait_for(l, std::chrono::seconds(20)); | |
686 | - // printf("finish first task in operator queue\n"); | |
687 | - } | |
688 | - | |
689 | - int addRes = -1; | |
690 | - int newTaskID = TaskID++; | |
691 | - | |
692 | - if (AddTaskSucFlag == 1) | |
693 | - { | |
694 | - addRes = newTaskID; | |
695 | - } | |
696 | - else if (AddTaskSucFlag == -1) | |
697 | - { | |
698 | - addRes = -1; | |
699 | - TaskID--; | |
700 | - } | |
701 | - else if (AddTaskSucFlag == 0) | |
702 | - { | |
703 | - Operator newOper = TaskOperatorQ.back(); | |
704 | - if (strcmp(newOper.videoFileName, tparam.video_filename) == 0) | |
705 | - { | |
706 | - TaskOperatorQ.pop_back(); | |
707 | - } | |
708 | - cout << "Failed Add New Task! Algorithm Process Error! " << endl; | |
709 | - } | |
710 | - | |
711 | - return addRes; | |
712 | -} | |
713 | - | |
714 | -int CMutliSourceVideoProcess::get_task_progress(int taskid, double &progress) | |
715 | -{ | |
716 | - int ret = 0; | |
717 | - for (auto &item : tasks) | |
718 | - { | |
719 | - if (item.taskID == taskid) | |
720 | - { | |
721 | - progress = (double)item.taskFrameCount / (double)item.taskTotalFrameCount; | |
722 | - return 0; | |
723 | - } | |
724 | - } | |
725 | - return -1; | |
726 | - | |
727 | -} | |
728 | - | |
729 | -void CMutliSourceVideoProcess::AddOperator(int taskID, int taskOper) | |
730 | -{ | |
731 | - if (taskOper > 0 && taskOper < 4) | |
732 | - { | |
733 | - Operator newOper = {}; | |
734 | - newOper.changeTaskID = taskID; | |
735 | - newOper.changeTaskOperator = TaskOperator(taskOper); | |
736 | - newOper.videoFileName = NULL; | |
737 | - //TaskOperatorQ.push(newOper); | |
738 | - TaskOperatorQ.push_back(newOper); | |
739 | - } | |
740 | -} | |
741 | - | |
742 | -void CMutliSourceVideoProcess::OperatorTask() | |
743 | -{ | |
744 | - while (!TaskOperatorQ.empty()) | |
745 | - { | |
746 | - Operator newOperator = TaskOperatorQ.front(); | |
747 | - TaskOperatorQ.pop_front(); | |
748 | - | |
749 | - switch (newOperator.changeTaskOperator) | |
750 | - { | |
751 | - case ADDTASK: | |
752 | - //AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.result_folder_face, newOperator.on_image_display, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); | |
753 | - 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 | |
754 | - break; | |
755 | - case PAUSETASK: | |
756 | - PauseTask(newOperator.changeTaskID); | |
757 | - break; | |
758 | - case RESTARTTASK: | |
759 | - RestartTask(newOperator.changeTaskID); | |
760 | - break; | |
761 | - case FINISHTASK: | |
762 | - FinishTask(newOperator.changeTaskID); | |
763 | - break; | |
764 | - default: | |
765 | - break; | |
766 | - } | |
767 | - | |
768 | - } | |
769 | -} | |
770 | - | |
771 | - | |
772 | -int CMutliSourceVideoProcess::SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value) | |
773 | -{ | |
774 | - if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT) | |
775 | - { | |
776 | - if (m_face_det_config == SY_CONFIG_OPEN) | |
777 | - { | |
778 | - m_snaphot_helper.save_face_snapshot(obj_key); | |
779 | - } | |
780 | - | |
781 | - if (m_hp_analysis_config == SY_CONFIG_OPEN || m_hf_recg_config == SY_CONFIG_OPEN) | |
782 | - { | |
783 | - m_snaphot_helper.save_snapshot(obj_key); | |
784 | - m_snaphot_helper.hp_analysis(obj_key); | |
785 | - } | |
786 | - else | |
787 | - { | |
788 | - m_snaphot_helper.save_without_analysis(obj_key); | |
789 | - } | |
790 | - } | |
791 | - else if ((1 == obj_value.index.index || 2 == obj_value.index.index) && obj_value.snapShotLittle.width == HCP_WIDTH && obj_value.snapShotLittle.height == HCP_HEIGHT) | |
792 | - { | |
793 | - if (m_hcp_analysis_config == SY_CONFIG_OPEN || m_hcf_recg_config == SY_CONFIG_OPEN) | |
794 | - { | |
795 | - m_snaphot_helper.save_snapshot(obj_key); | |
796 | - m_snaphot_helper.hcp_analysis(obj_key); | |
797 | - } | |
798 | - else | |
799 | - { | |
800 | - m_snaphot_helper.save_without_analysis(obj_key); | |
801 | - } | |
802 | - } | |
803 | - 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) | |
804 | - { | |
805 | - //VEHICLEAnalysis(obj_key, obj_value); | |
806 | - if (m_vehicle_analysis_config == SY_CONFIG_OPEN || m_vcf_recg_config == SY_CONFIG_OPEN) | |
807 | - { | |
808 | - m_snaphot_helper.save_snapshot(obj_key); | |
809 | - m_snaphot_helper.vehicle_analysis(obj_key); | |
810 | - } | |
811 | - else | |
812 | - { | |
813 | - m_snaphot_helper.save_without_analysis(obj_key); | |
814 | - } | |
815 | - | |
816 | - } | |
817 | - else | |
818 | - { | |
819 | - m_snaphot_helper.save_without_analysis(obj_key); | |
820 | - } | |
821 | - | |
822 | - return 0; | |
823 | -} | |
824 | - | |
825 | - | |
826 | -//#define LOG_INFO | |
827 | -void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId) | |
828 | -{ | |
829 | - if (objCount == 0) | |
830 | - { | |
831 | - video_object_info newObjInfo; | |
832 | - newObjInfo.task_id = taskId; | |
833 | - newObjInfo.task_frame_count = taskFrameCount; | |
834 | - newObjInfo.object_id = -1; | |
835 | - newObjInfo.left = 0; | |
836 | - newObjInfo.right = 0; | |
837 | - newObjInfo.top = 0; | |
838 | - newObjInfo.bottom = 0; | |
839 | - newObjInfo.index = 0; | |
840 | - newObjInfo.confidence = 0; | |
841 | - | |
842 | - if (taskObjInfoCallbackFunc != nullptr) | |
843 | - taskObjInfoCallbackFunc(&newObjInfo); | |
844 | - } | |
845 | - else | |
846 | - { | |
847 | - for (int c = 0; c < objCount; c++) | |
848 | - { | |
849 | - OBJ_KEY newObj = { taskId, obj[c].id }; | |
850 | - video_object_info newObjInfo; | |
851 | - newObjInfo.task_id = taskId; | |
852 | - newObjInfo.task_frame_count = taskFrameCount; | |
853 | - newObjInfo.object_id = obj[c].id; | |
854 | - newObjInfo.left = obj[c].left; | |
855 | - newObjInfo.right = obj[c].right; | |
856 | - newObjInfo.top = obj[c].top; | |
857 | - newObjInfo.bottom = obj[c].bottom; | |
858 | - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) | |
859 | - newObjInfo.index = obj[c].index; | |
860 | - else | |
861 | - newObjInfo.index = m_snaphot_helper.snapShotInfo[newObj].index.index; | |
862 | - newObjInfo.confidence = obj[c].confidence; | |
863 | - if (taskObjInfoCallbackFunc != nullptr) | |
864 | - { | |
865 | - taskObjInfoCallbackFunc(&newObjInfo); | |
866 | - } | |
867 | - } | |
868 | - | |
869 | - } | |
870 | -} | |
871 | -DWORD ThreadProcess(LPVOID param) | |
872 | -{ | |
873 | - set<int> k; | |
874 | - int count = 0; | |
875 | - sy_img * batch_img = new sy_img[20]{}; | |
876 | - | |
877 | - DxGPUFrame frame = {}; | |
878 | - | |
879 | - CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)param; | |
880 | - | |
881 | - cudaSetDevice(pThreadParam->mgpuid); | |
882 | - | |
883 | - // CUdevice cuDevice; | |
884 | - // cuDeviceGet(&cuDevice, pThreadParam->mgpuid); | |
885 | - // CUcontext context; | |
886 | - // cuCtxCreate(&context, 0, cuDevice); | |
887 | - // cuCtxPushCurrent(context); | |
888 | - | |
889 | - // cuda_common::setColorSpace2(ITU709, 0); | |
890 | - // cudaMalloc((void**)&pThreadParam->FrameTemp, 3 * 4096 * 4096 * sizeof(unsigned char)); | |
891 | - int total_count = 0; | |
892 | - long long begintime1 =get_cur_time_ms(); | |
893 | - | |
894 | - int process_times = 0; | |
895 | - //std::string osPath = "./vptlog"; | |
896 | - //osPath += std::to_string(pThreadParam->mgpuid); | |
897 | - //osPath += ".txt"; | |
898 | - //std::ofstream os(osPath, std::ofstream::out | std::ofstream::trunc); | |
899 | - //os << unitbuf; | |
900 | - //try | |
901 | - | |
902 | - long long last_time = get_cur_time_ms(); | |
903 | - | |
904 | - { | |
905 | - while (1) | |
906 | - { | |
907 | - if (pThreadParam->licence_status <= -3) | |
908 | - { | |
909 | - printf("authority failed!\n"); | |
910 | - break; | |
911 | - } | |
912 | - | |
913 | - double time_val, time_val_p = 0; | |
914 | - { | |
915 | - std::lock_guard<std::mutex> l(pThreadParam->taskMutex); | |
916 | - pThreadParam->OperatorTask(); | |
917 | - } | |
918 | - pThreadParam->taskCondVar.notify_all(); | |
919 | - | |
920 | - int curTaskSize = pThreadParam->tasks.size(); | |
921 | - | |
922 | - count = 0; | |
923 | - static int ncount = 0; | |
924 | - map<int, vector<int>> finishTaskDeleteObj; | |
925 | - int curPlayTaskCount = 0; | |
926 | - | |
927 | - //�жϵ�ǰPLAY����Ľ���״̬��������ڽ����쳣��·������������·���� | |
928 | - for (int i = 0; i < curTaskSize; i++) | |
929 | - { | |
930 | - if ((pThreadParam->tasks[i].taskState == PLAY || pThreadParam->tasks[i].taskState == DECODEERROR)) | |
931 | - { | |
932 | - if (!pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) | |
933 | - { | |
934 | - cudaError_t cudaStatus = cudaGetLastError(); | |
935 | - if (cudaStatus != cudaSuccess) { | |
936 | - printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); | |
937 | - } | |
938 | - | |
939 | - cout << "***************** Task " << i << " is Finished *****************" << endl; | |
940 | - pThreadParam->tasks[i].taskState = FINISH; | |
941 | - | |
942 | - pThreadParam->FinishTask(pThreadParam->tasks[i].taskID); | |
943 | - | |
944 | - pThreadParam->tasks[i].taskTcuvid->DxCloseDecoder(); | |
945 | - delete pThreadParam->tasks[i].taskTcuvid; | |
946 | - pThreadParam->tasks[i].taskTcuvid = NULL; | |
947 | - int taskid = pThreadParam->tasks[i].taskID; | |
948 | - | |
949 | - //ѭ���ȴ� ֱ��finished_analysis_ss_info�����и�·Ŀ�궼�Ѿ����ظ��û����ſ��������������� | |
950 | - std::unique_lock<std::mutex> lock(pThreadParam->m_snaphot_helper.analysisThreadMutex); | |
951 | - 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<OBJ_KEY, video_object_snapshot> & item) ->bool { | |
952 | - if (item.first.videoID == taskid) | |
953 | - { | |
954 | - return true; | |
955 | - } | |
956 | - else | |
957 | - { | |
958 | - return false; | |
959 | - } | |
960 | - | |
961 | - }) != pThreadParam->m_snaphot_helper.finished_analysis_ss_info.end()) | |
962 | - { | |
963 | - lock.unlock(); | |
964 | - std::this_thread::yield(); | |
965 | - std::this_thread::sleep_for(std::chrono::milliseconds(100)); | |
966 | - lock.lock(); | |
967 | - } | |
968 | - | |
969 | - //�ص�֪ͨ�û� ��·����������� | |
970 | - if (pThreadParam->taskFinishCallbackFunc != nullptr) | |
971 | - { | |
972 | - std::lock_guard<std::mutex> l(pThreadParam->m_snaphot_helper.callback_tx); | |
973 | - pThreadParam->taskFinishCallbackFunc(pThreadParam->tasks[i].taskID); | |
974 | - } | |
975 | - | |
976 | - pThreadParam->TaskinPlay--; | |
977 | - } | |
978 | - } | |
979 | - | |
980 | - if (pThreadParam->tasks[i].taskState == FINISH) | |
981 | - count++; | |
982 | - } | |
983 | - | |
984 | - //�������������FINISH״̬ | |
985 | - if (count >= pThreadParam->tasks.size()) //have no decode video, break | |
986 | - { | |
987 | - { | |
988 | - std::lock_guard<std::mutex> l(pThreadParam->taskMutex); | |
989 | - //�ж���������ȴ������Ƿ����µ��������� | |
990 | - if (pThreadParam->HasNewTask()) | |
991 | - { | |
992 | - continue; | |
993 | - } | |
994 | - else | |
995 | - { | |
996 | - //std::this_thread::sleep_for(std::chrono::milliseconds(40)); | |
997 | - //continue; | |
998 | - //printf("802 set ProcessFlag false\n"); | |
999 | - | |
1000 | - //Sleep(10); | |
1001 | - //continue; | |
1002 | - | |
1003 | - //printf("0708\n"); | |
1004 | - //pThreadParam->ProcessFlag = false; | |
1005 | - break; | |
1006 | - } | |
1007 | - } | |
1008 | - } | |
1009 | - | |
1010 | - //��ǰû��PLAY������ ѭ���ȴ� | |
1011 | - curPlayTaskCount = pThreadParam->TaskinPlay; | |
1012 | - if (curPlayTaskCount <= 0) { | |
1013 | - Sleep(30); | |
1014 | - continue; | |
1015 | - } | |
1016 | - | |
1017 | - k.clear(); | |
1018 | - pThreadParam->TaskinPlayID.clear(); | |
1019 | - | |
1020 | - //��ȡ�������� | |
1021 | - getdata_flag: | |
1022 | - for (int i = 0; i < curTaskSize; i++) | |
1023 | - { | |
1024 | - if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) | |
1025 | - { | |
1026 | - if (pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&frame) == 0) | |
1027 | - { | |
1028 | - if (!pThreadParam->tasks[i].task_algorithm_data.frame && frame.width > 0 && frame.height > 0) | |
1029 | - { | |
1030 | - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->tasks[i].task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(unsigned char)); | |
1031 | - if (cudaStatus != cudaSuccess) { | |
1032 | - fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); | |
1033 | - break; | |
1034 | - } | |
1035 | - | |
1036 | - pThreadParam->tasks[i].task_algorithm_data.height = frame.height; | |
1037 | - pThreadParam->tasks[i].task_algorithm_data.width = frame.width; | |
1038 | - pThreadParam->tasks[i].task_algorithm_data.size = frame.size; | |
1039 | - | |
1040 | - pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3); | |
1041 | - AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1); | |
1042 | - } | |
1043 | - | |
1044 | - //copy decode data | |
1045 | - if (pThreadParam->tasks[i].task_algorithm_data.frame) | |
1046 | - { | |
1047 | - int height = frame.height; | |
1048 | - int width = frame.width; | |
1049 | - | |
1050 | - Nv12ToColor24<BGR24>( (unsigned char *)frame.frame, width, (unsigned char *)pThreadParam->tasks[i].task_algorithm_data.frame, 3 * width, width, height, 0 ); | |
1051 | - | |
1052 | - pThreadParam->tasks[i].task_algorithm_data.timestamp = frame.timestamp; | |
1053 | - | |
1054 | - k.insert(i); | |
1055 | - pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); | |
1056 | - } | |
1057 | - else | |
1058 | - { | |
1059 | - std::cout << "NOT ALLOC: pThreadParam->tasks[i].taskDataToBackup.frame" << pThreadParam->tasks[i].task_algorithm_data.frame << std::endl; | |
1060 | - } | |
1061 | - | |
1062 | - pThreadParam->tasks[i].taskTcuvid->DxUnlockFrame(); | |
1063 | - } | |
1064 | - } | |
1065 | - else if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && !pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) | |
1066 | - { | |
1067 | - pThreadParam->tasks[i].taskState = DECODEERROR; | |
1068 | - curPlayTaskCount--; | |
1069 | - FinishTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID); | |
1070 | - } | |
1071 | - } | |
1072 | - | |
1073 | - if (curPlayTaskCount <= 0) { | |
1074 | - Sleep(30); | |
1075 | - continue; | |
1076 | - } | |
1077 | - | |
1078 | - //��û�л�ȡ������·���Ľ������� ѭ���ȴ� | |
1079 | - if (k.size() < curPlayTaskCount) | |
1080 | - { | |
1081 | - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); | |
1082 | - goto getdata_flag; | |
1083 | - } | |
1084 | - | |
1085 | -#ifdef LOG_INFO2 | |
1086 | - long long gather_data_time = get_cur_time_ms(); | |
1087 | - std::cout << "gather_data time_using: " << gather_data_time - last_time << std::endl; | |
1088 | -#endif | |
1089 | - | |
1090 | - cudaDeviceSynchronize(); | |
1091 | - | |
1092 | - //------------------------------ ͳһBATCH���� --------------------------------// | |
1093 | - ////////////////////////////////////////////////////////////// | |
1094 | - //// | |
1095 | - //// compose data -> batch | |
1096 | - //// | |
1097 | - ///////////////////////////////////////////////////////////// | |
1098 | - | |
1099 | - vector<vector<int>> deleteObjectID; | |
1100 | - set<int>::iterator iter = pThreadParam->TaskinPlayID.begin(); | |
1101 | - | |
1102 | - int cur_batch_size = 0; | |
1103 | - cur_batch_size = pThreadParam->section_batch_size; | |
1104 | - | |
1105 | - if (0) | |
1106 | - { | |
1107 | - if (pThreadParam->section_batch_size == 20) | |
1108 | - cur_batch_size = pThreadParam->section_batch_size; | |
1109 | - else | |
1110 | - { | |
1111 | - if (curPlayTaskCount <= 2 * pThreadParam->section_batch_size) | |
1112 | - cur_batch_size = pThreadParam->section_batch_size; | |
1113 | - else if (curPlayTaskCount >= 2 * MAX_BATCH) | |
1114 | - cur_batch_size = MAX_BATCH; | |
1115 | - else | |
1116 | - cur_batch_size = curPlayTaskCount / 2 + (curPlayTaskCount % 2); | |
1117 | - } | |
1118 | - } | |
1119 | - | |
1120 | - long long start_time_vpt = get_cur_time_ms(); | |
1121 | - | |
1122 | - vector<vector<VPT_Result>> unUsedResult; | |
1123 | - vector<unsigned long long> vec_frameIndex; | |
1124 | - unUsedResult.resize(pThreadParam->VPTResult.size()); | |
1125 | - int cycleTimes = curPlayTaskCount / cur_batch_size + (curPlayTaskCount % cur_batch_size == 0 ? 0 : 1); | |
1126 | - for (int c = 0; c < cycleTimes; c++) | |
1127 | - { | |
1128 | - int batchsize = c == cycleTimes - 1 ? (curPlayTaskCount - cur_batch_size*c) : cur_batch_size; | |
1129 | - int startbatch = c*cur_batch_size; | |
1130 | - | |
1131 | - vec_frameIndex.clear(); | |
1132 | - for (int i = 0; i < batchsize; i++) | |
1133 | - { | |
1134 | - DxGPUFrame task_algorithm_data = pThreadParam->tasks[*iter].task_algorithm_data; | |
1135 | - int w = task_algorithm_data.width; | |
1136 | - int h = task_algorithm_data.height; | |
1137 | - int npitch = task_algorithm_data.size; | |
1138 | - | |
1139 | - batch_img[i].set_data(w, h, 3, (unsigned char *)task_algorithm_data.frame); | |
1140 | - vec_frameIndex.push_back(task_algorithm_data.timestamp); | |
1141 | - iter++; | |
1142 | - } | |
1143 | - | |
1144 | - vector<vector<int>> tempDeleteObjectID; | |
1145 | - tempDeleteObjectID.resize(batchsize); | |
1146 | - int flag = VPT_Process_GPU(pThreadParam->GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, pThreadParam->VPTResult, tempDeleteObjectID, unUsedResult); | |
1147 | - process_times++ ; | |
1148 | - | |
1149 | - for (auto iter : tempDeleteObjectID) | |
1150 | - { | |
1151 | - deleteObjectID.push_back(iter); | |
1152 | - } | |
1153 | - vector<vector<int>>().swap(tempDeleteObjectID); | |
1154 | - } | |
1155 | -#ifdef LOG_INFO2 | |
1156 | - std::cout << "VPT_Process_GPU time_using: " << get_cur_time_ms() - start_time_vpt << std::endl; | |
1157 | -#endif | |
1158 | - | |
1159 | - long long result_analysis_time = get_cur_time_ms(); | |
1160 | - | |
1161 | - iter = pThreadParam->TaskinPlayID.begin(); | |
1162 | - for (int i = 0; i < curPlayTaskCount; i++) | |
1163 | - { | |
1164 | - pThreadParam->tasks[*iter].taskFrameCount = pThreadParam->tasks[*iter].task_algorithm_data.timestamp; | |
1165 | - //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 | |
1166 | - if (pThreadParam->VPTResult[i].objCount == 0) | |
1167 | - { | |
1168 | - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskFrameCount, *iter); | |
1169 | - } | |
1170 | - | |
1171 | - //实时查看模块,若存在实时查看,把当前视频画面cp回内存 | |
1172 | - bool view = false; | |
1173 | - int frameHeight = pThreadParam->tasks[*iter].task_algorithm_data.height; | |
1174 | - int frameWidth = pThreadParam->tasks[*iter].task_algorithm_data.width; | |
1175 | - | |
1176 | - if (*iter == pThreadParam->viewTaskID) | |
1177 | - { | |
1178 | - 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); | |
1179 | - view = true; | |
1180 | - } | |
1181 | - | |
1182 | - //跟踪帧也需要返回跟踪的结果 | |
1183 | - if (pThreadParam->tasks[*iter].taskLastFrameCount > 0) | |
1184 | - { | |
1185 | - vector<VPT_Result> OneUnUsedResult = unUsedResult[i]; | |
1186 | - if (OneUnUsedResult.size() == 0) | |
1187 | - { | |
1188 | - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskLastFrameCount + 1, *iter); | |
1189 | - } | |
1190 | - for (int k = 0; k < OneUnUsedResult.size(); ++k) | |
1191 | - { | |
1192 | - if (OneUnUsedResult[k].objCount == 0) | |
1193 | - { | |
1194 | - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskLastFrameCount + k + 1, *iter); | |
1195 | - } | |
1196 | - else | |
1197 | - { | |
1198 | - //cout << "OneUnUsedResult.size = " << OneUnUsedResult.size() << " k=" << k << " OneUnUsedResult[k].objCount = " << OneUnUsedResult[k].objCount << endl; | |
1199 | - pThreadParam->callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, pThreadParam->tasks[*iter].taskLastFrameCount + k + 1, *iter); | |
1200 | - } | |
1201 | - } | |
1202 | - } | |
1203 | - pThreadParam->tasks[*iter].taskLastFrameCount = pThreadParam->tasks[*iter].taskFrameCount; | |
1204 | - | |
1205 | - unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{};// = new unsigned char*[pThreadParam->VPTResult[i].objCount]; | |
1206 | - int snapshot_left[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; | |
1207 | - int snapshot_right[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; | |
1208 | - int snapshot_top[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; | |
1209 | - int snapshot_bottom[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; | |
1210 | - int snapshot_dst_width[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; | |
1211 | - int snapshot_dst_height[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; | |
1212 | - | |
1213 | - int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 | |
1214 | - vector<int> human_idx; //用于记录快照数组中那些是人脸 | |
1215 | - vector<OBJ_KEY> human_obj_keys; | |
1216 | - | |
1217 | - pThreadParam->callTaskObjInfoCallbackFunc(pThreadParam->VPTResult[i].objCount, pThreadParam->VPTResult[i].obj, pThreadParam->tasks[*iter].taskFrameCount, *iter); | |
1218 | - for (int c = 0; c < pThreadParam->VPTResult[i].objCount; c++) | |
1219 | - { | |
1220 | - OBJ_KEY newObj = { (*iter), pThreadParam->VPTResult[i].obj[c].id }; | |
1221 | - | |
1222 | - int index = 0; | |
1223 | - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) | |
1224 | - index = pThreadParam->VPTResult[i].obj[c].index; | |
1225 | - else | |
1226 | - index = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; | |
1227 | - | |
1228 | - //实时查看模块 绘制目标框到画面上 | |
1229 | - if (view) | |
1230 | - { | |
1231 | - //cout << "---- vew ---- "; | |
1232 | - int p1 = pThreadParam->VPTResult[i].obj[c].left - 10 > 0 ? pThreadParam->VPTResult[i].obj[c].left - 10 : 0; | |
1233 | - int p2 = pThreadParam->VPTResult[i].obj[c].top - 15 > 0 ? pThreadParam->VPTResult[i].obj[c].top - 15 : 0; | |
1234 | - | |
1235 | - cv::rectangle(pThreadParam->tasks[*iter].frameImage, Rect(pThreadParam->VPTResult[i].obj[c].left, pThreadParam->VPTResult[i].obj[c].top, | |
1236 | - pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left, | |
1237 | - pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top), Scalar(158, 52, 254), 3, 1, 0); | |
1238 | - #ifdef _MSC_VER | |
1239 | - string resss = "" + to_string(index) + " " + ObjTypes[index]; | |
1240 | - putTextZH(pThreadParam->tasks[*iter].frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); | |
1241 | - #else | |
1242 | - string resss = "" + to_string(pThreadParam->VPTResult[i].obj[c].id) + " " + ObjTypesEnglish[pThreadParam->VPTResult[i].obj[c].index]; | |
1243 | - 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); | |
1244 | - #endif | |
1245 | - } | |
1246 | - | |
1247 | - //逐个目标更新快照 | |
1248 | - int boundary = 10; | |
1249 | - int boundaryLittle = 4; | |
1250 | - | |
1251 | - int cur_real_width = (pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left); | |
1252 | - int cur_real_height = (pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top); | |
1253 | - int cur_real_index = pThreadParam->VPTResult[i].obj[c].index; | |
1254 | - | |
1255 | - //第一次添加快照 | |
1256 | - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) | |
1257 | - { | |
1258 | - //DxAppendLog(DxLOG_INFO, "30"); | |
1259 | - if (LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) | |
1260 | - { | |
1261 | - //DxAppendLog(DxLOG_INFO, "31"); | |
1262 | - //--------------------- 保存快照视频截图 -----------------------------// | |
1263 | - | |
1264 | - int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left - boundaryLittle)); | |
1265 | - int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top - boundaryLittle)); | |
1266 | - int right = min({ frameWidth - 1, (int)(pThreadParam->VPTResult[i].obj[c].right + boundaryLittle) }); | |
1267 | - int bottom = min({ frameHeight - 1, (int)(pThreadParam->VPTResult[i].obj[c].bottom + boundaryLittle) }); | |
1268 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].frameCount = pThreadParam->tasks[*iter].taskFrameCount; | |
1269 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].isupdate = true; | |
1270 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lost = 0; | |
1271 | - | |
1272 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; | |
1273 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; | |
1274 | - | |
1275 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; | |
1276 | - | |
1277 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left = left; | |
1278 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top = top; | |
1279 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right = right; | |
1280 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; | |
1281 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); | |
1282 | - | |
1283 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left | |
1284 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top | |
1285 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right | |
1286 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom | |
1287 | - | |
1288 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = NULL; | |
1289 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.frame = NULL; | |
1290 | - | |
1291 | - if (pThreadParam->tasks[*iter].folderName != NULL) | |
1292 | - { | |
1293 | - //DxAppendLog(DxLOG_INFO, "32"); | |
1294 | - FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; | |
1295 | - pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); | |
1296 | - | |
1297 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.height = frameHeight; | |
1298 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.width = frameWidth; | |
1299 | - } | |
1300 | - | |
1301 | - | |
1302 | - //--------------------- 保存快照抠图 -----------------------------/ | |
1303 | - int vLeft = 0; | |
1304 | - int vTop = 0; | |
1305 | - int vRight = 0; | |
1306 | - int vBottom = 0; | |
1307 | - | |
1308 | - vLeft = max(0, pThreadParam->VPTResult[i].obj[c].left - boundary); | |
1309 | - vTop = max(0, pThreadParam->VPTResult[i].obj[c].top - boundary); | |
1310 | - vRight = min({ frameWidth - 1, pThreadParam->VPTResult[i].obj[c].right + boundary }); | |
1311 | - vBottom = min({ frameHeight - 1, pThreadParam->VPTResult[i].obj[c].bottom + boundary }); | |
1312 | - //DxAppendLog(DxLOG_INFO, "34"); | |
1313 | - if (pThreadParam->tasks[*iter].folderNameLittle != NULL) | |
1314 | - { | |
1315 | - //DxAppendLog(DxLOG_INFO, "35"); | |
1316 | - int cur_width = 0; | |
1317 | - int cur_height = 0; | |
1318 | - | |
1319 | - if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) | |
1320 | - { | |
1321 | - cur_width = HP_WIDTH; | |
1322 | - cur_height = HP_HEIGHT; | |
1323 | - | |
1324 | - human_idx.emplace_back(copy_obj_count); | |
1325 | - human_obj_keys.emplace_back (newObj); | |
1326 | - } | |
1327 | - else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) | |
1328 | - { | |
1329 | - cur_width = HCP_WIDTH; | |
1330 | - cur_height = HCP_HEIGHT; | |
1331 | - } | |
1332 | - 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)) | |
1333 | - { | |
1334 | - cur_width = VEHICLE_WIDTH; | |
1335 | - cur_height = VEHICLE_HEIGHT; | |
1336 | - } | |
1337 | - else //其余类别 | |
1338 | - { | |
1339 | - cur_width = vRight - vLeft; | |
1340 | - cur_height = vBottom - vTop; | |
1341 | - } | |
1342 | - | |
1343 | - if (cur_width != 0 && cur_height != 0) | |
1344 | - { | |
1345 | - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char)); | |
1346 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = cur_height; | |
1347 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = cur_width; | |
1348 | - | |
1349 | - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; | |
1350 | - snapshot_left[copy_obj_count] = vLeft; | |
1351 | - snapshot_top[copy_obj_count] = vTop; | |
1352 | - snapshot_right[copy_obj_count] = vRight; | |
1353 | - snapshot_bottom[copy_obj_count] = vBottom; | |
1354 | - | |
1355 | - snapshot_dst_width[copy_obj_count] = cur_width; | |
1356 | - snapshot_dst_height[copy_obj_count++] = cur_height; | |
1357 | - } | |
1358 | - } | |
1359 | - } | |
1360 | - } | |
1361 | - else | |
1362 | - { | |
1363 | - //DxAppendLog(DxLOG_INFO, "36"); | |
1364 | - bool updateShotInfo = false; | |
1365 | - int oldIndex = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; | |
1366 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].frameCount = pThreadParam->tasks[*iter].taskFrameCount; | |
1367 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].isupdate = true; | |
1368 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lost = 0; | |
1369 | - | |
1370 | - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count == 0) | |
1371 | - { | |
1372 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; | |
1373 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; | |
1374 | - } | |
1375 | - else | |
1376 | - { | |
1377 | - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index == pThreadParam->VPTResult[i].obj[c].index) | |
1378 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; | |
1379 | - else | |
1380 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count--; | |
1381 | - } | |
1382 | - if (oldIndex != pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) | |
1383 | - { | |
1384 | - updateShotInfo = true; | |
1385 | - } | |
1386 | - | |
1387 | - int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left - boundaryLittle)); | |
1388 | - int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top - boundaryLittle)); | |
1389 | - int right = min(frameWidth - 1, (int)(pThreadParam->VPTResult[i].obj[c].right + boundaryLittle)); | |
1390 | - int bottom = min(frameHeight - 1, (int)(pThreadParam->VPTResult[i].obj[c].bottom + boundaryLittle)); | |
1391 | - | |
1392 | - 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); | |
1393 | - | |
1394 | - if ((LegalArea(maxArea, pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea, left, top, right, bottom) | |
1395 | - && LegalPos(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth) | |
1396 | - && LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) || updateShotInfo) | |
1397 | - { | |
1398 | - //DxAppendLog(DxLOG_INFO, "37"); | |
1399 | - int boundary_w = (pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left) * 0.1; | |
1400 | - int boundary_h = (pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top)* 0.1; | |
1401 | - | |
1402 | - int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h; | |
1403 | - | |
1404 | - ExpandMargin((left - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left), | |
1405 | - (bottom - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom), | |
1406 | - boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom); | |
1407 | - | |
1408 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left = left; | |
1409 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top = top; | |
1410 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right = right; | |
1411 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; | |
1412 | - //printf("ori: %d %d %d %d\n", left, top, right - left, bottom - top); | |
1413 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; | |
1414 | - if (pThreadParam->tasks[*iter].folderName != NULL) | |
1415 | - { | |
1416 | - FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; | |
1417 | - pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); | |
1418 | - } | |
1419 | - | |
1420 | - | |
1421 | - //--------------------- 保存快照抠图 -----------------------------// | |
1422 | - int vLeft = 0; | |
1423 | - int vTop = 0; | |
1424 | - int vRight = 0; | |
1425 | - int vBottom = 0; | |
1426 | - | |
1427 | - vLeft = max(0, pThreadParam->VPTResult[i].obj[c].left - boundary_left); | |
1428 | - vTop = max(0, pThreadParam->VPTResult[i].obj[c].top - boundary_top); | |
1429 | - vRight = min(frameWidth - 1, pThreadParam->VPTResult[i].obj[c].right + boundary_right); | |
1430 | - vBottom = min(frameHeight - 1, pThreadParam->VPTResult[i].obj[c].bottom + boundary_bottom); | |
1431 | - if (pThreadParam->tasks[*iter].folderNameLittle != NULL) | |
1432 | - { | |
1433 | - | |
1434 | - if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) | |
1435 | - { | |
1436 | - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) | |
1437 | - { | |
1438 | - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 | |
1439 | - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char)); | |
1440 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH; | |
1441 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT; | |
1442 | - } | |
1443 | - | |
1444 | - human_idx.push_back(copy_obj_count); | |
1445 | - human_obj_keys.emplace_back(newObj); | |
1446 | - | |
1447 | - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; | |
1448 | - snapshot_left[copy_obj_count] = vLeft; | |
1449 | - snapshot_top[copy_obj_count] = vTop; | |
1450 | - snapshot_right[copy_obj_count] = vRight; | |
1451 | - snapshot_bottom[copy_obj_count] = vBottom; | |
1452 | - //printf("crop: %d %d %d %d\n", vLeft, vTop, vRight - vLeft, vBottom - vTop); | |
1453 | - snapshot_dst_width[copy_obj_count] = HP_WIDTH; | |
1454 | - snapshot_dst_height[copy_obj_count++] = HP_HEIGHT; | |
1455 | - | |
1456 | - } | |
1457 | - else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) | |
1458 | - { | |
1459 | - //DxAppendLog(DxLOG_INFO, "42"); | |
1460 | - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) | |
1461 | - { | |
1462 | - //DxAppendLog(DxLOG_INFO, "43"); | |
1463 | - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 | |
1464 | - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char)); | |
1465 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH; | |
1466 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT; | |
1467 | - } | |
1468 | - | |
1469 | - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; | |
1470 | - snapshot_left[copy_obj_count] = vLeft; | |
1471 | - snapshot_top[copy_obj_count] = vTop; | |
1472 | - snapshot_right[copy_obj_count] = vRight; | |
1473 | - snapshot_bottom[copy_obj_count] = vBottom; | |
1474 | - | |
1475 | - snapshot_dst_width[copy_obj_count] = HCP_WIDTH; | |
1476 | - snapshot_dst_height[copy_obj_count++] = HCP_HEIGHT; | |
1477 | - | |
1478 | - } | |
1479 | - 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)) | |
1480 | - { | |
1481 | - //DxAppendLog(DxLOG_INFO, "43.1"); | |
1482 | - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT) | |
1483 | - { | |
1484 | - //DxAppendLog(DxLOG_INFO, "44"); | |
1485 | - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 | |
1486 | - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char)); | |
1487 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH; | |
1488 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT; | |
1489 | - } | |
1490 | - | |
1491 | - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; | |
1492 | - snapshot_left[copy_obj_count] = vLeft; | |
1493 | - snapshot_top[copy_obj_count] = vTop; | |
1494 | - snapshot_right[copy_obj_count] = vRight; | |
1495 | - snapshot_bottom[copy_obj_count] = vBottom; | |
1496 | - | |
1497 | - snapshot_dst_width[copy_obj_count] = VEHICLE_WIDTH; | |
1498 | - snapshot_dst_height[copy_obj_count++] = VEHICLE_HEIGHT; | |
1499 | - | |
1500 | - } | |
1501 | - else | |
1502 | - { | |
1503 | - //DxAppendLog(DxLOG_INFO, "45"); | |
1504 | - // modified by zsh 220614---------------------------- | |
1505 | - int cur_width = vRight - vLeft; | |
1506 | - int cur_height = vBottom - vTop; | |
1507 | - if (cur_width != 0 && cur_height != 0) { | |
1508 | - //---------------------------------------- | |
1509 | - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 | |
1510 | - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char)); | |
1511 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop; | |
1512 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft; | |
1513 | - | |
1514 | - //printf("begin partMemCopy: %d %d %d %d %d %d\n", vLeft, vTop, vRight, vBottom, frameWidth, frameHeight); | |
1515 | - partMemCopy((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, | |
1516 | - (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom); | |
1517 | - } | |
1518 | - } | |
1519 | - | |
1520 | - } | |
1521 | - } | |
1522 | - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); | |
1523 | - } | |
1524 | - | |
1525 | - } | |
1526 | - | |
1527 | - //若待抠图的快照数不为0 则进行批量抠图 | |
1528 | - if (0 != copy_obj_count) | |
1529 | - { | |
1530 | - cudaSetDevice(pThreadParam->mgpuid); | |
1531 | - PartMemResizeBatch((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, | |
1532 | - 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); | |
1533 | - | |
1534 | - //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选 | |
1535 | - if (pThreadParam->m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) | |
1536 | - { | |
1537 | - //需要做人脸检测 | |
1538 | - int human_count = human_idx.size(); | |
1539 | - sy_img *human_img = new sy_img[human_count]; | |
1540 | - | |
1541 | - sy_point* ori_points = new sy_point[human_count]; | |
1542 | - for (int idx = 0; idx < human_count; idx++) | |
1543 | - { | |
1544 | - int ii = human_idx[idx]; | |
1545 | - human_img[idx].set_data(snapshot_dst_width[ii], snapshot_dst_height[ii], 3, snapshot_image_data[ii]); | |
1546 | - ori_points[idx].x_ = (snapshot_right[ii] - snapshot_left[ii]); | |
1547 | - ori_points[idx].y_ = (snapshot_bottom[ii] - snapshot_top[ii]); | |
1548 | - } | |
1549 | - | |
1550 | - fd_result *face_det_result = new fd_result[human_count]; | |
1551 | - for (int fd_i = 0; fd_i < human_count; fd_i++) | |
1552 | - { | |
1553 | - face_det_result[fd_i].info = new fd_info[10]; //内存由外部申请 | |
1554 | - } | |
1555 | - | |
1556 | - if (pThreadParam->m_face_det_module->face_det_module_process(human_img, human_count, face_det_result, ori_points) == SUCCESS) | |
1557 | - { | |
1558 | - //printf("finish face_det_module_process: %d\n", human_count); | |
1559 | - for (int idx = 0; idx < human_count; idx++) | |
1560 | - { | |
1561 | - OBJ_KEY cur_obj_key = human_obj_keys[idx]; | |
1562 | - fd_result &cur_det_res = face_det_result[idx]; | |
1563 | - int face_count = cur_det_res.count; | |
1564 | - int face_idx = 0; | |
1565 | - int ii = human_idx[idx]; | |
1566 | - | |
1567 | - if (face_count == 0) continue; | |
1568 | - | |
1569 | - if (face_count > 1) //检测到多余一个人脸 选最佳 | |
1570 | - { | |
1571 | - sy_point center_human = { human_img[idx].w_/2, human_img [idx].h_/2}; | |
1572 | - float min_distance = INT_MAX; | |
1573 | - | |
1574 | - for (int c = 0; c < face_count; c++) | |
1575 | - { | |
1576 | - sy_point face_center = { cur_det_res.info[c].face_position.width_/2, cur_det_res.info[c].face_position.height_/2}; | |
1577 | - float distance = fabs(center_human.x_ - face_center.x_) + fabs(center_human.y_ - face_center.y_); | |
1578 | - | |
1579 | - if (distance < min_distance) | |
1580 | - { | |
1581 | - min_distance = distance; | |
1582 | - face_idx = c; | |
1583 | - } | |
1584 | - } | |
1585 | - } | |
1586 | - | |
1587 | - fd_info& cur_det_info = cur_det_res.info[face_idx]; | |
1588 | - if (pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame == nullptr) | |
1589 | - { | |
1590 | - sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_ ), | |
1591 | - (int)(snapshot_top[ii] + cur_det_info.face_position.top_), | |
1592 | - (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; | |
1593 | - | |
1594 | - int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); | |
1595 | - int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); | |
1596 | - int new_right = min((int)pThreadParam->tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); | |
1597 | - int new_bottom = min((int)pThreadParam->tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); | |
1598 | - int new_width = new_right - new_left; | |
1599 | - int new_height = new_bottom - new_top; | |
1600 | - | |
1601 | - sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; | |
1602 | - | |
1603 | - int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; | |
1604 | - | |
1605 | - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); | |
1606 | - if (cudaStatus != cudaSuccess) { | |
1607 | - fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); | |
1608 | - break; | |
1609 | - } | |
1610 | - | |
1611 | - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; | |
1612 | - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; | |
1613 | - memcpy((void*)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); | |
1614 | - | |
1615 | - //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 | |
1616 | - fd_info& tmp_info = pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; | |
1617 | - | |
1618 | - for (int p = 0; p < FACIALFEAPOINTSIZE; p++) | |
1619 | - { | |
1620 | - tmp_info.facial_fea_point[p].x_ = | |
1621 | - tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); | |
1622 | - tmp_info.facial_fea_point[p].y_ = | |
1623 | - tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); | |
1624 | - } | |
1625 | - | |
1626 | - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = | |
1627 | - { (face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_ }; | |
1628 | - | |
1629 | - | |
1630 | - 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, | |
1631 | - (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_); | |
1632 | - | |
1633 | - //show_gpu_img_func(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace); | |
1634 | - } | |
1635 | - else | |
1636 | - { | |
1637 | - sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_), | |
1638 | - (int)(snapshot_top[ii] + cur_det_info.face_position.top_), | |
1639 | - (int)(cur_det_info.face_position.width_), (int)(cur_det_info.face_position.height_) }; | |
1640 | - | |
1641 | - //更新人脸快照条件:① 角度满足条件 ② 面积比之前人脸面积大 | |
1642 | - 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) | |
1643 | - && betterArea(face_ori_rect, pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position)) | |
1644 | - { | |
1645 | - int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); | |
1646 | - int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); | |
1647 | - int new_right = min((int)pThreadParam->tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); | |
1648 | - int new_bottom = min((int)pThreadParam->tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); | |
1649 | - int new_width = new_right - new_left; | |
1650 | - int new_height = new_bottom - new_top; | |
1651 | - | |
1652 | - sy_rect face_expand_rect = { new_left, new_top, new_width, new_height }; | |
1653 | - | |
1654 | - //更新快照 | |
1655 | - int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; | |
1656 | - | |
1657 | - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame); | |
1658 | - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); | |
1659 | - if (cudaStatus != cudaSuccess) { | |
1660 | - fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); | |
1661 | - break; | |
1662 | - } | |
1663 | - | |
1664 | - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; | |
1665 | - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; | |
1666 | - memcpy((void*)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); | |
1667 | - | |
1668 | - //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 | |
1669 | - fd_info& tmp_info = pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; | |
1670 | - | |
1671 | - for (int p = 0; p < FACIALFEAPOINTSIZE; p++) | |
1672 | - { | |
1673 | - tmp_info.facial_fea_point[p].x_ = | |
1674 | - tmp_info.facial_fea_point[p].x_ - tmp_info.face_position.left_ + (face_ori_rect.left_ - face_expand_rect.left_); | |
1675 | - tmp_info.facial_fea_point[p].y_ = | |
1676 | - tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); | |
1677 | - } | |
1678 | - | |
1679 | - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = | |
1680 | - {(face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_}; | |
1681 | - | |
1682 | - 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, | |
1683 | - (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_); | |
1684 | - | |
1685 | - //show_gpu_image_withfdinfo_(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, cur_det_info); | |
1686 | - | |
1687 | - //show_gpu_image_withfdinfo_(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info); | |
1688 | - } | |
1689 | - } | |
1690 | - } | |
1691 | - } | |
1692 | - | |
1693 | - if (face_det_result) | |
1694 | - { | |
1695 | - for (int fd_i = 0; fd_i < human_count; fd_i++) | |
1696 | - delete[] face_det_result[fd_i].info; | |
1697 | - delete face_det_result; | |
1698 | - } | |
1699 | - | |
1700 | - if (human_img) delete[] human_img; | |
1701 | - if (ori_points) delete[] ori_points; | |
1702 | - } | |
1703 | - } | |
1704 | - | |
1705 | - //实时查看 绘制目标轨迹 回调函数返回 | |
1706 | - if (view) | |
1707 | - { | |
1708 | - DrawTracker(pThreadParam->VPT_Handle, *iter, &pThreadParam->tasks[*iter].frameImage); | |
1709 | - if (pThreadParam->tasks[*iter].taskRealTimeCallbackFunc != nullptr) | |
1710 | - pThreadParam->tasks[*iter].taskRealTimeCallbackFunc(pThreadParam->tasks[*iter].frameImage.data, pThreadParam->tasks[*iter].frameImage.rows, pThreadParam->tasks[*iter].frameImage.cols); | |
1711 | - } | |
1712 | - // pThreadParam->tasks[*iter].taskFrameCount += pThreadParam->skip_frame_; | |
1713 | - iter++; | |
1714 | - } | |
1715 | - | |
1716 | -#ifdef LOG_INFO2 | |
1717 | - long long result_analysis_time2 = get_cur_time_ms(); | |
1718 | - cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; | |
1719 | -#endif | |
1720 | - | |
1721 | - | |
1722 | - auto task_iter = pThreadParam->TaskinPlayID.begin(); | |
1723 | - | |
1724 | - pThreadParam->AttributionAnalysis = false; | |
1725 | - | |
1726 | - long long second_analysis_time = get_cur_time_ms(); | |
1727 | - | |
1728 | - for (int i = 0; i < curPlayTaskCount; i++) | |
1729 | - { | |
1730 | - for (int j = 0; j < deleteObjectID[i].size(); j++) | |
1731 | - { | |
1732 | - OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; | |
1733 | - | |
1734 | - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) | |
1735 | - continue; | |
1736 | - | |
1737 | - auto iter = pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj); | |
1738 | - iter->second.finishTracker = true; | |
1739 | - | |
1740 | - pThreadParam->SaveResultInFile(iter->first, iter->second); | |
1741 | - } | |
1742 | - | |
1743 | - task_iter++; | |
1744 | - } | |
1745 | - | |
1746 | - for (int i = 0; i < deleteObjectID.size(); i++) | |
1747 | - vector<int>().swap(deleteObjectID[i]); | |
1748 | - vector<vector<int>>().swap(deleteObjectID); | |
1749 | - | |
1750 | - // pThreadParam->m_snaphot_helper.object_attri_analysis(); | |
1751 | - | |
1752 | -#ifdef LOG_INFO2 | |
1753 | - long long second_analysis_time2 = get_cur_time_ms(); | |
1754 | - cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl; | |
1755 | -#endif | |
1756 | - | |
1757 | - cudaError_t cudaStatus = cudaGetLastError(); | |
1758 | - if (cudaStatus != cudaSuccess) { | |
1759 | - printf("object_attri_analysis last error: %s\n", cudaGetErrorString(cudaStatus)); | |
1760 | - } | |
1761 | - | |
1762 | - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); | |
1763 | - | |
1764 | - ++total_count; | |
1765 | - ++ncount; | |
1766 | - | |
1767 | -#ifdef LOG_INFO2 | |
1768 | - last_time = get_cur_time_ms(); | |
1769 | - cout << "process time_using:" << last_time - gather_data_time << endl; | |
1770 | - cout << endl; | |
1771 | -#endif | |
1772 | - } | |
1773 | - } | |
1774 | - //catch (exception &e) | |
1775 | - { | |
1776 | - //os << 51 << e.what()<< std::endl; | |
1777 | - /* std::cout << e.what() << std::endl; | |
1778 | - exit(-1);*/ | |
1779 | - } | |
1780 | - long long costTime1 = get_cur_time_ms() - begintime1; | |
1781 | - std::cout << "==================== Process Thread is Finished: " << std::endl; | |
1782 | - printf("total frame cost time = %lld us, process times: %d \n", costTime1, process_times); | |
1783 | - | |
1784 | - pThreadParam->m_snaphot_helper.snapShotInfo.clear(); | |
1785 | - pThreadParam->ProcessFlag = false; | |
1786 | - | |
1787 | - // printf("1499 set ProcessFlag false\n"); | |
1788 | - // if (pThreadParam->FrameTemp) | |
1789 | - // { | |
1790 | - // cudaFree(pThreadParam->FrameTemp); | |
1791 | - // } | |
1792 | - | |
1793 | - if (batch_img != NULL) | |
1794 | - { | |
1795 | - delete[] batch_img; | |
1796 | - batch_img = NULL; | |
1797 | - } | |
1798 | - | |
1799 | - // cuCtxPopCurrent(nullptr); | |
1800 | - // cuCtxDestroy(context); | |
1801 | - | |
1802 | - return 0; | |
1803 | -} | |
1804 | - | |
1805 | -int CMutliSourceVideoProcess::GetRuningNb() { | |
1806 | - int no = 0; | |
1807 | - for(int i=0; i < tasks.size(); i++){ | |
1808 | - if(tasks[i].taskState == PLAY){ | |
1809 | - no ++; | |
1810 | - } | |
1811 | - } | |
1812 | - | |
1813 | - return no; | |
1814 | -} | |
1815 | - | |
1816 | -#ifdef AUTHORIZATION | |
1817 | -void check_thread(void* handle) | |
1818 | -{ | |
1819 | - int res = -1; | |
1820 | -#ifndef _MSC_VER | |
1821 | - char wtime[15]; | |
1822 | - memset(wtime, 0, 15); | |
1823 | - char * time = wtime; | |
1824 | -#endif | |
1825 | - | |
1826 | - CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)handle; | |
1827 | - | |
1828 | - while (1) | |
1829 | - { | |
1830 | - //printf("xxx check status on process...\n"); | |
1831 | -#ifdef _MSC_VER | |
1832 | - res = sy_licence(productSN); | |
1833 | -#else | |
1834 | - res = sy_licence(productSN, &time); | |
1835 | - //printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status); | |
1836 | -#endif | |
1837 | - if (res < 0) | |
1838 | - { | |
1839 | - pThreadParam->licence_status = pThreadParam->licence_status - 1; | |
1840 | - } | |
1841 | - else | |
1842 | - { | |
1843 | - if (pThreadParam->licence_status < 0) | |
1844 | - { | |
1845 | - pThreadParam->licence_status = 0; | |
1846 | - } | |
1847 | - } | |
1848 | - boost::this_thread::sleep(boost::posix_time::seconds(300)); //5min | |
1849 | - } | |
1850 | -} | |
1851 | -#endif | |
1852 | 0 | \ No newline at end of file |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h
... | ... | @@ -13,12 +13,10 @@ |
13 | 13 | #include "VPTProcess.h" |
14 | 14 | #include <queue> |
15 | 15 | #include <set> |
16 | -#include <boost/thread/thread.hpp> | |
17 | 16 | #include "common.h" |
18 | 17 | #include "../FFNvDecoder/ImageSaveGPU.h" |
19 | 18 | |
20 | 19 | #include "mvpt_process_assist.h" |
21 | -#include <boost/thread/thread_pool.hpp> | |
22 | 20 | #include "snapshot_helper.h" |
23 | 21 | #include "FaceDetModule.h" |
24 | 22 | |
... | ... | @@ -235,7 +233,7 @@ public: |
235 | 233 | private: |
236 | 234 | //bool ChangeTask; |
237 | 235 | //HANDLE handle_process; |
238 | - boost::thread ProcessThread; | |
236 | + std::thread ProcessThread; | |
239 | 237 | std::mutex _tx_add_task; |
240 | 238 | |
241 | 239 | |
... | ... | @@ -246,7 +244,7 @@ private: |
246 | 244 | //cv::Mat objSnapshot; |
247 | 245 | |
248 | 246 | double gpu_total_memory; |
249 | - boost::thread thrd; | |
247 | + std::thread thrd; | |
250 | 248 | void* authority_handle; |
251 | 249 | |
252 | 250 | public: /*锟斤拷锟斤拷锟斤拷锟斤拷应锟斤拷锟斤拷public锟斤拷 锟斤拷锟斤拷锟斤拷锟竭程猴拷锟斤拷锟叫伙拷锟矫碉拷锟斤拷锟铰碉拷锟斤拷锟斤拷 每锟斤拷锟斤拷写一锟斤拷get锟斤拷锟斤拷太锟斤拷锟斤拷锟斤拷*/ |
... | ... | @@ -282,14 +280,7 @@ public: /*锟斤拷锟斤拷锟斤拷锟斤拷应锟斤拷锟斤拷public锟斤拷 锟斤拷锟斤拷锟斤拷 |
282 | 280 | |
283 | 281 | queue<SNAPSHOT_PROCESS_UNIT> snapshotProcessQueue; |
284 | 282 | |
285 | - //CUcontext cuCtx; | |
286 | - //int PROCESSHEIGHT; | |
287 | - //int PROCESSWIDTH; | |
288 | - //int DATASIZE; | |
289 | 283 | |
290 | - bool beginSaveSnapshot; | |
291 | - boost::thread_group saveSnapshotsThreadGroup; | |
292 | - //boost::mutex process_thread_mutex; | |
293 | 284 | std::mutex taskMutex; |
294 | 285 | std::condition_variable taskCondVar; |
295 | 286 | bool AttributionAnalysis; //锟斤拷锟节匡拷锟狡o拷每帧锟斤拷锟斤拷只锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟皆凤拷锟斤拷 |
... | ... | @@ -305,6 +296,9 @@ public: /*锟斤拷锟斤拷锟斤拷锟斤拷应锟斤拷锟斤拷public锟斤拷 锟斤拷锟斤拷锟斤拷 |
305 | 296 | sy_command m_vcf_recg_config; //锟角凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷识锟斤拷 |
306 | 297 | sy_command m_face_det_config; //锟角凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟 |
307 | 298 | snapshot_helper m_snaphot_helper; |
299 | + | |
300 | + bool m_bExit{false}; | |
301 | + bool m_bProcessExit{false}; | |
308 | 302 | }; |
309 | 303 | |
310 | 304 | static CMutliSourceVideoProcess mainProcess; | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cppbk deleted
1 | -#include "VPTProcess.h" | |
2 | - | |
3 | -#ifndef _MSC_VER | |
4 | -#include <sys/time.h> | |
5 | -#endif | |
6 | - | |
7 | -#include <stdlib.h> | |
8 | -#include <cuda_runtime.h> | |
9 | -#include "ObjCls.h" | |
10 | -#include <time.h> | |
11 | -#include "ErrorInfo.h" | |
12 | -#include "fstream" | |
13 | -#include <boost/thread/thread.hpp> | |
14 | -//#include "mobileshift0.6_mergeBNALL.h" | |
15 | -//#include "ga_mobile_10_SSD10_416x224_416x224_mobile_shift2_mindim06_iter_46107_mergeBNALL.h" | |
16 | - | |
17 | -//#include "test_mergeBNALLGPU.h" | |
18 | -//#include "ga_mobile_10cls_SSD_512x512_mobile_10clsv1_iter_200000_mergeBNALL.h" | |
19 | - | |
20 | -#include "../model/vptModeTrt/ga_vpt_init_net.h" | |
21 | -#include "../model/vptModeTrt/ga_vpt_predict_net.h" | |
22 | -#include "../model/vptModeTrt/ga_trt_fpn_vpt_calibrator.h" | |
23 | -#include "../model/hidemodel_caffe_1108/ga_vpt_init_net_caffe2.h" | |
24 | -#include "../model/hidemodel_caffe_1108/ga_vpt_predict_net_caffe2.h" | |
25 | -#include "vpt_fpn_plugin_factory.h" | |
26 | -//#include "vpt.h" | |
27 | -#include "MutliSourceVideoProcess.h" | |
28 | -//struct vpt_handle | |
29 | -//{ | |
30 | -// void* det_handle; | |
31 | -// vector<TaskTracker> taskTrackers; | |
32 | -//}; | |
33 | - | |
34 | -typedef struct objDetector { | |
35 | - | |
36 | - void* det_handle; | |
37 | - float threshold; | |
38 | - VPT_FPNPluginFactory tensorrt_plugin_factory; | |
39 | - | |
40 | - int licence_status = -1;//鎺堟潈鐩稿叧鍙傛暟 | |
41 | - int thrd_status = -1; //鎺堟潈鐩稿叧鍙傛暟 | |
42 | - boost::thread thrd; //鎺堟潈鐩稿叧鍙傛暟 | |
43 | - vector<TaskTracker> taskTrackers; | |
44 | - objDetector() | |
45 | - { | |
46 | - det_handle = NULL; | |
47 | - threshold = 0.6; | |
48 | - } | |
49 | -}objDetector; | |
50 | - | |
51 | - | |
52 | -//int VPT_Init(void *&handle, VPTProcess_PARAM param) | |
53 | -//{ | |
54 | -// int ret = SUCCESS; | |
55 | -////#ifdef AUTHORIZATION | |
56 | -////#ifdef _WIN32 | |
57 | -//// if (SUCCESS == (ret = sy_licence(productSN))) | |
58 | -////#elif __linux__ | |
59 | -//// char* wtime = new char[15]; | |
60 | -//// memset(wtime, 0, 15); | |
61 | -//// if (SUCCESS == (ret = sy_licence(productSN, &wtime))) | |
62 | -////#endif | |
63 | -////#else | |
64 | -//// ret = sy_time_check(2021, 4); | |
65 | -//// if (ret == SUCCESS) | |
66 | -////#endif | |
67 | -//// { | |
68 | -//// cuInit(0); | |
69 | -//// int device_count = 0; | |
70 | -//// cuDeviceGetCount(&device_count); | |
71 | -//// | |
72 | -//// if (param.gpuid >= device_count) | |
73 | -//// { | |
74 | -//// printf("\nGPU_ID PARAM WRONG!\n"); | |
75 | -//// return GPUID_PARAM_ERROR; | |
76 | -//// } | |
77 | -// | |
78 | -// objDetector * tools = new objDetector; | |
79 | -// | |
80 | -// ctools_init_params vpt_param; | |
81 | -// vpt_param.thres_ = param.threshold; | |
82 | -// vpt_param.log_level_ = 0; | |
83 | -// vpt_param.device_type_ = param.mode; | |
84 | -// vpt_param.device_id_ = param.gpuid; | |
85 | -// vpt_param.engine_type_ = param.engine; | |
86 | -// vpt_param.model_type_ = MODEL_FPN; | |
87 | -// | |
88 | -//#ifdef _MSC_VER | |
89 | -// vpt_param.weight_file_ = NULL; | |
90 | -// vpt_param.net_file_ = NULL; | |
91 | -//#else | |
92 | -// vpt_param.weight_file_ = NULL; | |
93 | -// vpt_param.net_file_ = NULL; | |
94 | -//#endif | |
95 | -// | |
96 | -// | |
97 | -// vpt_param.data_process_str_ = param.preprocess_param; | |
98 | -// vpt_param.need_im_info_ = 1; // true | |
99 | -// | |
100 | -// if (vpt_param.engine_type_ == ENGINE_MCAFFE2) | |
101 | -// { | |
102 | -// //caffe2妯″瀷棰勫鐞嗗弬鏁? | |
103 | -// vpt_param.data_process_str_ = | |
104 | -// "CopyData_CPU2GPU_U8;" | |
105 | -// "TypeConvert_U8_F32;" | |
106 | -// "ResizePad_F32_F32,test_size,720,test_max_size,1280,fpn_coarsest_stride,32," | |
107 | -// "submean_b,103.94,submean_g,116.78,submean_r,123.68," | |
108 | -// "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" | |
109 | -// "NHWC2NCHW_F32" | |
110 | -// ; | |
111 | -// | |
112 | -// vpt_param.weight_array_ = (unsigned char*)ga_vpt_init_net_caffe2; | |
113 | -// vpt_param.weight_array_len_ = ga_vpt_init_net_len_caffe2; | |
114 | -// vpt_param.net_array_ = (unsigned char*)ga_vpt_predict_net_caffe2; | |
115 | -// vpt_param.net_array_len_ = ga_vpt_predict_net_len_caffe2; | |
116 | -// } | |
117 | -// else if (vpt_param.engine_type_ == ENGINE_TENSORRT) | |
118 | -// { | |
119 | -// vpt_param.weight_array_ = (uint8_t*)ga_vpt_init_net; | |
120 | -// vpt_param.weight_array_len_ = ga_vpt_init_net_len; | |
121 | -// vpt_param.net_array_ = (uint8_t*)ga_vpt_predict_net; | |
122 | -// vpt_param.net_array_len_ = ga_vpt_predict_net_len; | |
123 | -// | |
124 | -// vpt_param.trt_serialize_file_ = param.serialize_file;// NULL;// "FPN_VPT_ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
125 | -// | |
126 | -// //trt鐗堟湰棰勫鐞嗗弬鏁? | |
127 | -// param.preprocess_param = | |
128 | -// "CopyData_CPU2GPU_U8;" | |
129 | -// "TypeConvert_U8_F32;" | |
130 | -// "ResizeMaxPad_F32_F32,test_size,720,test_max_size,1280,max_height,736,max_width,1280," | |
131 | -// "submean_b,103.94,submean_g,116.78,submean_r,123.68," | |
132 | -// "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" | |
133 | -// "NHWC2NCHW_F32" | |
134 | -// ; | |
135 | -// | |
136 | -// memset(vpt_param.tensorrt_param_str_, 0, sizeof(vpt_param.tensorrt_param_str_)); | |
137 | -// | |
138 | -// int batch_size = param.max_batch; | |
139 | -// std::string g_data_mode = "FP32"; | |
140 | -// bool g_is_create_calibrator = false; | |
141 | -// | |
142 | -// sprintf(vpt_param.tensorrt_param_str_, "max_batchsize %d," | |
143 | -// "data_mode %s," | |
144 | -// "is_create_calibrator %d," | |
145 | -// "input_names data im_info," | |
146 | -// "output_names cls_prob bbox_pred_final rois_count_each_img", | |
147 | -// batch_size, g_data_mode.c_str(), g_is_create_calibrator); | |
148 | -// | |
149 | -// vpt_param.tensorrt_calibrator_file_ = NULL;// "trt_fpn_vpt_calibrator"; | |
150 | -// vpt_param.tensorrt_calibrator_array_len_ = ga_trt_fpn_vpt_calibrator_len;// "trt_fpn_vpt_calibrator"; | |
151 | -// vpt_param.tensorrt_calibrator_array_ = (unsigned char*)ga_trt_fpn_vpt_calibrator;// "trt_fpn_vpt_calibrator"; | |
152 | -// | |
153 | -// vpt_param.tensorrt_plugin_factory_ptr_ = &(tools->tensorrt_plugin_factory); | |
154 | -// } | |
155 | -// | |
156 | -// tools->threshold = param.threshold; | |
157 | -// | |
158 | -// int flag = ctools_init(&tools->det_handle, &vpt_param); | |
159 | -// | |
160 | -// if (SUCCESS != flag) | |
161 | -// { | |
162 | -// printf("VPT_Init(ERROR): Init failed\n"); | |
163 | -// handle = NULL; | |
164 | -// } | |
165 | -// else | |
166 | -// handle = (void*)tools; | |
167 | -// | |
168 | -// return flag; | |
169 | -//// } | |
170 | -//// else | |
171 | -//// { | |
172 | -//// return AUTHOR_ERROR; | |
173 | -//// } | |
174 | -////#ifdef AUTHORIZATION | |
175 | -////#ifdef __linux__ | |
176 | -//// if (wtime) | |
177 | -//// { | |
178 | -//// delete[] wtime; | |
179 | -//// wtime = NULL; | |
180 | -//// } | |
181 | -////#endif | |
182 | -////#endif | |
183 | -//} | |
184 | - | |
185 | - | |
186 | -int VPT_Init(void *&handle, VPTProcess_PARAM vparam) | |
187 | -{ | |
188 | - objDetector *tools = new objDetector; | |
189 | - | |
190 | - | |
191 | - ctools_init_params param; | |
192 | - param.thres_ = vparam.threshold; | |
193 | - param.log_level_ = 0; | |
194 | - param.device_type_ = vparam.mode; | |
195 | - param.device_id_ = vparam.gpuid; | |
196 | - param.engine_type_ = vparam.engine; | |
197 | - param.model_type_ = MODEL_FPN; | |
198 | - | |
199 | - param.weight_array_ = (uint8_t*)ga_vpt_init_net; | |
200 | - param.weight_array_len_ = ga_vpt_init_net_len; | |
201 | - param.net_array_ = (uint8_t*)ga_vpt_predict_net; | |
202 | - param.net_array_len_ = ga_vpt_predict_net_len; | |
203 | - | |
204 | - param.trt_serialize_file_ = vparam.serialize_file;// NULL;// "FPN_VPT_ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
205 | - | |
206 | - //trt鐗堟湰棰勫鐞嗗弬鏁? | |
207 | - | |
208 | - | |
209 | - memset(param.tensorrt_param_str_, 0, sizeof(param.tensorrt_param_str_)); | |
210 | - | |
211 | - int batch_size = vparam.max_batch; | |
212 | - std::string g_data_mode = "INT8"; | |
213 | - bool g_is_create_calibrator = false; | |
214 | - | |
215 | - sprintf(param.tensorrt_param_str_, "max_batchsize %d," | |
216 | - "data_mode %s," | |
217 | - "is_create_calibrator %d," | |
218 | - "input_names data im_info," | |
219 | - "output_names cls_prob bbox_pred_final rois_count_each_img", | |
220 | - batch_size, g_data_mode.c_str(), g_is_create_calibrator); | |
221 | - | |
222 | - param.tensorrt_calibrator_file_ = NULL;// "trt_fpn_vpt_calibrator"; | |
223 | - param.tensorrt_calibrator_array_len_ = ga_trt_fpn_vpt_calibrator_len;// "trt_fpn_vpt_calibrator"; | |
224 | - param.tensorrt_calibrator_array_ = (unsigned char*)ga_trt_fpn_vpt_calibrator;// "trt_fpn_vpt_calibrator"; | |
225 | - | |
226 | - param.tensorrt_plugin_factory_ptr_ = &(tools->tensorrt_plugin_factory); | |
227 | - | |
228 | - | |
229 | - //param.data_process_str_ = | |
230 | - // "TypeConvert_U8_F32;" | |
231 | - // "ResizePad_F32_F32,test_size,540,test_max_size,1280,fpn_coarsest_stride,32," | |
232 | - // "submean_b,103.94,submean_g,116.78,submean_r,123.68," | |
233 | - // "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" | |
234 | - // "NHWC2NCHW_F32" | |
235 | - // ; | |
236 | - | |
237 | - param.data_process_str_ = | |
238 | - //"CopyData_CPU2GPU_U8;" | |
239 | - "TypeConvert_U8_F32;" | |
240 | - "ResizeMaxPad_F32_F32,test_size,720,test_max_size,1280,max_height,736,max_width,1280," | |
241 | - "submean_b,103.94,submean_g,116.78,submean_r,123.68," | |
242 | - "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" | |
243 | - "NHWC2NCHW_F32" | |
244 | - ; | |
245 | - /* | |
246 | - param.data_process_str_ = | |
247 | - "CopyData_CPU2GPU_U8;" | |
248 | - "TypeConvert_U8_F32;" | |
249 | - "ResizePad_F32_F32,test_size,720,test_max_size,1280,fpn_coarsest_stride,32," | |
250 | - "submean_b,103.94,submean_g,116.78,submean_r,123.68," | |
251 | - "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" | |
252 | - "NHWC2NCHW_F32" | |
253 | - ; | |
254 | - */ | |
255 | - | |
256 | - int flag = ctools_init(&(tools->det_handle), ¶m); | |
257 | - if (SUCCESS != flag) | |
258 | - { | |
259 | - if (tools) | |
260 | - { | |
261 | - delete tools; | |
262 | - tools = NULL; | |
263 | - } | |
264 | - } | |
265 | - else | |
266 | - { | |
267 | - handle = tools; | |
268 | - } | |
269 | - return flag; | |
270 | -} | |
271 | - | |
272 | - | |
273 | -void tmp_test(void * handle) | |
274 | -{ | |
275 | - objDetector *tools = (objDetector*)handle; | |
276 | - | |
277 | -const int batchsize = 5; | |
278 | - sy_img images[batchsize]; | |
279 | - cv::Mat img[batchsize]; | |
280 | - | |
281 | - char strpath[1024]; | |
282 | - memset(strpath, 0, sizeof(strpath)); | |
283 | - for (int b = 0; b < batchsize; b++) | |
284 | - { | |
285 | -#ifdef _MSC_VER | |
286 | - sprintf(strpath, "../../../data/%d.jpg", b);// b); | |
287 | -#else | |
288 | - sprintf(strpath, "0.jpg", b); | |
289 | - | |
290 | -#endif | |
291 | - | |
292 | - img[b] = cv::imread(strpath); | |
293 | - images[b].set_data(img[b].cols, img[b].rows, img[b].channels(), img[b].data); | |
294 | - } | |
295 | - | |
296 | - | |
297 | - //vpt_batch(handle, images, batchsize, &result); | |
298 | - | |
299 | - int count = 1; | |
300 | - while (count--) | |
301 | - { | |
302 | - | |
303 | -printf("begin vpt_batch\n"); | |
304 | - vpt_batch(tools->det_handle, images, batchsize, &result); | |
305 | - | |
306 | - } | |
307 | - | |
308 | - | |
309 | - for (int b = 0; b < batchsize; b++) | |
310 | - { | |
311 | - std::cout << "b: " << b << ", count: " << result[b].obj_count_ << std::endl; | |
312 | - } | |
313 | -} | |
314 | - | |
315 | -int VPT_Process_GPU(void * handle, sy_img * batch_img, int startBatch, int batchsize, vector<VPT_Result>& result, vector<vector<int>>& deleteObjectID, vector<vector<VPT_Result>>& unUsedResult) | |
316 | -{ | |
317 | - | |
318 | - | |
319 | - | |
320 | -tmp_test(handle); | |
321 | - | |
322 | - | |
323 | - | |
324 | - | |
325 | - objDetector *tools = (objDetector*)handle; | |
326 | -#ifndef _MSC_VER | |
327 | - struct timeval first_time, second_time; | |
328 | - gettimeofday(&first_time, NULL); | |
329 | -#endif | |
330 | - | |
331 | - bool isUseDet = true; | |
332 | - int channels = 3; | |
333 | - | |
334 | -#ifndef _MSC_VER | |
335 | - if (0) | |
336 | - { | |
337 | - gettimeofday(&second_time, NULL); | |
338 | - double time_val = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; | |
339 | - printf("set data time_val(ms) = %lf\n", time_val / 1000.0); | |
340 | - gettimeofday(&first_time, NULL); | |
341 | - } | |
342 | -#endif | |
343 | - | |
344 | - | |
345 | - ctools_result *detresult; | |
346 | - | |
347 | - sy_img * batch_img_cpu = new sy_img[batchsize]; | |
348 | - for (int i = 0; i < batchsize; ++i) | |
349 | - { | |
350 | - batch_img_cpu[i].data_ = (unsigned char *)malloc(batch_img[i].w_ * batch_img[i].h_ * batch_img[i].c_); | |
351 | - cudaMemcpy(batch_img_cpu[i].data_, batch_img[i].data_, batch_img[i].w_ * batch_img[i].h_ * batch_img[i].c_, cudaMemcpyDeviceToHost); | |
352 | - | |
353 | - cv::Mat newVideoImg(batch_img[i].h_, batch_img[i].w_, CV_8UC3, batch_img_cpu[i].data_); | |
354 | - | |
355 | - char filename[260]; | |
356 | - sprintf(filename, "pic/%d.jpg", i); | |
357 | - cv::imwrite(filename, newVideoImg); | |
358 | - free(batch_img_cpu[i].data_); | |
359 | - | |
360 | - } | |
361 | - | |
362 | - int res_status = ctools_process(tools->det_handle, batch_img, batchsize, &detresult); | |
363 | - //for (int i = 0; i < batchsize; ++i) | |
364 | - //{ | |
365 | - // free(batch_img_cpu[i].data_); | |
366 | - //} | |
367 | - //delete[]batch_img_cpu; | |
368 | - | |
369 | -#ifndef _MSC_VER | |
370 | - | |
371 | - if (0) | |
372 | - { | |
373 | - gettimeofday(&second_time, NULL); | |
374 | - double time_val = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; | |
375 | - printf("process time_val(ms) = %lf\n", time_val / 1000.0); | |
376 | - } | |
377 | - | |
378 | -#endif | |
379 | - | |
380 | - vector <vector< vector <float>>> detectResult(batchsize); //杞寲涓鸿窡韪墍闇瑕佺殑杈撳叆 | |
381 | - int batch_size = batchsize; | |
382 | - | |
383 | -#ifndef _MSC_VER | |
384 | - | |
385 | - if (0) | |
386 | - { | |
387 | - gettimeofday(&first_time, NULL); | |
388 | - | |
389 | - } | |
390 | - | |
391 | -#endif | |
392 | - | |
393 | - for (int b = 0; b < batch_size; b++) | |
394 | - { | |
395 | - ctools_result &cur_result = detresult[b]; | |
396 | -printf("b=%d, count=%d\n", b, cur_result.obj_count_); | |
397 | - for (int c = 0; c < cur_result.obj_count_ && c < MAX_OBJ_COUNT; c++) | |
398 | - { | |
399 | - | |
400 | - float x1 = cur_result.obj_results_[c].data_[2]; | |
401 | - float y1 = cur_result.obj_results_[c].data_[3]; | |
402 | - float x2 = cur_result.obj_results_[c].data_[4]; | |
403 | - float y2 = cur_result.obj_results_[c].data_[5]; | |
404 | - | |
405 | - float class_id = cur_result.obj_results_[c].data_[0]; | |
406 | - float score = cur_result.obj_results_[c].data_[1]; | |
407 | - | |
408 | - int imgid = b; | |
409 | - if (score >= THRESHOLD) | |
410 | - { | |
411 | - vector <float> obj; | |
412 | - | |
413 | - obj.push_back(x1); | |
414 | - obj.push_back(y1); | |
415 | - obj.push_back(x2); | |
416 | - obj.push_back(y2); | |
417 | - obj.push_back(score); | |
418 | - obj.push_back(class_id); | |
419 | - detectResult[imgid].push_back(obj); | |
420 | - } | |
421 | - } | |
422 | - } | |
423 | - //exit(-1); | |
424 | -#ifndef _MSC_VER | |
425 | - | |
426 | - if (0) | |
427 | - { | |
428 | - gettimeofday(&second_time, NULL); | |
429 | - double time_val = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; | |
430 | - printf("save result time_val(ms) = %lf\n", time_val / 1000.0); | |
431 | - } | |
432 | - | |
433 | -#endif | |
434 | - | |
435 | - int resIndex = startBatch; | |
436 | - int detectIndex = 0; | |
437 | - | |
438 | -#ifndef _MSC_VER | |
439 | - | |
440 | - if (0) | |
441 | - { | |
442 | - gettimeofday(&first_time, NULL); | |
443 | - } | |
444 | -#endif | |
445 | - | |
446 | - for (int i = startBatch; i < tools->taskTrackers.size(); i++) //batch?直????貌?同?母????? | |
447 | - { | |
448 | - printf("i=%d\n", i); | |
449 | - if (!tools->taskTrackers[i].tracker.GetState()) | |
450 | - { | |
451 | - cout << "************************************ " << i << " pause" << endl; | |
452 | - continue; | |
453 | - } | |
454 | - | |
455 | - | |
456 | - // cout << i << " " << taskTrackers[i].TaskID << " " << resIndex << endl; | |
457 | - isUseDet = true; | |
458 | - for (int j = 0; j < FusionInterval; j++) //??帧??????一帧?????? (FusionInterval - 1)帧 | |
459 | - { | |
460 | - int width = 1920; int height = 1080; | |
461 | - //int objCount = 0; | |
462 | - if (j == 0) | |
463 | - { | |
464 | - 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]); | |
465 | - result[resIndex].objCount = objCount; | |
466 | - vector<vector<float>>().swap(detectResult[detectIndex]); | |
467 | - detectResult[detectIndex].clear(); | |
468 | - isUseDet = false; | |
469 | - } | |
470 | - else | |
471 | - { | |
472 | - VPT_Result unresult; | |
473 | - VPT_ObjInfo obj[MAX_OBJ_COUNT]; | |
474 | - 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]); | |
475 | - unUsedResult[resIndex].push_back(unresult); | |
476 | - } | |
477 | - } | |
478 | - std::cout<<"tracked obj Count : "<<result[resIndex].objCount<<"\n"; | |
479 | - resIndex++; | |
480 | - detectIndex++; | |
481 | - if (resIndex == startBatch + batchsize) | |
482 | - break; | |
483 | - } | |
484 | - | |
485 | - vector <vector< vector <float>>>().swap(detectResult); | |
486 | - | |
487 | -#ifndef _MSC_VER | |
488 | - | |
489 | - if (0) | |
490 | - { | |
491 | - gettimeofday(&second_time, NULL); | |
492 | - double time_val = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; | |
493 | - printf("tracking time_val(ms) = %lf\n", time_val / 1000.0); | |
494 | - } | |
495 | -#endif | |
496 | - | |
497 | - return SUCCESS; | |
498 | -} | |
499 | - | |
500 | - | |
501 | - | |
502 | -void VPT_Release(void * handle) | |
503 | -{ | |
504 | - objDetector *tools = (objDetector*)handle; | |
505 | - | |
506 | - if (tools) | |
507 | - { | |
508 | - if (tools->det_handle) | |
509 | - { | |
510 | - ctools_release(&tools->det_handle); | |
511 | - tools->det_handle = NULL; | |
512 | - } | |
513 | - | |
514 | - vector<TaskTracker>().swap(tools->taskTrackers); | |
515 | - | |
516 | - delete tools; | |
517 | - tools = NULL; | |
518 | - } | |
519 | -} | |
520 | - | |
521 | -void AddTaskTracker(void * handle, const int taskID, const double rWidth, const double rHeight) | |
522 | -{ | |
523 | - objDetector *tools = (objDetector*)handle; | |
524 | - TaskTracker t; | |
525 | - t.TaskID = taskID; | |
526 | - t.ratioWidth = rWidth; | |
527 | - t.ratioHeight = rHeight; | |
528 | - tools->taskTrackers.push_back(t); | |
529 | -} | |
530 | - | |
531 | -void FinishTaskTracker(void * handle, const int taskID) | |
532 | -{ | |
533 | - objDetector *tools = (objDetector*)handle; | |
534 | - for (int i = 0; i < tools->taskTrackers.size(); i++) | |
535 | - { | |
536 | - if (tools->taskTrackers[i].TaskID == taskID) | |
537 | - { | |
538 | - tools->taskTrackers.erase(tools->taskTrackers.begin() + i); | |
539 | - break; | |
540 | - } | |
541 | - } | |
542 | -} | |
543 | - | |
544 | -void PauseTaskTracker(void * handle, const int taskID) | |
545 | -{ | |
546 | - objDetector *tools = (objDetector*)handle; | |
547 | - for (int i = 0; i < tools->taskTrackers.size(); i++) | |
548 | - { | |
549 | - if (tools->taskTrackers[i].TaskID == taskID) | |
550 | - { | |
551 | - tools->taskTrackers[i].tracker.Pause(); | |
552 | - break; | |
553 | - } | |
554 | - } | |
555 | -} | |
556 | - | |
557 | -void RestartTaskTraker(void * handle, const int taskID) | |
558 | -{ | |
559 | - objDetector *tools = (objDetector*)handle; | |
560 | - for (int i = 0; i < tools->taskTrackers.size(); i++) | |
561 | - { | |
562 | - if (tools->taskTrackers[i].TaskID == taskID) | |
563 | - { | |
564 | - tools->taskTrackers[i].tracker.ReSet(); | |
565 | - break; | |
566 | - } | |
567 | - } | |
568 | -} | |
569 | - | |
570 | -void DrawTracker(void * handle, const int taskID, cv::Mat *img) | |
571 | -{ | |
572 | - objDetector *tools = (objDetector*)handle; | |
573 | - for (int i = 0; i < tools->taskTrackers.size(); i++) | |
574 | - { | |
575 | - if (tools->taskTrackers[i].TaskID == taskID) | |
576 | - { | |
577 | - tools->taskTrackers[i].tracker.addTracker(img); | |
578 | - break; | |
579 | - } | |
580 | - } | |
581 | -} | |
582 | - | |
583 | - | |
584 | - | |
585 | -int VPT_Process(void * handle, unsigned char ** bgr, int batchsize, VPT_Result *result) | |
586 | -{ | |
587 | - // isUseDet = false; | |
588 | - // } | |
589 | - | |
590 | - // } | |
591 | - // resIndex++; | |
592 | - // if (resIndex == batchsize) break; | |
593 | - //} | |
594 | - //vector <vector< vector <float>>>().swap(detectResult); | |
595 | - //vector<vector<float>>().swap(ssdResult); | |
596 | - ///*detectResult.clear(); | |
597 | - //ssdResult.clear();*/ | |
598 | - | |
599 | - return SUCCESS; | |
600 | -} | |
601 | - | |
602 | -//#include <windows.h> | |
603 | - | |
604 | - | |
605 | - | |
606 | - | |
607 | -void permute(float * image, int testWidth, int testHeight) | |
608 | -{ | |
609 | - //cv::Mat host_image; | |
610 | - float * host_image; | |
611 | - //host_image.create(testHeight, testWidth, CV_32FC3); | |
612 | - | |
613 | - host_image = (float *)malloc(testHeight*testWidth * 3 * sizeof(float));; | |
614 | - | |
615 | - float *Host_img = new float[3 * testWidth * testHeight]{};//?????诖? | |
616 | - | |
617 | - float* image_data_original = image; | |
618 | - //NPP_CHECK_CUDA(cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyDeviceToHost));//?????钥???????图???????? | |
619 | - cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyDeviceToHost);//?????钥???????图???????? | |
620 | - | |
621 | - for (int j = 0; j < testHeight; j++) | |
622 | - { | |
623 | - float *pts = host_image + j * testWidth * 3; | |
624 | - for (int i = 0; i < testWidth; i++) | |
625 | - { | |
626 | - //pts[3 * i] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 0]); //b | |
627 | - //pts[3 * i + 1] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 1]); //g | |
628 | - //pts[3 * i + 2] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 2]); //r | |
629 | - | |
630 | - pts[3 * i] = (Host_img[j * testWidth + i]); //b | |
631 | - pts[3 * i + 1] = (Host_img[testWidth * testHeight + j * testWidth + i]); //g | |
632 | - pts[3 * i + 2] = (Host_img[2 * testWidth * testHeight + j * testWidth + i]); //r | |
633 | - } | |
634 | - } | |
635 | - | |
636 | - cudaMemcpy(image_data_original, host_image, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyHostToDevice); | |
637 | - free(host_image); | |
638 | - //cv::Mat showImg; | |
639 | - //cv::resize(host_image, showImg, cv::Size(640, 480)); | |
640 | - //cv::imshow("image", showImg); | |
641 | - //cv::waitKey(0); | |
642 | -} | |
643 | - | |
644 | -cv::Mat GpuMat2OpencvMat(unsigned char* image, int width, int height) | |
645 | -{ | |
646 | - int testWidth = width; | |
647 | - int testHeight = height; | |
648 | - cv::Mat host_image; | |
649 | - host_image.create(testHeight, testWidth, CV_8UC3); | |
650 | - unsigned char *Host_img = new unsigned char[3 * testWidth * testHeight]{};//?????诖? | |
651 | - unsigned char* image_data_original = image; | |
652 | - | |
653 | - cudaError_t code = cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost);//?????钥???????图???????? | |
654 | - if (code != 0) | |
655 | - { | |
656 | - printf("==========================================================error"); | |
657 | - } | |
658 | - std::ofstream outfile("decode.bin", ios::out | ios::binary); | |
659 | - outfile.write((char*)Host_img, int(sizeof(char) * 1080 * 1920 * 3)); | |
660 | - outfile.close(); | |
661 | - | |
662 | - cudaMemcpy(host_image.data, image_data_original, 1920 * testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost);//?????钥???????图???????? | |
663 | - | |
664 | - // for (int j = 0; j < host_image.rows; j++) | |
665 | - // { | |
666 | - // uchar *pts = host_image.ptr<uchar>(j); | |
667 | - // for (int i = 0; i < host_image.cols; i++) | |
668 | - // { | |
669 | - // //pts[3 * i] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 0]); //b | |
670 | - // //pts[3 * i + 1] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 1]); //g | |
671 | - // //pts[3 * i + 2] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 2]); //r | |
672 | - // pts[3 * i] = cv::saturate_cast<uchar>(Host_img[j* host_image.cols*3 + 3 * i]); //b | |
673 | - // pts[3 * i + 1] = cv::saturate_cast<uchar>(Host_img[j* host_image.cols*3 + 3 * i + 1]); //g | |
674 | - // pts[3 * i + 2] = cv::saturate_cast<uchar>(Host_img[j* host_image.cols*3 + 3 * i + 2]); //r | |
675 | - // } | |
676 | - // } | |
677 | - cv::imwrite("input3.jpg", host_image); | |
678 | - return host_image; | |
679 | -} | |
680 | - | |
681 | - | |
682 | -int VPT_ProcessImage(void * handle, unsigned char ** bgr, int batchsize, VPT_Result * result) | |
683 | -{ | |
684 | - //objDetector* tools = (objDetector*)handle; | |
685 | - //if (bgr == NULL) //图?????荽??? | |
686 | - // return IMG_DATA_ERROR; | |
687 | - | |
688 | - //vector <Mat> imgs; | |
689 | - ////int datasize = tools->param.w * tools->param.h * tools->param.c; | |
690 | - //for (int i = 0; i < batchsize; i++) | |
691 | - //{ | |
692 | - // Mat img(tools->param.h, tools->param.w, tools->param.c, bgr[i]); | |
693 | - // imgs.push_back(img); | |
694 | - //} | |
695 | - | |
696 | - //vector<vector<float>> ssdResult; | |
697 | - ////clock_t begin = clock(); | |
698 | - //ssdResult = SSD_Detect(tools->detector, batchsize, imgs); // | |
699 | - //vector <vector< vector <float>>> detectResult(batchsize); //转??为????????要?????? | |
700 | - //for (int i = 0; i < ssdResult.size(); ++i) | |
701 | - //{ | |
702 | - // const vector<float>& d = ssdResult[i];// Detection format: [image_id, label, score, xmin, ymin, xmax, ymax) | |
703 | - // const float score = d[2]; | |
704 | - // int imgid = d[0]; | |
705 | - // if (score >= THRESHOLD) //????为left top right bottom score id | |
706 | - // { | |
707 | - // vector <float> obj; | |
708 | - // obj.push_back(d[3] * imgs[d[0]].cols); | |
709 | - // obj.push_back(d[4] * imgs[d[0]].rows); | |
710 | - // obj.push_back(d[5] * imgs[d[0]].cols); | |
711 | - // obj.push_back(d[6] * imgs[d[0]].rows); | |
712 | - // obj.push_back(d[2]); | |
713 | - // obj.push_back(d[1]); | |
714 | - // detectResult[imgid].push_back(obj); | |
715 | - // } | |
716 | - //} | |
717 | - //for (int i = 0; i < batchsize; i++) | |
718 | - //{ | |
719 | - // for (int j = 0; j < detectResult[i].size(); j++)//left top right bottom score id | |
720 | - // { | |
721 | - // result[i].obj[j].id = 0; | |
722 | - // result[i].obj[j].left = detectResult[i][j][0]; | |
723 | - // result[i].obj[j].top = detectResult[i][j][1]; | |
724 | - // result[i].obj[j].right = detectResult[i][j][2]; | |
725 | - // result[i].obj[j].bottom = detectResult[i][j][3]; | |
726 | - // result[i].obj[j].confidence = detectResult[i][j][4]; | |
727 | - // result[i].obj[j].index = detectResult[i][j][5] - 1; | |
728 | - // } | |
729 | - // | |
730 | - //} | |
731 | - | |
732 | - return SUCCESS; | |
733 | -} | |
734 | 0 | \ No newline at end of file |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/backup.h deleted
1 | -//QueryPerformanceCounter(&nSnapshotBeginTime); | |
2 | -//int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left * pThreadParam->tasks[*iter].taskHeightWidth.width) - 2); | |
3 | -//int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top * pThreadParam->tasks[*iter].taskHeightWidth.height) - 2); | |
4 | -//int right = min(pThreadParam->tasks[*iter].taskDataToBackup.width, (int)(pThreadParam->VPTResult[i].obj[c].right * pThreadParam->tasks[*iter].taskHeightWidth.width) + 2); | |
5 | -//int bottom = min(pThreadParam->tasks[*iter].taskDataToBackup.height, (int)(pThreadParam->VPTResult[i].obj[c].bottom * pThreadParam->tasks[*iter].taskHeightWidth.height) + 2); | |
6 | -// | |
7 | -// | |
8 | -//pThreadParam->tasks[*iter].taskDataToBackupHost = (float*)malloc(100 * 100 * sizeof(float)); | |
9 | -//cudaMemcpy2D(pThreadParam->tasks[*iter].taskDataToBackupHost, sizeof(float) * 100, pThreadParam->tasks[*iter].taskDataToBackup.data + 100, pitch, sizeof(float) * 100, 100, cudaMemcpyDeviceToHost); | |
10 | -//pThreadParam->SaveSnapshot(pThreadParam->tasks[*iter].taskDataToBackupHost, 100, 100, *iter, pThreadParam->VPTResult[i].obj[c].id, 0, 0, 100, 100); | |
11 | -// | |
12 | -//QueryPerformanceCounter(&nSnapshotEndTime); | |
13 | -//printf("%d %d Copy Image Time: %.2f ms \n", *iter, pThreadParam->tasks[*iter].taskFrameCount, (double)(nSnapshotEndTime.QuadPart - nSnapshotBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart); | |
14 | - | |
15 | - | |
16 | -// GPU±£´æ | |
17 | -//QueryPerformanceCounter(&nSnapshotBeginTime); | |
18 | -//char snapShotName[260]; | |
19 | -//sprintf(snapShotName, "SnapshotLittle\\%d\\%d.jpg", *iter, pThreadParam->VPTResult[i].obj[c].id); | |
20 | -//saveJPEG(snapShotName, pThreadParam->tasks[*iter].taskDataToBackup.data, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height); | |
21 | -//QueryPerformanceCounter(&nSnapshotEndTime); | |
22 | -//printf("%d %d Copy Image Time: %.2f ms \n", *iter, pThreadParam->tasks[*iter].taskFrameCount, (double)(nSnapshotEndTime.QuadPart - nSnapshotBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart); |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/header.hold deleted
1 | -#pragma once | |
2 | - | |
3 | -#ifdef _MSC_VER | |
4 | -#include <windows.h> | |
5 | -#else | |
6 | -#include <stddef.h> | |
7 | -#endif | |
8 | - | |
9 | -#include "sy_common.h" | |
10 | - | |
11 | -#define DETECTTYPE 9 | |
12 | - | |
13 | -#ifndef VD_INFO_ | |
14 | -#define VD_INFO_ | |
15 | -//结果 | |
16 | -typedef struct vd_info | |
17 | -{ | |
18 | - sy_rect rect; | |
19 | - float score; | |
20 | -}vd_info; | |
21 | -#endif | |
22 | - | |
23 | -#ifndef VCWD_INFO_ | |
24 | -#define VCWD_INFO_ | |
25 | -//结果 | |
26 | -typedef struct vcwd_info | |
27 | -{ | |
28 | - vd_info c_info; //车辆信息 | |
29 | - vd_info w_info; //车窗信息 | |
30 | -}vcwd_info; | |
31 | -#endif | |
32 | - | |
33 | -#ifndef VCWD_RESULT_ | |
34 | -#define VCWD_RESULT_ | |
35 | -#define VD_MAXDETECTCOUNT 100 //车头车尾数量最大值 | |
36 | -#define FEATURESIZE 256 | |
37 | -typedef struct vcwd_result | |
38 | -{ | |
39 | - vcwd_info * vhd_info; //车头信息 | |
40 | - int h_count; //车头数量 | |
41 | - | |
42 | - vcwd_info * vrd_info; //车尾信息 | |
43 | - int r_count; //车尾数量 | |
44 | -}vcwd_result; | |
45 | - | |
46 | -#endif | |
47 | - | |
48 | -//二次属性分析结果结构体 | |
49 | -#ifndef __HF_OBJ_RESULT__ | |
50 | -#define __HF_OBJ_RESULT__ | |
51 | -const int Hf_FIR_INDEX_SIZE = 1280; | |
52 | -typedef struct hf_result | |
53 | -{ | |
54 | - float res_objs[Hf_FIR_INDEX_SIZE]{}; //分类结果 | |
55 | -} hf_result; | |
56 | -#endif | |
57 | -//二次属性分析结果结构体 | |
58 | -#ifndef __CLASSIFY_OBJ_RESULT__ | |
59 | -#define __CLASSIFY_OBJ_RESULT__ | |
60 | -typedef struct classify_obj_res //分类结果结构体 | |
61 | -{ | |
62 | - int res_index; //分类结果 | |
63 | - float res_prob; //分类结构体 | |
64 | - classify_obj_res() : res_index(0), res_prob(0) {}; | |
65 | -} classify_obj_res; | |
66 | -#endif | |
67 | - | |
68 | -#ifndef __HF_FEA_RESULT__ | |
69 | -#define __HF_FEA_RESULT__ | |
70 | -const int HF_FEA_SIZE = 576; | |
71 | -#endif | |
72 | - | |
73 | -#ifndef __HP_OBJ_RESULT__ | |
74 | -#define __HP_OBJ_RESULT__ | |
75 | -const int HP_FIR_INDEX_SIZE = 16; | |
76 | -typedef struct hp_res | |
77 | -{ | |
78 | - classify_obj_res res_objs[HP_FIR_INDEX_SIZE]; //分类结果 | |
79 | - float feature[HF_FEA_SIZE]; //行人特征 | |
80 | -} hp_res; | |
81 | -#endif | |
82 | - | |
83 | -typedef struct hp_result | |
84 | -{ | |
85 | - hp_res res_objs{}; //分类结果 | |
86 | - float feature[Hf_FIR_INDEX_SIZE]{}; //特征 | |
87 | -} hp_result; | |
88 | - | |
89 | -#ifndef __HCF_FEA_RES__ | |
90 | -#define __HCF_FEA_RES__ | |
91 | -const int HCF_FEA_SIZE = 1280; | |
92 | -#endif | |
93 | - | |
94 | -#ifndef __HCP_OBJ_RESULT__ | |
95 | -#define __HCP_OBJ_RESULT__ | |
96 | -const int HCP_FIR_INDEX_SIZE = 14; | |
97 | -typedef struct hcp_res | |
98 | -{ | |
99 | - classify_obj_res res_objs[HCP_FIR_INDEX_SIZE]; //分类结果 | |
100 | - float feature[HCF_FEA_SIZE]; //人骑车特征 | |
101 | -} hcp_res; | |
102 | -#endif | |
103 | - | |
104 | -typedef struct hcp_result | |
105 | -{ | |
106 | - hcp_res res_objs{}; //分类结果 | |
107 | - float feature[Hf_FIR_INDEX_SIZE]{}; //特征 | |
108 | -} hcp_result; | |
109 | - | |
110 | -//VEHICLE | |
111 | -#define PLATENUM 8 //车牌号码位数 | |
112 | -#define MAX_PALTE_COUNT 10 //每张图片中最多检测出10个车牌 | |
113 | - | |
114 | -#define SINGLETYPE_BLUE 0 //单排蓝色 | |
115 | -#define SINGLETYPE_YELLOW 1 //单排黄色 | |
116 | -#define SINGLETYPE_WHITE 2 //单排白色 | |
117 | -#define SINGLETYPE_BLACK 3 //单排黑色 | |
118 | -#define DOUBLETYPE_YELLOW 4 //双排黄色 | |
119 | -#define DOUBLETYPE_WHITE 5 //双排白色 | |
120 | -#define NEWENERGYTYPE_YELLOWGREEN 6 //新能源黄绿色 | |
121 | -#define NEWENERGYTYPE_WHITEGRA 7 //新能源白绿色 | |
122 | - | |
123 | -//车牌号码 | |
124 | -#ifndef VPLATENUM_RESULT_ | |
125 | -#define VPLATENUM_RESULT_ | |
126 | -typedef struct vplate_num | |
127 | -{ | |
128 | - char character[4]; //识别结果字符 | |
129 | - float maxprob; //识别置信度 | |
130 | -}vplate_num; | |
131 | -#endif | |
132 | - | |
133 | -#ifndef VP_RESULT_ | |
134 | -#define VP_RESULT_ | |
135 | -typedef struct vplate_result | |
136 | -{ | |
137 | - sy_rect rect; //位置 | |
138 | - float detect_score; //检测置信度 | |
139 | - vplate_num recg[PLATENUM]; //识别结果 | |
140 | - float num_score; //识别置信度 | |
141 | - int type; //车牌类型 | |
142 | -}vplate_result; | |
143 | -#endif | |
144 | - | |
145 | -#ifndef VR_RESULT_ | |
146 | -#define VR_RESULT_ | |
147 | -typedef struct vr_result //结果 | |
148 | -{ | |
149 | - char vehicle_brand[260]; //车辆品牌 | |
150 | - char vehicle_subbrand[260]; //车辆子品牌 | |
151 | - char vehicle_issue_year[260]; //车辆年款 | |
152 | - char vehicle_type[260]; //车辆类型 | |
153 | - char freight_ton[260]; //货车吨级 | |
154 | - float name_score; //识别置信度 | |
155 | -}vr_result; | |
156 | -#endif | |
157 | - | |
158 | - | |
159 | - | |
160 | -//2.车颜色结果 | |
161 | -#ifndef VC_RESULT_ | |
162 | -#define VC_RESULT_ | |
163 | -typedef struct vc_result | |
164 | -{ | |
165 | - float score; | |
166 | - int index; | |
167 | -}vc_result; | |
168 | -#endif | |
169 | - | |
170 | - | |
171 | -//#ifndef __VEHICLE_RESULT__ | |
172 | -//#define __VEHICLE_RESULT__ | |
173 | -//typedef struct vehicle_res //车二次属性分析结果 | |
174 | -//{ | |
175 | -// vr_result vr_res; //车型识别结果 | |
176 | -// vc_result vc_res; //车颜色识别结果 | |
177 | -// vplate_result vp_res; //车牌检测结果 | |
178 | -//} vehicle_res; | |
179 | -// | |
180 | -//#endif | |
181 | -#ifndef __VEHICLE_RESULT__ | |
182 | -#define __VEHICLE_RESULT__ | |
183 | -typedef struct vehicle_result //车二次属性分析结果 | |
184 | -{ | |
185 | - vr_result vr_res; //车型识别结果 | |
186 | - vc_result vc_res; //车颜色识别结果 | |
187 | - vplate_result vp_res; //车牌检测结果 | |
188 | - float feature[FEATURESIZE]{}; //车辆特征 | |
189 | -} vehicle_result; | |
190 | -#endif | |
191 | -//返回的检测物体快照结果 | |
192 | -#ifndef __VIDEO_OBJECT_SNAPSHOT__ | |
193 | -#define __VIDEO_OBJECT_SNAPSHOT__ | |
194 | -typedef struct video_object_snapshot | |
195 | -{ | |
196 | - int task_id; //该物体属于的任务ID号 | |
197 | - int object_id; //该物体的ID号 | |
198 | - char video_image_path[256]; //该物体快照的视频截图保存路径 | |
199 | - char snapshot_image_path[256]; //该物体快照抠图保存路径 | |
200 | - int object_type_index; //该物体所属类别的索引 | |
201 | - char obj_type[64]; //该物体属于的类别 | |
202 | - double progress; //该路视频的检测进度 | |
203 | - | |
204 | - int left; //该物体位置的左坐标 | |
205 | - int top; //该物体位置的上坐标 | |
206 | - int right; //该物体位置的右坐标 | |
207 | - int bottom; //该物体位置的下坐标 | |
208 | - double confidence; //置信度 | |
209 | - | |
210 | - void* analysisRes; //二次属性分析结果 | |
211 | -} video_object_snapshot; | |
212 | -#endif | |
213 | - | |
214 | -//返回的检测物体结果信息 | |
215 | -#ifndef __VIDEO_OBJECT_INFO__ | |
216 | -#define __VIDEO_OBJECT_INFO__ | |
217 | -typedef struct video_object_info | |
218 | -{ | |
219 | - int task_id; //该物体属于的任务ID号 | |
220 | - int task_frame_count; //该物体当前出现的帧号 | |
221 | - int object_id; //该物体的ID号 | |
222 | - int left; //该物体位置的左坐标 | |
223 | - int top; //该物体位置的上坐标 | |
224 | - int right; //该物体位置的右坐标 | |
225 | - int bottom; //该物体位置的下坐标 | |
226 | - int index; //该物体所属类别的编号 | |
227 | - double confidence; //该物体的置信度 | |
228 | -} video_object_info; | |
229 | -#endif | |
230 | - | |
231 | -//回调函数,通知处理结束的视频,返回任务ID号 | |
232 | -typedef void(*VIDEO_OBJECT_INFO_CALLBACK)(void * handle, video_object_info *obj_info); | |
233 | - | |
234 | - | |
235 | -//回调函数,返回检测物体的快照信息 | |
236 | -typedef void(*VIDEO_OBJECT_SNAPSHOT_CALLBACK)(void * handle, video_object_snapshot *snapshot_info); | |
237 | - | |
238 | - | |
239 | -//回调函数,返回实时查看时视频的图像 | |
240 | -typedef void(*VIDEO_REALTIME_CALLBACK)(void * handle, unsigned char *img_data, int img_height, int img_width); | |
241 | - | |
242 | - | |
243 | -//回调函数,通知处理结束的视频,返回任务ID号 | |
244 | -typedef void(*VIDEO_FINISH_CALLBACK)(void * handle, const int task_id); | |
245 | - | |
246 | - | |
247 | -//TASK初始化参数 | |
248 | -#ifndef __TASK_PARAM__ | |
249 | -#define __TASK_PARAM__ | |
250 | -typedef struct task_param | |
251 | -{ | |
252 | - const char* video_filename; | |
253 | - const char* result_folder_little; | |
254 | - const char* result_folder; | |
255 | - sy_rect minBoxsize[DETECTTYPE]; //自定义的minBoxsize大小 | |
256 | - VIDEO_OBJECT_SNAPSHOT_CALLBACK obj_snapshot_callback_func; | |
257 | - VIDEO_REALTIME_CALLBACK rt_view_callback_func; | |
258 | -}task_param; | |
259 | -#endif | |
260 | - | |
261 | - | |
262 | -//VPT初始化参数 | |
263 | -#ifndef __MVPT_PARAM__ | |
264 | -#define __MVPT_PARAM__ | |
265 | -typedef struct mvpt_param | |
266 | -{ | |
267 | - int gpuid; //指定显卡id | |
268 | - char* vrdbpath; //指定车行识别的车型数据库的路径 | |
269 | - | |
270 | - //算法配置参数 | |
271 | - sy_command hp_analysis_config; //是否开启行人结构化识别 | |
272 | - sy_command hcp_analysis_config; //是否开启人骑车结构化识别 | |
273 | - sy_command vehicle_analysis_config; //是否开启车型识别 | |
274 | - sy_command hf_recg_config; //是否开启行人特征识别 | |
275 | - sy_command hcf_recg_config; //是否开启人骑车特征识别 | |
276 | - sy_command vcf_recg_config; //是否开启车辆特征识别 | |
277 | - | |
278 | - VIDEO_OBJECT_INFO_CALLBACK task_obj_info_callback_func; //目标检测结果实时返回回调函数 | |
279 | - VIDEO_FINISH_CALLBACK task_finish_callbackfunc; //任务分析结束结果回调函数 | |
280 | -}mvpt_param; | |
281 | -#endif | |
282 | - | |
283 | - | |
284 | -#ifndef _MSC_VER | |
285 | -#include <sys/time.h> | |
286 | - | |
287 | -#define MACRO_COUNT_TIME_START struct timeval macro_tv_start;\ | |
288 | - struct timeval macro_tv_end;\ | |
289 | - gettimeofday(¯o_tv_start,NULL); | |
290 | - | |
291 | -#define MACRO_COUNT_TIME_END(___total_count___) gettimeofday(¯o_tv_end,NULL);\ | |
292 | - if(___total_count___<=0)\ | |
293 | - 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);\ | |
294 | - else\ | |
295 | - 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___); | |
296 | -#endif |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/jpegNPP.hbk deleted
1 | -/* | |
2 | -* Copyright 1993-2015 NVIDIA Corporation. All rights reserved. | |
3 | -* | |
4 | -* NOTICE TO USER: | |
5 | -* | |
6 | -* This source code is subject to NVIDIA ownership rights under U.S. and | |
7 | -* international Copyright laws. | |
8 | -* | |
9 | -* NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE | |
10 | -* CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR | |
11 | -* IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH | |
12 | -* REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF | |
13 | -* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. | |
14 | -* IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, | |
15 | -* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | |
16 | -* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE | |
17 | -* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE | |
18 | -* OR PERFORMANCE OF THIS SOURCE CODE. | |
19 | -* | |
20 | -* U.S. Government End Users. This source code is a "commercial item" as | |
21 | -* that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of | |
22 | -* "commercial computer software" and "commercial computer software | |
23 | -* documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) | |
24 | -* and is provided to the U.S. Government only as a commercial end item. | |
25 | -* Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through | |
26 | -* 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the | |
27 | -* source code with only those rights set forth herein. | |
28 | -*/ | |
29 | - | |
30 | -// This sample needs at least CUDA 5.5 and a GPU that has at least Compute Capability 2.0 | |
31 | - | |
32 | -// This sample demonstrates a simple image processing pipeline. | |
33 | -// First, a JPEG file is huffman decoded and inverse DCT transformed and dequantized. | |
34 | -// Then the different planes are resized. Finally, the resized image is quantized, forward | |
35 | -// DCT transformed and huffman encoded. | |
36 | - | |
37 | -#include <npp.h> | |
38 | -#include <cuda_runtime.h> | |
39 | -#include "EnCode/Exceptions.h" | |
40 | - | |
41 | -#include "EnCode/Endianess.h" | |
42 | -#include <math.h> | |
43 | - | |
44 | -#include <string.h> | |
45 | -#include <fstream> | |
46 | -#include <iostream> | |
47 | - | |
48 | -#include <helper_string.h> | |
49 | -#include <helper_cuda.h> | |
50 | - | |
51 | -using namespace std; | |
52 | - | |
53 | -struct FrameHeader //帧图像 | |
54 | -{ | |
55 | - unsigned char nSamplePrecision; //精度:表示每个数据样本的位数 | |
56 | - unsigned short nHeight; //图像的高 像素为单位 | |
57 | - unsigned short nWidth; //图像的宽 像素为单位 | |
58 | - unsigned char nComponents; //颜色分量个数 | |
59 | - unsigned char aComponentIdentifier[3]; //颜色分量ID | |
60 | - unsigned char aSamplingFactors[3]; //水平/垂直采样因子,高4位代表水平采样因子,低4位代表垂直采样因子 | |
61 | - unsigned char aQuantizationTableSelector[3]; //当前分量使用的量化表ID | |
62 | -}; | |
63 | - | |
64 | -struct ScanHeader | |
65 | -{ | |
66 | - unsigned char nComponents; | |
67 | - unsigned char aComponentSelector[3]; | |
68 | - unsigned char aHuffmanTablesSelector[3]; | |
69 | - unsigned char nSs; | |
70 | - unsigned char nSe; | |
71 | - unsigned char nA; | |
72 | -}; | |
73 | - | |
74 | -struct QuantizationTable | |
75 | -{ | |
76 | - unsigned char nPrecisionAndIdentifier; | |
77 | - unsigned char aTable[64]; | |
78 | -}; | |
79 | - | |
80 | -struct HuffmanTable | |
81 | -{ | |
82 | - unsigned char nClassAndIdentifier; | |
83 | - unsigned char aCodes[16]; | |
84 | - unsigned char aTable[256]; | |
85 | -}; | |
86 | - | |
87 | - | |
88 | -int DivUp(int x, int d) | |
89 | -{ | |
90 | - return (x + d - 1) / d; | |
91 | -} | |
92 | - | |
93 | -template<typename T> | |
94 | -T readAndAdvance(const unsigned char *&pData) | |
95 | -{ | |
96 | - T nElement = readBigEndian<T>(pData); | |
97 | - pData += sizeof(T); | |
98 | - return nElement; | |
99 | -} | |
100 | - | |
101 | -template<typename T> | |
102 | -void writeAndAdvance(unsigned char *&pData, T nElement) | |
103 | -{ | |
104 | - writeBigEndian<T>(pData, nElement); | |
105 | - pData += sizeof(T); | |
106 | -} | |
107 | - | |
108 | - | |
109 | -int nextMarker(const unsigned char *pData, int &nPos, int nLength) | |
110 | -{ | |
111 | - unsigned char c = pData[nPos++]; | |
112 | - | |
113 | - do | |
114 | - { | |
115 | - while (c != 0xffu && nPos < nLength) | |
116 | - { | |
117 | - c = pData[nPos++]; | |
118 | - } | |
119 | - | |
120 | - if (nPos >= nLength) | |
121 | - return -1; | |
122 | - | |
123 | - c = pData[nPos++]; | |
124 | - } while (c == 0 || c == 0x0ffu); | |
125 | - | |
126 | - return c; | |
127 | -} | |
128 | - | |
129 | -void writeMarker(unsigned char nMarker, unsigned char *&pData) | |
130 | -{ | |
131 | - *pData++ = 0x0ff; | |
132 | - *pData++ = nMarker; | |
133 | -} | |
134 | - | |
135 | -void writeJFIFTag(unsigned char *&pData) | |
136 | -{ | |
137 | - const char JFIF_TAG[] = | |
138 | - { | |
139 | - 0x4a, 0x46, 0x49, 0x46, 0x00, | |
140 | - 0x01, 0x02, | |
141 | - 0x00, | |
142 | - 0x00, 0x01, 0x00, 0x01, | |
143 | - 0x00, 0x00 | |
144 | - }; | |
145 | - | |
146 | - writeMarker(0x0e0, pData); | |
147 | - writeAndAdvance<unsigned short>(pData, sizeof(JFIF_TAG) + sizeof(unsigned short)); | |
148 | - memcpy(pData, JFIF_TAG, sizeof(JFIF_TAG)); | |
149 | - pData += sizeof(JFIF_TAG); | |
150 | -} | |
151 | - | |
152 | -void loadJpeg(const char *input_file, unsigned char *&pJpegData, int &nInputLength) | |
153 | -{ | |
154 | - // Load file into CPU memory | |
155 | - ifstream stream(input_file, ifstream::binary); | |
156 | - | |
157 | - if (!stream.good()) | |
158 | - { | |
159 | - return; | |
160 | - } | |
161 | - | |
162 | - stream.seekg(0, ios::end); | |
163 | - nInputLength = (int)stream.tellg(); | |
164 | - stream.seekg(0, ios::beg); | |
165 | - | |
166 | - pJpegData = new unsigned char[nInputLength] {}; | |
167 | - stream.read(reinterpret_cast<char *>(pJpegData), nInputLength); | |
168 | -} | |
169 | - | |
170 | -void readFrameHeader(const unsigned char *pData, FrameHeader &header) | |
171 | -{ | |
172 | - readAndAdvance<unsigned short>(pData); | |
173 | - header.nSamplePrecision = readAndAdvance<unsigned char>(pData); | |
174 | - header.nHeight = readAndAdvance<unsigned short>(pData); | |
175 | - header.nWidth = readAndAdvance<unsigned short>(pData); | |
176 | - header.nComponents = readAndAdvance<unsigned char>(pData); | |
177 | - | |
178 | - for (int c = 0; c<header.nComponents; ++c) | |
179 | - { | |
180 | - header.aComponentIdentifier[c] = readAndAdvance<unsigned char>(pData); | |
181 | - header.aSamplingFactors[c] = readAndAdvance<unsigned char>(pData); | |
182 | - header.aQuantizationTableSelector[c] = readAndAdvance<unsigned char>(pData); | |
183 | - } | |
184 | - | |
185 | -} | |
186 | - | |
187 | -void writeFrameHeader(const FrameHeader &header, unsigned char *&pData) | |
188 | -{ | |
189 | - unsigned char aTemp[128]; | |
190 | - unsigned char *pTemp = aTemp; | |
191 | - | |
192 | - writeAndAdvance<unsigned char>(pTemp, header.nSamplePrecision); | |
193 | - writeAndAdvance<unsigned short>(pTemp, header.nHeight); | |
194 | - writeAndAdvance<unsigned short>(pTemp, header.nWidth); | |
195 | - writeAndAdvance<unsigned char>(pTemp, header.nComponents); | |
196 | - | |
197 | - for (int c = 0; c<header.nComponents; ++c) | |
198 | - { | |
199 | - writeAndAdvance<unsigned char>(pTemp, header.aComponentIdentifier[c]); | |
200 | - writeAndAdvance<unsigned char>(pTemp, header.aSamplingFactors[c]); | |
201 | - writeAndAdvance<unsigned char>(pTemp, header.aQuantizationTableSelector[c]); | |
202 | - } | |
203 | - | |
204 | - unsigned short nLength = (unsigned short)(pTemp - aTemp); | |
205 | - | |
206 | - writeMarker(0x0C0, pData); | |
207 | - writeAndAdvance<unsigned short>(pData, nLength + 2); | |
208 | - memcpy(pData, aTemp, nLength); | |
209 | - pData += nLength; | |
210 | -} | |
211 | - | |
212 | - | |
213 | -void readScanHeader(const unsigned char *pData, ScanHeader &header) | |
214 | -{ | |
215 | - readAndAdvance<unsigned short>(pData); | |
216 | - | |
217 | - header.nComponents = readAndAdvance<unsigned char>(pData); | |
218 | - | |
219 | - for (int c = 0; c<header.nComponents; ++c) | |
220 | - { | |
221 | - header.aComponentSelector[c] = readAndAdvance<unsigned char>(pData); | |
222 | - header.aHuffmanTablesSelector[c] = readAndAdvance<unsigned char>(pData); | |
223 | - } | |
224 | - | |
225 | - header.nSs = readAndAdvance<unsigned char>(pData); | |
226 | - header.nSe = readAndAdvance<unsigned char>(pData); | |
227 | - header.nA = readAndAdvance<unsigned char>(pData); | |
228 | -} | |
229 | - | |
230 | - | |
231 | -void writeScanHeader(const ScanHeader &header, unsigned char *&pData) | |
232 | -{ | |
233 | - unsigned char aTemp[128]; | |
234 | - unsigned char *pTemp = aTemp; | |
235 | - | |
236 | - writeAndAdvance<unsigned char>(pTemp, header.nComponents); | |
237 | - | |
238 | - for (int c = 0; c<header.nComponents; ++c) | |
239 | - { | |
240 | - writeAndAdvance<unsigned char>(pTemp, header.aComponentSelector[c]); | |
241 | - writeAndAdvance<unsigned char>(pTemp, header.aHuffmanTablesSelector[c]); | |
242 | - } | |
243 | - | |
244 | - writeAndAdvance<unsigned char>(pTemp, header.nSs); | |
245 | - writeAndAdvance<unsigned char>(pTemp, header.nSe); | |
246 | - writeAndAdvance<unsigned char>(pTemp, header.nA); | |
247 | - | |
248 | - unsigned short nLength = (unsigned short)(pTemp - aTemp); | |
249 | - | |
250 | - writeMarker(0x0DA, pData); | |
251 | - writeAndAdvance<unsigned short>(pData, nLength + 2); | |
252 | - memcpy(pData, aTemp, nLength); | |
253 | - pData += nLength; | |
254 | -} | |
255 | - | |
256 | - | |
257 | -void readQuantizationTables(const unsigned char *pData, QuantizationTable *pTables) | |
258 | -{ | |
259 | - unsigned short nLength = readAndAdvance<unsigned short>(pData) -2; | |
260 | - | |
261 | - while (nLength > 0) | |
262 | - { | |
263 | - unsigned char nPrecisionAndIdentifier = readAndAdvance<unsigned char>(pData); | |
264 | - int nIdentifier = nPrecisionAndIdentifier & 0x0f; | |
265 | - | |
266 | - pTables[nIdentifier].nPrecisionAndIdentifier = nPrecisionAndIdentifier; | |
267 | - memcpy(pTables[nIdentifier].aTable, pData, 64); | |
268 | - pData += 64; | |
269 | - | |
270 | - nLength -= 65; | |
271 | - } | |
272 | -} | |
273 | - | |
274 | -void writeQuantizationTable(const QuantizationTable &table, unsigned char *&pData) | |
275 | -{ | |
276 | - writeMarker(0x0DB, pData); | |
277 | - writeAndAdvance<unsigned short>(pData, sizeof(QuantizationTable) + 2); | |
278 | - memcpy(pData, &table, sizeof(QuantizationTable)); | |
279 | - pData += sizeof(QuantizationTable); | |
280 | -} | |
281 | - | |
282 | -void readHuffmanTables(const unsigned char *pData, HuffmanTable *pTables) | |
283 | -{ | |
284 | - unsigned short nLength = readAndAdvance<unsigned short>(pData) -2; | |
285 | - | |
286 | - while (nLength > 0) | |
287 | - { | |
288 | - unsigned char nClassAndIdentifier = readAndAdvance<unsigned char>(pData); | |
289 | - int nClass = nClassAndIdentifier >> 4; // AC or DC | |
290 | - int nIdentifier = nClassAndIdentifier & 0x0f; | |
291 | - int nIdx = nClass * 2 + nIdentifier; | |
292 | - pTables[nIdx].nClassAndIdentifier = nClassAndIdentifier; | |
293 | - | |
294 | - // Number of Codes for Bit Lengths [1..16] | |
295 | - int nCodeCount = 0; | |
296 | - | |
297 | - for (int i = 0; i < 16; ++i) | |
298 | - { | |
299 | - pTables[nIdx].aCodes[i] = readAndAdvance<unsigned char>(pData); | |
300 | - nCodeCount += pTables[nIdx].aCodes[i]; | |
301 | - } | |
302 | - | |
303 | - memcpy(pTables[nIdx].aTable, pData, nCodeCount); | |
304 | - pData += nCodeCount; | |
305 | - | |
306 | - nLength -= 17 + nCodeCount; | |
307 | - } | |
308 | -} | |
309 | - | |
310 | -void writeHuffmanTable(const HuffmanTable &table, unsigned char *&pData) | |
311 | -{ | |
312 | - writeMarker(0x0C4, pData); | |
313 | - | |
314 | - // Number of Codes for Bit Lengths [1..16] | |
315 | - int nCodeCount = 0; | |
316 | - | |
317 | - for (int i = 0; i < 16; ++i) | |
318 | - { | |
319 | - nCodeCount += table.aCodes[i]; | |
320 | - } | |
321 | - | |
322 | - writeAndAdvance<unsigned short>(pData, 17 + nCodeCount + 2); | |
323 | - memcpy(pData, &table, 17 + nCodeCount); | |
324 | - pData += 17 + nCodeCount; | |
325 | -} | |
326 | - | |
327 | - | |
328 | -void readRestartInterval(const unsigned char *pData, int &nRestartInterval) | |
329 | -{ | |
330 | - readAndAdvance<unsigned short>(pData); | |
331 | - nRestartInterval = readAndAdvance<unsigned short>(pData); | |
332 | -} | |
333 | - | |
334 | -void printHelp() | |
335 | -{ | |
336 | - cout << "jpegNPP usage" << endl; | |
337 | - cout << " -input=srcfile.jpg (input file JPEG image)" << endl; | |
338 | - cout << " -output=destfile.jpg (output file JPEG image)" << endl; | |
339 | - cout << " -scale=1.0 (scale multiplier for width and height)" << endl << endl; | |
340 | -} | |
341 | - | |
342 | -bool printfNPPinfo(int argc, char *argv[], int cudaVerMajor, int cudaVerMinor) | |
343 | -{ | |
344 | - const NppLibraryVersion *libVer = nppGetLibVersion(); | |
345 | - | |
346 | - printf("NPP Library Version %d.%d.%d\n", libVer->major, libVer->minor, libVer->build); | |
347 | - | |
348 | - int driverVersion, runtimeVersion; | |
349 | - cudaDriverGetVersion(&driverVersion); | |
350 | - cudaRuntimeGetVersion(&runtimeVersion); | |
351 | - | |
352 | - printf(" CUDA Driver Version: %d.%d\n", driverVersion / 1000, (driverVersion % 100) / 10); | |
353 | - printf(" CUDA Runtime Version: %d.%d\n", runtimeVersion / 1000, (runtimeVersion % 100) / 10); | |
354 | - | |
355 | - bool bVal = checkCudaCapabilities(cudaVerMajor, cudaVerMinor); | |
356 | - return bVal; | |
357 | -} | |
358 | - | |
359 | -const char *szInputFile; | |
360 | -const char *szOutputFile; | |
361 | -NppiSize aSrcSize[3]; | |
362 | -Npp16s *aphDCT[3] = { 0, 0, 0 }; | |
363 | -Npp16s *apdDCT[3] = { 0, 0, 0 }; | |
364 | -Npp16s *apdDCT_My[3] = { 0, 0, 0 }; | |
365 | -Npp32s aDCTStep[3]; | |
366 | - | |
367 | -Npp8u *apSrcImage[3] = { 0, 0, 0 }; | |
368 | -Npp32s aSrcImageStep[3]; | |
369 | - | |
370 | -Npp8u *apDstImage[3] = { 0, 0, 0 }; | |
371 | -Npp32s aDstImageStep[3]; | |
372 | -NppiSize aDstSize[3]; | |
373 | - | |
374 | -HuffmanTable aHuffmanTables[4]; | |
375 | -HuffmanTable *pHuffmanDCTables = aHuffmanTables; | |
376 | -HuffmanTable *pHuffmanACTables = &aHuffmanTables[2]; | |
377 | - | |
378 | -ScanHeader oScanHeader; | |
379 | -FrameHeader oFrameHeader; | |
380 | -QuantizationTable aQuantizationTables[4]; | |
381 | -Npp8u *pdQuantizationTables; | |
382 | -NppiDCTState *pDCTState; | |
383 | -int nMCUBlocksH = 0; | |
384 | -int nMCUBlocksV = 0; | |
385 | -unsigned char *pJpegData = 0; | |
386 | -int nInputLength = 0; | |
387 | - | |
388 | - | |
389 | - | |
390 | -int DecodeJPEG() | |
391 | -{ | |
392 | - //float nScaleFactor; | |
393 | - | |
394 | - szInputFile = "G:\\TestData\\人车物\\18.jpg"; | |
395 | - cout << "Source File: " << szInputFile << endl; | |
396 | - szOutputFile = "scaled.jpg"; | |
397 | - cout << "Output File: " << szOutputFile << endl; | |
398 | - | |
399 | - /*if (checkCmdLineFlag(argc, (const char **)argv, "scale")) | |
400 | - { | |
401 | - nScaleFactor = max(0.0f, min(getCmdLineArgumentFloat(argc, (const char **)argv, "scale"), 1.0f)); | |
402 | - } | |
403 | - else | |
404 | - { | |
405 | - nScaleFactor = 1.0f; | |
406 | - } | |
407 | - | |
408 | - cout << "Scale Factor: " << nScaleFactor << endl;*/ | |
409 | - | |
410 | - | |
411 | - NPP_CHECK_NPP(nppiDCTInitAlloc(&pDCTState)); | |
412 | - | |
413 | - | |
414 | - | |
415 | - // Load Jpeg | |
416 | - loadJpeg(szInputFile, pJpegData, nInputLength); | |
417 | - | |
418 | - if (pJpegData == 0) | |
419 | - { | |
420 | - cerr << "1. Input File Error: " << szInputFile << endl; | |
421 | - return EXIT_FAILURE; | |
422 | - } | |
423 | - | |
424 | - /*************************** | |
425 | - * | |
426 | - * Input | |
427 | - * | |
428 | - ***************************/ | |
429 | - | |
430 | - | |
431 | - // Check if this is a valid JPEG file | |
432 | - int nPos = 0; | |
433 | - int nMarker = nextMarker(pJpegData, nPos, nInputLength); | |
434 | - | |
435 | - if (nMarker != 0x0D8) | |
436 | - { | |
437 | - cerr << "Invalid Jpeg Image" << endl; | |
438 | - return EXIT_FAILURE; | |
439 | - } | |
440 | - | |
441 | - nMarker = nextMarker(pJpegData, nPos, nInputLength); | |
442 | - | |
443 | - // Parsing and Huffman Decoding (on host) | |
444 | - | |
445 | - cudaMalloc(&pdQuantizationTables, 64 * 4); | |
446 | - | |
447 | - | |
448 | - memset(&oFrameHeader, 0, sizeof(FrameHeader)); | |
449 | - memset(aQuantizationTables, 0, 4 * sizeof(QuantizationTable)); | |
450 | - memset(aHuffmanTables, 0, 4 * sizeof(HuffmanTable)); | |
451 | - | |
452 | - int nRestartInterval = -1; | |
453 | - | |
454 | - | |
455 | - | |
456 | - while (nMarker != -1) | |
457 | - { | |
458 | - if (nMarker == 0x0D8) | |
459 | - { | |
460 | - // Embedded Thumbnail, skip it | |
461 | - int nNextMarker = nextMarker(pJpegData, nPos, nInputLength); | |
462 | - | |
463 | - while (nNextMarker != -1 && nNextMarker != 0x0D9) | |
464 | - { | |
465 | - nNextMarker = nextMarker(pJpegData, nPos, nInputLength); | |
466 | - } | |
467 | - } | |
468 | - | |
469 | - if (nMarker == 0x0DD) | |
470 | - { | |
471 | - readRestartInterval(pJpegData + nPos, nRestartInterval); | |
472 | - } | |
473 | - | |
474 | - if ((nMarker == 0x0C0) | (nMarker == 0x0C2)) | |
475 | - { | |
476 | - //Assert Baseline for this Sample | |
477 | - //Note: NPP does support progressive jpegs for both encode and decode | |
478 | - if (nMarker != 0x0C0) | |
479 | - { | |
480 | - cerr << "The sample does only support baseline JPEG images" << endl; | |
481 | - return EXIT_SUCCESS; | |
482 | - } | |
483 | - | |
484 | - // Baseline or Progressive Frame Header | |
485 | - //读取JPEG文件头 | |
486 | - readFrameHeader(pJpegData + nPos, oFrameHeader); | |
487 | - cout << "Image Size: " << oFrameHeader.nWidth << "x" << oFrameHeader.nHeight << "x" << static_cast<int>(oFrameHeader.nComponents) << endl; | |
488 | - | |
489 | - //Assert 3-Channel Image for this Sample | |
490 | - if (oFrameHeader.nComponents != 3) | |
491 | - { | |
492 | - cerr << "The sample does only support color JPEG images" << endl; | |
493 | - return EXIT_SUCCESS; | |
494 | - } | |
495 | - | |
496 | - // Compute channel sizes as stored in the JPEG (8x8 blocks & MCU block layout) | |
497 | - for (int i = 0; i < oFrameHeader.nComponents; ++i) | |
498 | - { | |
499 | - nMCUBlocksV = max(nMCUBlocksV, oFrameHeader.aSamplingFactors[i] & 0x0f); //2 1 1 | |
500 | - nMCUBlocksH = max(nMCUBlocksH, oFrameHeader.aSamplingFactors[i] >> 4); //2 1 1 | |
501 | - } | |
502 | - | |
503 | - for (int i = 0; i < oFrameHeader.nComponents; ++i) | |
504 | - { | |
505 | - NppiSize oBlocks; | |
506 | - NppiSize oBlocksPerMCU = { oFrameHeader.aSamplingFactors[i] >> 4, oFrameHeader.aSamplingFactors[i] & 0x0f }; //水平采样因子 和 垂直采样因子 | |
507 | - | |
508 | - cout << "oBlocksPerMCU Size: " << oBlocksPerMCU.width << " " << oBlocksPerMCU.height << endl; | |
509 | - | |
510 | - oBlocks.width = (int)ceil((oFrameHeader.nWidth + 7) / 8 * | |
511 | - static_cast<float>(oBlocksPerMCU.width) / nMCUBlocksH); | |
512 | - oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width; //相除 并且 上取整 确保够所有的MCU Block的大小 | |
513 | - | |
514 | - oBlocks.height = (int)ceil((oFrameHeader.nHeight + 7) / 8 * | |
515 | - static_cast<float>(oBlocksPerMCU.height) / nMCUBlocksV); | |
516 | - oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height; | |
517 | - | |
518 | - aSrcSize[i].width = oBlocks.width * 8; | |
519 | - aSrcSize[i].height = oBlocks.height * 8; | |
520 | - | |
521 | - cout << "oBlock Size: " << oBlocks.width << " " << oBlocks.height << endl; | |
522 | - | |
523 | - // Allocate Memory | |
524 | - size_t nPitch; //返回分配的一行的内存大小 | |
525 | - NPP_CHECK_CUDA(cudaMallocPitch(&apdDCT[i], &nPitch, oBlocks.width * 64 * sizeof(Npp16s), oBlocks.height)); | |
526 | - NPP_CHECK_CUDA(cudaMallocPitch(&apdDCT_My[i], &nPitch, oBlocks.width * 64 * sizeof(Npp16s), oBlocks.height)); | |
527 | - aDCTStep[i] = static_cast<Npp32s>(nPitch); | |
528 | - | |
529 | - NPP_CHECK_CUDA(cudaMallocPitch(&apSrcImage[i], &nPitch, aSrcSize[i].width, aSrcSize[i].height)); | |
530 | - aSrcImageStep[i] = static_cast<Npp32s>(nPitch); | |
531 | - | |
532 | - NPP_CHECK_CUDA(cudaHostAlloc(&aphDCT[i], aDCTStep[i] * oBlocks.height, cudaHostAllocDefault)); | |
533 | - } | |
534 | - } | |
535 | - | |
536 | - //从压缩数据中读取量化表 | |
537 | - if (nMarker == 0x0DB) | |
538 | - { | |
539 | - // Quantization Tables | |
540 | - readQuantizationTables(pJpegData + nPos, aQuantizationTables); | |
541 | - } | |
542 | - | |
543 | - //从压缩数据中读取码表 熵编码表 | |
544 | - if (nMarker == 0x0C4) | |
545 | - { | |
546 | - // Huffman Tables | |
547 | - readHuffmanTables(pJpegData + nPos, aHuffmanTables); | |
548 | - } | |
549 | - | |
550 | - if (nMarker == 0x0DA) | |
551 | - { | |
552 | - // Scan | |
553 | - readScanHeader(pJpegData + nPos, oScanHeader); | |
554 | - nPos += 6 + oScanHeader.nComponents * 2; | |
555 | - | |
556 | - int nAfterNextMarkerPos = nPos; | |
557 | - int nAfterScanMarker = nextMarker(pJpegData, nAfterNextMarkerPos, nInputLength); | |
558 | - | |
559 | - if (nRestartInterval > 0) | |
560 | - { | |
561 | - while (nAfterScanMarker >= 0x0D0 && nAfterScanMarker <= 0x0D7) | |
562 | - { | |
563 | - // This is a restart marker, go on | |
564 | - nAfterScanMarker = nextMarker(pJpegData, nAfterNextMarkerPos, nInputLength); | |
565 | - } | |
566 | - } | |
567 | - | |
568 | - NppiDecodeHuffmanSpec *apHuffmanDCTable[3]; | |
569 | - NppiDecodeHuffmanSpec *apHuffmanACTable[3]; | |
570 | - | |
571 | - for (int i = 0; i < 3; ++i) | |
572 | - { | |
573 | - nppiDecodeHuffmanSpecInitAllocHost_JPEG(pHuffmanDCTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, nppiDCTable, &apHuffmanDCTable[i]); | |
574 | - nppiDecodeHuffmanSpecInitAllocHost_JPEG(pHuffmanACTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f)].aCodes, nppiACTable, &apHuffmanACTable[i]); | |
575 | - } | |
576 | - | |
577 | - //恢复图像数据 | |
578 | - NPP_CHECK_NPP(nppiDecodeHuffmanScanHost_JPEG_8u16s_P3R(pJpegData + nPos, nAfterNextMarkerPos - nPos - 2, | |
579 | - nRestartInterval, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, | |
580 | - aphDCT, aDCTStep, | |
581 | - apHuffmanDCTable, | |
582 | - apHuffmanACTable, | |
583 | - aSrcSize)); | |
584 | - | |
585 | - for (int i = 0; i < 3; ++i) | |
586 | - { | |
587 | - nppiDecodeHuffmanSpecFreeHost_JPEG(apHuffmanDCTable[i]); | |
588 | - nppiDecodeHuffmanSpecFreeHost_JPEG(apHuffmanACTable[i]); | |
589 | - } | |
590 | - } | |
591 | - | |
592 | - nMarker = nextMarker(pJpegData, nPos, nInputLength); | |
593 | - } | |
594 | - | |
595 | - // Copy DCT coefficients and Quantization Tables from host to device | |
596 | - for (int i = 0; i < 4; ++i) | |
597 | - { | |
598 | - NPP_CHECK_CUDA(cudaMemcpyAsync(pdQuantizationTables + i * 64, aQuantizationTables[i].aTable, 64, cudaMemcpyHostToDevice)); | |
599 | - } | |
600 | - | |
601 | - for (int i = 0; i < 3; ++i) | |
602 | - { | |
603 | - | |
604 | - cout << aDCTStep[i] << " " << aSrcSize[i].height << " " << aDCTStep[i] * aSrcSize[i].height / 8 << endl; | |
605 | - NPP_CHECK_CUDA(cudaMemcpyAsync(apdDCT[i], aphDCT[i], aDCTStep[i] * aSrcSize[i].height / 8, cudaMemcpyHostToDevice)); | |
606 | - } | |
607 | - | |
608 | - /* Inverse DCT | |
609 | - 该函数实现了将jpeg图像 解码成 YUV数据*/ | |
610 | - for (int i = 0; i < 3; ++i) | |
611 | - { | |
612 | - NPP_CHECK_NPP(nppiDCTQuantInv8x8LS_JPEG_16s8u_C1R_NEW(apdDCT[i], aDCTStep[i], | |
613 | - apSrcImage[i], aSrcImageStep[i], | |
614 | - pdQuantizationTables + oFrameHeader.aQuantizationTableSelector[i] * 64, | |
615 | - aSrcSize[i], | |
616 | - pDCTState)); | |
617 | - } | |
618 | - | |
619 | - //Npp16s | |
620 | -} | |
621 | - | |
622 | -int EncodeJPEG(char* SaveFileName) | |
623 | -{ | |
624 | - | |
625 | - | |
626 | - /*Npp8u *apSrcImageTest[3]; | |
627 | - | |
628 | - | |
629 | - for (int i = 0; i < 3; i++) | |
630 | - { | |
631 | - size_t nPitch; | |
632 | - NPP_CHECK_CUDA(cudaMalloc(&apSrcImageTest[i], 1920 * 1080 * sizeof(Npp8u))); | |
633 | - NPP_CHECK_CUDA(cudaMemcpy(apSrcImageTest[i], imgData[i], 1920 * 1080 * sizeof(Npp8u), cudaMemcpyDeviceToDevice)); | |
634 | - } | |
635 | -*/ | |
636 | - for (int i = 0; i < 3; i++) | |
637 | - { | |
638 | - NPP_CHECK_NPP(nppiDCTQuantFwd8x8LS_JPEG_8u16s_C1R_NEW(apSrcImage[i], aSrcImageStep[i], | |
639 | - apdDCT_My[i], aDCTStep[i], | |
640 | - pdQuantizationTables + oFrameHeader.aQuantizationTableSelector[i] * 64, | |
641 | - aSrcSize[i], | |
642 | - pDCTState | |
643 | - )); | |
644 | - } | |
645 | - | |
646 | - //后面的代码是关于图像编码的 | |
647 | - /*************************** | |
648 | - * | |
649 | - * Processing | |
650 | - * | |
651 | - ***************************/ | |
652 | - | |
653 | - // Compute channel sizes as stored in the output JPEG (8x8 blocks & MCU block layout) | |
654 | - /*************** 1. 求输出图像的大小********************/ | |
655 | - NppiSize oDstImageSize; | |
656 | - float frameWidth = floor((float)oFrameHeader.nWidth); //原图像大小 * 防缩比例 | |
657 | - float frameHeight = floor((float)oFrameHeader.nHeight); | |
658 | - | |
659 | - oDstImageSize.width = (int)max(1.0f, frameWidth); | |
660 | - oDstImageSize.height = (int)max(1.0f, frameHeight); | |
661 | - | |
662 | - //cout << "Output Size: " << oDstImageSize.width << "x" << oDstImageSize.height << "x" << static_cast<int>(oFrameHeader.nComponents) << endl; | |
663 | - | |
664 | - | |
665 | - /*************** 2. 求aDstSize的大小********************/ | |
666 | - for (int i = 0; i < oFrameHeader.nComponents; ++i) //3次 | |
667 | - { | |
668 | - NppiSize oBlocks; | |
669 | - NppiSize oBlocksPerMCU = { oFrameHeader.aSamplingFactors[i] & 0x0f, oFrameHeader.aSamplingFactors[i] >> 4 }; | |
670 | - | |
671 | - oBlocks.width = (int)ceil((oDstImageSize.width + 7) / 8 * | |
672 | - static_cast<float>(oBlocksPerMCU.width) / nMCUBlocksH); | |
673 | - oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width; | |
674 | - | |
675 | - oBlocks.height = (int)ceil((oDstImageSize.height + 7) / 8 * | |
676 | - static_cast<float>(oBlocksPerMCU.height) / nMCUBlocksV); | |
677 | - oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height; | |
678 | - | |
679 | - aDstSize[i].width = oBlocks.width * 8; | |
680 | - aDstSize[i].height = oBlocks.height * 8; | |
681 | - | |
682 | - //cout << "***********" << aDstSize[i].width << " " << aDstSize[i].height << "***********" << endl; | |
683 | - ////不影响保存 但是不确定能不能删除 | |
684 | - //Allocate Memory | |
685 | - size_t nPitch; | |
686 | - NPP_CHECK_CUDA(cudaMallocPitch(&apDstImage[i], &nPitch, aDstSize[i].width, aDstSize[i].height)); | |
687 | - aDstImageStep[i] = static_cast<Npp32s>(nPitch); | |
688 | - } | |
689 | - | |
690 | - /*************** 3. Huffman Encoding********************/ | |
691 | - // Huffman Encoding | |
692 | - Npp8u *pdScan; | |
693 | - Npp32s nScanLength; | |
694 | - NPP_CHECK_CUDA(cudaMalloc(&pdScan, 4 << 20)); | |
695 | - | |
696 | - Npp8u *pJpegEncoderTemp; | |
697 | - Npp32s nTempSize; | |
698 | - NPP_CHECK_NPP(nppiEncodeHuffmanGetSize(aSrcSize[0], 3, &nTempSize)); | |
699 | - NPP_CHECK_CUDA(cudaMalloc(&pJpegEncoderTemp, nTempSize)); | |
700 | - | |
701 | - NppiEncodeHuffmanSpec *apHuffmanDCTable[3]; | |
702 | - NppiEncodeHuffmanSpec *apHuffmanACTable[3]; | |
703 | - | |
704 | - for (int i = 0; i < 3; ++i) | |
705 | - { | |
706 | - nppiEncodeHuffmanSpecInitAlloc_JPEG(pHuffmanDCTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, nppiDCTable, &apHuffmanDCTable[i]); | |
707 | - nppiEncodeHuffmanSpecInitAlloc_JPEG(pHuffmanACTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f)].aCodes, nppiACTable, &apHuffmanACTable[i]); | |
708 | - } | |
709 | - | |
710 | - //Npp16s *apdDCT1[3] = { 0, 0, 0 }; | |
711 | - //Huffman Encode | |
712 | - //apdDCT = (Npp16s*)(img); | |
713 | - NPP_CHECK_NPP(nppiEncodeHuffmanScan_JPEG_8u16s_P3R(apdDCT_My, aDCTStep, | |
714 | - 0, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, | |
715 | - pdScan, &nScanLength, | |
716 | - apHuffmanDCTable, //在这之前申请 在这之后释放 | |
717 | - apHuffmanACTable, //在这之前申请 在这之后释放 | |
718 | - aDstSize, | |
719 | - pJpegEncoderTemp)); | |
720 | - | |
721 | - for (int i = 0; i < 3; ++i) | |
722 | - { | |
723 | - nppiEncodeHuffmanSpecFree_JPEG(apHuffmanDCTable[i]); | |
724 | - nppiEncodeHuffmanSpecFree_JPEG(apHuffmanACTable[i]); | |
725 | - } | |
726 | - | |
727 | - //Write JPEG | |
728 | - unsigned char *pDstJpeg = new unsigned char[4 << 20]{}; | |
729 | - unsigned char *pDstOutput = pDstJpeg; | |
730 | - | |
731 | - oFrameHeader.nWidth = oDstImageSize.width; | |
732 | - oFrameHeader.nHeight = oDstImageSize.height; | |
733 | - | |
734 | - writeMarker(0x0D8, pDstOutput); | |
735 | - writeJFIFTag(pDstOutput); | |
736 | - writeQuantizationTable(aQuantizationTables[0], pDstOutput); | |
737 | - writeQuantizationTable(aQuantizationTables[1], pDstOutput); | |
738 | - writeFrameHeader(oFrameHeader, pDstOutput); | |
739 | - writeHuffmanTable(pHuffmanDCTables[0], pDstOutput); | |
740 | - writeHuffmanTable(pHuffmanACTables[0], pDstOutput); | |
741 | - writeHuffmanTable(pHuffmanDCTables[1], pDstOutput); | |
742 | - writeHuffmanTable(pHuffmanACTables[1], pDstOutput); | |
743 | - writeScanHeader(oScanHeader, pDstOutput); | |
744 | - NPP_CHECK_CUDA(cudaMemcpy(pDstOutput, pdScan, nScanLength, cudaMemcpyDeviceToHost)); | |
745 | - pDstOutput += nScanLength; | |
746 | - writeMarker(0x0D9, pDstOutput); | |
747 | - | |
748 | - { | |
749 | - // Write result to file. | |
750 | - std::ofstream outputFile(SaveFileName, ios::out | ios::binary); | |
751 | - outputFile.write(reinterpret_cast<const char *>(pDstJpeg), static_cast<int>(pDstOutput - pDstJpeg)); | |
752 | - } | |
753 | - | |
754 | - // Cleanup | |
755 | - cudaFree(pJpegEncoderTemp); | |
756 | - cudaFree(pdScan); | |
757 | - //delete[] pJpegData; | |
758 | - delete[] pDstJpeg; | |
759 | -/* | |
760 | - | |
761 | - cudaFree(pdQuantizationTables); | |
762 | - | |
763 | - | |
764 | - nppiDCTFree(pDCTState); | |
765 | - */ | |
766 | - for (int i = 0; i < 3; ++i) | |
767 | - { | |
768 | - /* cudaFree(apdDCT[i]); | |
769 | - cudaFree(apdDCT_My[i]); | |
770 | - cudaFreeHost(aphDCT[i]); | |
771 | - cudaFree(apSrcImage[i]);*/ | |
772 | - cudaFree(apDstImage[i]); | |
773 | - } | |
774 | - | |
775 | - return EXIT_SUCCESS; | |
776 | -} | |
777 | - | |
778 | - | |
779 | - | |
780 | -// | |
781 | -//int main(int argc, char **argv) | |
782 | -//{ | |
783 | -// // Min spec is SM 2.0 devices | |
784 | -// if (printfNPPinfo(argc, argv, 2, 0) == false) | |
785 | -// { | |
786 | -// cerr << "jpegNPP requires a GPU with Compute Capability 2.0 or higher" << endl; | |
787 | -// return EXIT_SUCCESS; | |
788 | -// } | |
789 | -// | |
790 | -// const char *szInputFile; | |
791 | -// const char *szOutputFile; | |
792 | -// //float nScaleFactor; | |
793 | -// | |
794 | -// if ((argc == 1) || checkCmdLineFlag(argc, (const char **)argv, "help")) | |
795 | -// { | |
796 | -// printHelp(); | |
797 | -// } | |
798 | -// | |
799 | -// if (checkCmdLineFlag(argc, (const char **)argv, "input")) | |
800 | -// { | |
801 | -// getCmdLineArgumentString(argc, (const char **)argv, "input", (char **)&szInputFile); | |
802 | -// } | |
803 | -// else | |
804 | -// { | |
805 | -// szInputFile = sdkFindFilePath("18.jpg", argv[0]); | |
806 | -// } | |
807 | -// | |
808 | -// cout << "Source File: " << szInputFile << endl; | |
809 | -// | |
810 | -// if (checkCmdLineFlag(argc, (const char **)argv, "output")) | |
811 | -// { | |
812 | -// getCmdLineArgumentString(argc, (const char **)argv, "output", (char **)&szOutputFile); | |
813 | -// } | |
814 | -// else | |
815 | -// { | |
816 | -// szOutputFile = "scaled.jpg"; | |
817 | -// } | |
818 | -// | |
819 | -// cout << "Output File mm: " << szOutputFile << endl; | |
820 | -// | |
821 | -// /*if (checkCmdLineFlag(argc, (const char **)argv, "scale")) | |
822 | -// { | |
823 | -// nScaleFactor = max(0.0f, min(getCmdLineArgumentFloat(argc, (const char **)argv, "scale"), 1.0f)); | |
824 | -// } | |
825 | -// else | |
826 | -// { | |
827 | -// nScaleFactor = 1.0f; | |
828 | -// } | |
829 | -// | |
830 | -// cout << "Scale Factor: " << nScaleFactor << endl;*/ | |
831 | -// | |
832 | -// NppiDCTState *pDCTState; | |
833 | -// NPP_CHECK_NPP(nppiDCTInitAlloc(&pDCTState)); | |
834 | -// | |
835 | -// unsigned char *pJpegData = 0; | |
836 | -// int nInputLength = 0; | |
837 | -// | |
838 | -// // Load Jpeg | |
839 | -// loadJpeg(szInputFile, pJpegData, nInputLength); | |
840 | -// | |
841 | -// if (pJpegData == 0) | |
842 | -// { | |
843 | -// cerr << "Input File Error: " << szInputFile << endl; | |
844 | -// return EXIT_FAILURE; | |
845 | -// } | |
846 | -// | |
847 | -// /*************************** | |
848 | -// * | |
849 | -// * Input | |
850 | -// * | |
851 | -// ***************************/ | |
852 | -// | |
853 | -// | |
854 | -// // Check if this is a valid JPEG file | |
855 | -// int nPos = 0; | |
856 | -// int nMarker = nextMarker(pJpegData, nPos, nInputLength); | |
857 | -// | |
858 | -// if (nMarker != 0x0D8) | |
859 | -// { | |
860 | -// cerr << "Invalid Jpeg Image" << endl; | |
861 | -// return EXIT_FAILURE; | |
862 | -// } | |
863 | -// | |
864 | -// nMarker = nextMarker(pJpegData, nPos, nInputLength); | |
865 | -// | |
866 | -// // Parsing and Huffman Decoding (on host) | |
867 | -// FrameHeader oFrameHeader; | |
868 | -// QuantizationTable aQuantizationTables[4]; | |
869 | -// Npp8u *pdQuantizationTables; | |
870 | -// cudaMalloc(&pdQuantizationTables, 64 * 4); | |
871 | -// | |
872 | -// HuffmanTable aHuffmanTables[4]; | |
873 | -// HuffmanTable *pHuffmanDCTables = aHuffmanTables; | |
874 | -// HuffmanTable *pHuffmanACTables = &aHuffmanTables[2]; | |
875 | -// ScanHeader oScanHeader; | |
876 | -// memset(&oFrameHeader, 0, sizeof(FrameHeader)); | |
877 | -// memset(aQuantizationTables, 0, 4 * sizeof(QuantizationTable)); | |
878 | -// memset(aHuffmanTables, 0, 4 * sizeof(HuffmanTable)); | |
879 | -// int nMCUBlocksH = 0; | |
880 | -// int nMCUBlocksV = 0; | |
881 | -// | |
882 | -// int nRestartInterval = -1; | |
883 | -// | |
884 | -// NppiSize aSrcSize[3]; | |
885 | -// Npp16s *aphDCT[3] = { 0, 0, 0 }; | |
886 | -// Npp16s *apdDCT[3] = { 0, 0, 0 }; | |
887 | -// Npp32s aDCTStep[3]; | |
888 | -// | |
889 | -// Npp8u *apSrcImage[3] = { 0, 0, 0 }; | |
890 | -// Npp32s aSrcImageStep[3]; | |
891 | -// | |
892 | -// Npp8u *apDstImage[3] = { 0, 0, 0 }; | |
893 | -// Npp32s aDstImageStep[3]; | |
894 | -// NppiSize aDstSize[3]; | |
895 | -// | |
896 | -// while (nMarker != -1) | |
897 | -// { | |
898 | -// if (nMarker == 0x0D8) | |
899 | -// { | |
900 | -// // Embedded Thumbnail, skip it | |
901 | -// int nNextMarker = nextMarker(pJpegData, nPos, nInputLength); | |
902 | -// | |
903 | -// while (nNextMarker != -1 && nNextMarker != 0x0D9) | |
904 | -// { | |
905 | -// nNextMarker = nextMarker(pJpegData, nPos, nInputLength); | |
906 | -// } | |
907 | -// } | |
908 | -// | |
909 | -// if (nMarker == 0x0DD) | |
910 | -// { | |
911 | -// readRestartInterval(pJpegData + nPos, nRestartInterval); | |
912 | -// } | |
913 | -// | |
914 | -// if ((nMarker == 0x0C0) | (nMarker == 0x0C2)) | |
915 | -// { | |
916 | -// //Assert Baseline for this Sample | |
917 | -// //Note: NPP does support progressive jpegs for both encode and decode | |
918 | -// if (nMarker != 0x0C0) | |
919 | -// { | |
920 | -// cerr << "The sample does only support baseline JPEG images" << endl; | |
921 | -// return EXIT_SUCCESS; | |
922 | -// } | |
923 | -// | |
924 | -// // Baseline or Progressive Frame Header | |
925 | -// readFrameHeader(pJpegData + nPos, oFrameHeader); | |
926 | -// cout << "Image Size: " << oFrameHeader.nWidth << "x" << oFrameHeader.nHeight << "x" << static_cast<int>(oFrameHeader.nComponents) << endl; | |
927 | -// | |
928 | -// //Assert 3-Channel Image for this Sample | |
929 | -// if (oFrameHeader.nComponents != 3) | |
930 | -// { | |
931 | -// cerr << "The sample does only support color JPEG images" << endl; | |
932 | -// return EXIT_SUCCESS; | |
933 | -// } | |
934 | -// | |
935 | -// // Compute channel sizes as stored in the JPEG (8x8 blocks & MCU block layout) | |
936 | -// for (int i = 0; i < oFrameHeader.nComponents; ++i) | |
937 | -// { | |
938 | -// nMCUBlocksV = max(nMCUBlocksV, oFrameHeader.aSamplingFactors[i] & 0x0f); | |
939 | -// nMCUBlocksH = max(nMCUBlocksH, oFrameHeader.aSamplingFactors[i] >> 4); | |
940 | -// } | |
941 | -// | |
942 | -// for (int i = 0; i < oFrameHeader.nComponents; ++i) | |
943 | -// { | |
944 | -// NppiSize oBlocks; | |
945 | -// NppiSize oBlocksPerMCU = { oFrameHeader.aSamplingFactors[i] >> 4, oFrameHeader.aSamplingFactors[i] & 0x0f }; | |
946 | -// | |
947 | -// oBlocks.width = (int)ceil((oFrameHeader.nWidth + 7) / 8 * | |
948 | -// static_cast<float>(oBlocksPerMCU.width) / nMCUBlocksH); | |
949 | -// oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width; | |
950 | -// | |
951 | -// oBlocks.height = (int)ceil((oFrameHeader.nHeight + 7) / 8 * | |
952 | -// static_cast<float>(oBlocksPerMCU.height) / nMCUBlocksV); | |
953 | -// oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height; | |
954 | -// | |
955 | -// aSrcSize[i].width = oBlocks.width * 8; | |
956 | -// aSrcSize[i].height = oBlocks.height * 8; | |
957 | -// | |
958 | -// // Allocate Memory | |
959 | -// size_t nPitch; | |
960 | -// NPP_CHECK_CUDA(cudaMallocPitch(&apdDCT[i], &nPitch, oBlocks.width * 64 * sizeof(Npp16s), oBlocks.height)); | |
961 | -// aDCTStep[i] = static_cast<Npp32s>(nPitch); | |
962 | -// | |
963 | -// NPP_CHECK_CUDA(cudaMallocPitch(&apSrcImage[i], &nPitch, aSrcSize[i].width, aSrcSize[i].height)); | |
964 | -// aSrcImageStep[i] = static_cast<Npp32s>(nPitch); | |
965 | -// | |
966 | -// NPP_CHECK_CUDA(cudaHostAlloc(&aphDCT[i], aDCTStep[i] * oBlocks.height, cudaHostAllocDefault)); | |
967 | -// } | |
968 | -// } | |
969 | -// | |
970 | -// if (nMarker == 0x0DB) | |
971 | -// { | |
972 | -// // Quantization Tables | |
973 | -// readQuantizationTables(pJpegData + nPos, aQuantizationTables); | |
974 | -// } | |
975 | -// | |
976 | -// if (nMarker == 0x0C4) | |
977 | -// { | |
978 | -// // Huffman Tables | |
979 | -// readHuffmanTables(pJpegData + nPos, aHuffmanTables); | |
980 | -// } | |
981 | -// | |
982 | -// if (nMarker == 0x0DA) | |
983 | -// { | |
984 | -// // Scan | |
985 | -// readScanHeader(pJpegData + nPos, oScanHeader); | |
986 | -// nPos += 6 + oScanHeader.nComponents * 2; | |
987 | -// | |
988 | -// int nAfterNextMarkerPos = nPos; | |
989 | -// int nAfterScanMarker = nextMarker(pJpegData, nAfterNextMarkerPos, nInputLength); | |
990 | -// | |
991 | -// if (nRestartInterval > 0) | |
992 | -// { | |
993 | -// while (nAfterScanMarker >= 0x0D0 && nAfterScanMarker <= 0x0D7) | |
994 | -// { | |
995 | -// // This is a restart marker, go on | |
996 | -// nAfterScanMarker = nextMarker(pJpegData, nAfterNextMarkerPos, nInputLength); | |
997 | -// } | |
998 | -// } | |
999 | -// | |
1000 | -// NppiDecodeHuffmanSpec *apHuffmanDCTable[3]; | |
1001 | -// NppiDecodeHuffmanSpec *apHuffmanACTable[3]; | |
1002 | -// | |
1003 | -// for (int i = 0; i < 3; ++i) | |
1004 | -// { | |
1005 | -// nppiDecodeHuffmanSpecInitAllocHost_JPEG(pHuffmanDCTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, nppiDCTable, &apHuffmanDCTable[i]); | |
1006 | -// nppiDecodeHuffmanSpecInitAllocHost_JPEG(pHuffmanACTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f)].aCodes, nppiACTable, &apHuffmanACTable[i]); | |
1007 | -// } | |
1008 | -// | |
1009 | -// NPP_CHECK_NPP(nppiDecodeHuffmanScanHost_JPEG_8u16s_P3R(pJpegData + nPos, nAfterNextMarkerPos - nPos - 2, | |
1010 | -// nRestartInterval, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, | |
1011 | -// aphDCT, aDCTStep, | |
1012 | -// apHuffmanDCTable, | |
1013 | -// apHuffmanACTable, | |
1014 | -// aSrcSize)); | |
1015 | -// | |
1016 | -// for (int i = 0; i < 3; ++i) | |
1017 | -// { | |
1018 | -// nppiDecodeHuffmanSpecFreeHost_JPEG(apHuffmanDCTable[i]); | |
1019 | -// nppiDecodeHuffmanSpecFreeHost_JPEG(apHuffmanACTable[i]); | |
1020 | -// } | |
1021 | -// } | |
1022 | -// | |
1023 | -// nMarker = nextMarker(pJpegData, nPos, nInputLength); | |
1024 | -// } | |
1025 | -// | |
1026 | -// // Copy DCT coefficients and Quantization Tables from host to device | |
1027 | -// for (int i = 0; i < 4; ++i) | |
1028 | -// { | |
1029 | -// NPP_CHECK_CUDA(cudaMemcpyAsync(pdQuantizationTables + i * 64, aQuantizationTables[i].aTable, 64, cudaMemcpyHostToDevice)); | |
1030 | -// } | |
1031 | -// | |
1032 | -// for (int i = 0; i < 3; ++i) | |
1033 | -// { | |
1034 | -// NPP_CHECK_CUDA(cudaMemcpyAsync(apdDCT[i], aphDCT[i], aDCTStep[i] * aSrcSize[i].height / 8, cudaMemcpyHostToDevice)); | |
1035 | -// } | |
1036 | -// | |
1037 | -// // Inverse DCT | |
1038 | -// //该函数实现了将jpeg图像 解码成 YUV数据 | |
1039 | -// //for (int i = 0; i < 3; ++i) | |
1040 | -// //{ | |
1041 | -// // NPP_CHECK_NPP(nppiDCTQuantInv8x8LS_JPEG_16s8u_C1R_NEW(apdDCT[i], aDCTStep[i], | |
1042 | -// // apSrcImage[i], aSrcImageStep[i], | |
1043 | -// // pdQuantizationTables + oFrameHeader.aQuantizationTableSelector[i] * 64, | |
1044 | -// // aSrcSize[i], | |
1045 | -// // pDCTState)); | |
1046 | -// //} | |
1047 | -// | |
1048 | -// //后面的代码是关于图像编码的 | |
1049 | -// /*************************** | |
1050 | -// * | |
1051 | -// * Processing | |
1052 | -// * | |
1053 | -// ***************************/ | |
1054 | -// | |
1055 | -// // Compute channel sizes as stored in the output JPEG (8x8 blocks & MCU block layout) | |
1056 | -// /*************** 1. 求输出图像的大小********************/ | |
1057 | -// NppiSize oDstImageSize; | |
1058 | -// float frameWidth = floor((float)oFrameHeader.nWidth); //原图像大小 * 防缩比例 | |
1059 | -// float frameHeight = floor((float)oFrameHeader.nHeight); | |
1060 | -// | |
1061 | -// oDstImageSize.width = (int)max(1.0f, frameWidth); | |
1062 | -// oDstImageSize.height = (int)max(1.0f, frameHeight); | |
1063 | -// | |
1064 | -// cout << "Output Size: " << oDstImageSize.width << "x" << oDstImageSize.height << "x" << static_cast<int>(oFrameHeader.nComponents) << endl; | |
1065 | -// | |
1066 | -// | |
1067 | -// /*************** 2. 求aDstSize的大小********************/ | |
1068 | -// for (int i = 0; i < oFrameHeader.nComponents; ++i) //3次 | |
1069 | -// { | |
1070 | -// NppiSize oBlocks; | |
1071 | -// NppiSize oBlocksPerMCU = { oFrameHeader.aSamplingFactors[i] & 0x0f, oFrameHeader.aSamplingFactors[i] >> 4 }; | |
1072 | -// | |
1073 | -// oBlocks.width = (int)ceil((oDstImageSize.width + 7) / 8 * | |
1074 | -// static_cast<float>(oBlocksPerMCU.width) / nMCUBlocksH); | |
1075 | -// oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width; | |
1076 | -// | |
1077 | -// oBlocks.height = (int)ceil((oDstImageSize.height + 7) / 8 * | |
1078 | -// static_cast<float>(oBlocksPerMCU.height) / nMCUBlocksV); | |
1079 | -// oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height; | |
1080 | -// | |
1081 | -// aDstSize[i].width = oBlocks.width * 8; | |
1082 | -// aDstSize[i].height = oBlocks.height * 8; | |
1083 | -// | |
1084 | -// cout << "***********" << aDstSize[i].width << " " << aDstSize[i].height << "***********" << endl; | |
1085 | -// ////不影响保存 但是不确定能不能删除 | |
1086 | -// //Allocate Memory | |
1087 | -// /*size_t nPitch; | |
1088 | -// NPP_CHECK_CUDA(cudaMallocPitch(&apDstImage[i], &nPitch, aDstSize[i].width, aDstSize[i].height)); | |
1089 | -// aDstImageStep[i] = static_cast<Npp32s>(nPitch);*/ | |
1090 | -// } | |
1091 | -// | |
1092 | -// /*************** 3. Huffman Encoding********************/ | |
1093 | -// // Huffman Encoding | |
1094 | -// Npp8u *pdScan; | |
1095 | -// Npp32s nScanLength; | |
1096 | -// NPP_CHECK_CUDA(cudaMalloc(&pdScan, 4 << 20)); | |
1097 | -// | |
1098 | -// Npp8u *pJpegEncoderTemp; | |
1099 | -// Npp32s nTempSize; | |
1100 | -// NPP_CHECK_NPP(nppiEncodeHuffmanGetSize(aSrcSize[0], 3, &nTempSize)); | |
1101 | -// NPP_CHECK_CUDA(cudaMalloc(&pJpegEncoderTemp, nTempSize)); | |
1102 | -// | |
1103 | -// NppiEncodeHuffmanSpec *apHuffmanDCTable[3]; | |
1104 | -// NppiEncodeHuffmanSpec *apHuffmanACTable[3]; | |
1105 | -// | |
1106 | -// for (int i = 0; i < 3; ++i) | |
1107 | -// { | |
1108 | -// nppiEncodeHuffmanSpecInitAlloc_JPEG(pHuffmanDCTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, nppiDCTable, &apHuffmanDCTable[i]); | |
1109 | -// nppiEncodeHuffmanSpecInitAlloc_JPEG(pHuffmanACTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f)].aCodes, nppiACTable, &apHuffmanACTable[i]); | |
1110 | -// } | |
1111 | -// | |
1112 | -// //Npp16s *apdDCT1[3] = { 0, 0, 0 }; | |
1113 | -// //Huffman Encode | |
1114 | -// NPP_CHECK_NPP(nppiEncodeHuffmanScan_JPEG_8u16s_P3R(apdDCT, aDCTStep, | |
1115 | -// 0, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, | |
1116 | -// pdScan, &nScanLength, | |
1117 | -// apHuffmanDCTable, //在这之前申请 在这之后释放 | |
1118 | -// apHuffmanACTable, //在这之前申请 在这之后释放 | |
1119 | -// aDstSize, | |
1120 | -// pJpegEncoderTemp)); | |
1121 | -// | |
1122 | -// for (int i = 0; i < 3; ++i) | |
1123 | -// { | |
1124 | -// nppiEncodeHuffmanSpecFree_JPEG(apHuffmanDCTable[i]); | |
1125 | -// nppiEncodeHuffmanSpecFree_JPEG(apHuffmanACTable[i]); | |
1126 | -// } | |
1127 | -// | |
1128 | -// //Write JPEG | |
1129 | -// unsigned char *pDstJpeg = new unsigned char[4 << 20]; | |
1130 | -// unsigned char *pDstOutput = pDstJpeg; | |
1131 | -// | |
1132 | -// oFrameHeader.nWidth = oDstImageSize.width; | |
1133 | -// oFrameHeader.nHeight = oDstImageSize.height; | |
1134 | -// | |
1135 | -// writeMarker(0x0D8, pDstOutput); | |
1136 | -// writeJFIFTag(pDstOutput); | |
1137 | -// writeQuantizationTable(aQuantizationTables[0], pDstOutput); | |
1138 | -// writeQuantizationTable(aQuantizationTables[1], pDstOutput); | |
1139 | -// writeFrameHeader(oFrameHeader, pDstOutput); | |
1140 | -// writeHuffmanTable(pHuffmanDCTables[0], pDstOutput); | |
1141 | -// writeHuffmanTable(pHuffmanACTables[0], pDstOutput); | |
1142 | -// writeHuffmanTable(pHuffmanDCTables[1], pDstOutput); | |
1143 | -// writeHuffmanTable(pHuffmanACTables[1], pDstOutput); | |
1144 | -// writeScanHeader(oScanHeader, pDstOutput); | |
1145 | -// NPP_CHECK_CUDA(cudaMemcpy(pDstOutput, pdScan, nScanLength, cudaMemcpyDeviceToHost)); | |
1146 | -// pDstOutput += nScanLength; | |
1147 | -// writeMarker(0x0D9, pDstOutput); | |
1148 | -// | |
1149 | -// { | |
1150 | -// // Write result to file. | |
1151 | -// std::ofstream outputFile(szOutputFile, ios::out | ios::binary); | |
1152 | -// outputFile.write(reinterpret_cast<const char *>(pDstJpeg), static_cast<int>(pDstOutput - pDstJpeg)); | |
1153 | -// } | |
1154 | -// | |
1155 | -// // Cleanup | |
1156 | -// delete[] pJpegData; | |
1157 | -// delete[] pDstJpeg; | |
1158 | -// | |
1159 | -// cudaFree(pJpegEncoderTemp); | |
1160 | -// cudaFree(pdQuantizationTables); | |
1161 | -// cudaFree(pdScan); | |
1162 | -// | |
1163 | -// nppiDCTFree(pDCTState); | |
1164 | -// | |
1165 | -// for (int i = 0; i < 3; ++i) | |
1166 | -// { | |
1167 | -// cudaFree(apdDCT[i]); | |
1168 | -// cudaFreeHost(aphDCT[i]); | |
1169 | -// cudaFree(apSrcImage[i]); | |
1170 | -// cudaFree(apDstImage[i]); | |
1171 | -// } | |
1172 | -// | |
1173 | -// return EXIT_SUCCESS; | |
1174 | -//} |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/putText.cpp-- deleted
1 | -#include "putText.h" | |
2 | - | |
3 | -void GetStringSize(HDC hDC, const char* str, int* w, int* h) | |
4 | -{ | |
5 | - SIZE size; | |
6 | - GetTextExtentPoint32A(hDC, str, strlen(str), &size); | |
7 | - if (w != 0) *w = size.cx; | |
8 | - if (h != 0) *h = size.cy; | |
9 | -} | |
10 | - | |
11 | -void putTextZH(Mat &dst, const char* str, Point org, Scalar color, int fontSize, const char* fn, bool italic, bool underline) | |
12 | -{ | |
13 | - CV_Assert(dst.data != 0 && (dst.channels() == 1 || dst.channels() == 3)); | |
14 | - | |
15 | - int x, y, r, b; | |
16 | - if (org.x > dst.cols || org.y > dst.rows) return; | |
17 | - x = org.x < 0 ? -org.x : 0; | |
18 | - y = org.y < 0 ? -org.y : 0; | |
19 | - | |
20 | - LOGFONTA lf; | |
21 | - lf.lfHeight = -fontSize; | |
22 | - lf.lfWidth = 0; | |
23 | - lf.lfEscapement = 0; | |
24 | - lf.lfOrientation = 0; | |
25 | - lf.lfWeight = 5; | |
26 | - lf.lfItalic = italic; //斜体 | |
27 | - lf.lfUnderline = underline; //下划线 | |
28 | - lf.lfStrikeOut = 0; | |
29 | - lf.lfCharSet = DEFAULT_CHARSET; | |
30 | - lf.lfOutPrecision = 0; | |
31 | - lf.lfClipPrecision = 0; | |
32 | - lf.lfQuality = PROOF_QUALITY; | |
33 | - lf.lfPitchAndFamily = 0; | |
34 | - strcpy_s(lf.lfFaceName, fn); | |
35 | - | |
36 | - HFONT hf = CreateFontIndirectA(&lf); | |
37 | - HDC hDC = CreateCompatibleDC(0); | |
38 | - HFONT hOldFont = (HFONT)SelectObject(hDC, hf); | |
39 | - | |
40 | - int strBaseW = 0, strBaseH = 0; | |
41 | - int singleRow = 0; | |
42 | - char buf[1 << 12]; | |
43 | - strcpy_s(buf, str); | |
44 | - char *bufT[1 << 12]; // 这个用于分隔字符串后剩余的字符,可能会超出。 | |
45 | - //处理多行 | |
46 | - { | |
47 | - int nnh = 0; | |
48 | - int cw, ch; | |
49 | - | |
50 | - const char* ln = strtok_s(buf, "\n", bufT); | |
51 | - while (ln != 0) | |
52 | - { | |
53 | - GetStringSize(hDC, ln, &cw, &ch); | |
54 | - strBaseW = max(strBaseW, cw); | |
55 | - strBaseH = max(strBaseH, ch); | |
56 | - | |
57 | - ln = strtok_s(0, "\n", bufT); | |
58 | - nnh++; | |
59 | - } | |
60 | - singleRow = strBaseH; | |
61 | - strBaseH *= nnh; | |
62 | - } | |
63 | - | |
64 | - if (org.x + strBaseW < 0 || org.y + strBaseH < 0) | |
65 | - { | |
66 | - SelectObject(hDC, hOldFont); | |
67 | - DeleteObject(hf); | |
68 | - DeleteObject(hDC); | |
69 | - return; | |
70 | - } | |
71 | - | |
72 | - r = org.x + strBaseW > dst.cols ? dst.cols - org.x - 1 : strBaseW - 1; | |
73 | - b = org.y + strBaseH > dst.rows ? dst.rows - org.y - 1 : strBaseH - 1; | |
74 | - org.x = org.x < 0 ? 0 : org.x; | |
75 | - org.y = org.y < 0 ? 0 : org.y; | |
76 | - | |
77 | - BITMAPINFO bmp = { 0 }; | |
78 | - BITMAPINFOHEADER& bih = bmp.bmiHeader; | |
79 | - int strDrawLineStep = strBaseW * 3 % 4 == 0 ? strBaseW * 3 : (strBaseW * 3 + 4 - ((strBaseW * 3) % 4)); | |
80 | - | |
81 | - bih.biSize = sizeof(BITMAPINFOHEADER); | |
82 | - bih.biWidth = strBaseW; | |
83 | - bih.biHeight = strBaseH; | |
84 | - bih.biPlanes = 1; | |
85 | - bih.biBitCount = 24; | |
86 | - bih.biCompression = BI_RGB; | |
87 | - bih.biSizeImage = strBaseH * strDrawLineStep; | |
88 | - bih.biClrUsed = 0; | |
89 | - bih.biClrImportant = 0; | |
90 | - | |
91 | - void* pDibData = 0; | |
92 | - HBITMAP hBmp = CreateDIBSection(hDC, &bmp, DIB_RGB_COLORS, &pDibData, 0, 0); | |
93 | - | |
94 | - CV_Assert(pDibData != 0); | |
95 | - HBITMAP hOldBmp = (HBITMAP)SelectObject(hDC, hBmp); | |
96 | - | |
97 | - //color.val[2], color.val[1], color.val[0] | |
98 | - SetTextColor(hDC, RGB(255, 255, 255)); | |
99 | - SetBkColor(hDC, 0); | |
100 | - //SetStretchBltMode(hDC, COLORONCOLOR); | |
101 | - | |
102 | - strcpy_s(buf, str); | |
103 | - const char* ln = strtok_s(buf, "\n", bufT); | |
104 | - int outTextY = 0; | |
105 | - while (ln != 0) | |
106 | - { | |
107 | - TextOutA(hDC, 0, outTextY, ln, strlen(ln)); | |
108 | - outTextY += singleRow; | |
109 | - ln = strtok_s(0, "\n", bufT); | |
110 | - } | |
111 | - uchar* dstData = (uchar*)dst.data; | |
112 | - int dstStep = dst.step / sizeof(dstData[0]); | |
113 | - unsigned char* pImg = (unsigned char*)dst.data + org.x * dst.channels() + org.y * dstStep; | |
114 | - unsigned char* pStr = (unsigned char*)pDibData + x * 3; | |
115 | - for (int tty = y; tty <= b; ++tty) | |
116 | - { | |
117 | - unsigned char* subImg = pImg + (tty - y) * dstStep; | |
118 | - unsigned char* subStr = pStr + (strBaseH - tty - 1) * strDrawLineStep; | |
119 | - for (int ttx = x; ttx <= r; ++ttx) | |
120 | - { | |
121 | - for (int n = 0; n < dst.channels(); ++n){ | |
122 | - double vtxt = subStr[n] / 255.0; | |
123 | - int cvv = vtxt * color.val[n] + (1 - vtxt) * subImg[n]; | |
124 | - subImg[n] = cvv > 255 ? 255 : (cvv < 0 ? 0 : cvv); | |
125 | - } | |
126 | - | |
127 | - subStr += 3; | |
128 | - subImg += dst.channels(); | |
129 | - } | |
130 | - } | |
131 | - | |
132 | - SelectObject(hDC, hOldBmp); | |
133 | - SelectObject(hDC, hOldFont); | |
134 | - DeleteObject(hf); | |
135 | - DeleteObject(hBmp); | |
136 | - DeleteDC(hDC); | |
137 | -} | |
138 | 0 | \ No newline at end of file |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/putText.h- deleted
1 | -#ifndef PUTTEXT_H_ | |
2 | -#define PUTTEXT_H_ | |
3 | - | |
4 | -#include <windows.h> | |
5 | -#include <string> | |
6 | -#include <opencv2/opencv.hpp> | |
7 | - | |
8 | -using namespace cv; | |
9 | - | |
10 | -void GetStringSize(HDC hDC, const char* str, int* w, int* h); | |
11 | -void putTextZH(Mat &dst, const char* str, Point org, Scalar color, int fontSize, | |
12 | - const char *fn = "Arial", bool italic = false, bool underline = false); | |
13 | - | |
14 | -#endif // PUTTEXT_H_ | |
15 | 0 | \ No newline at end of file |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/script.mri deleted
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) |
35 | 35 | { |
36 | 36 | m_face_det_handle = nullptr; |
37 | 37 | |
38 | - //��������ʼ�� | |
39 | - fd_param fd_param_; | |
40 | - fd_param_.thresld = 0.7; | |
41 | - fd_param_.gpuid = gpuid; | |
42 | - fd_param_.mode = DEVICE_GPU; | |
43 | - fd_param_.log = SY_CONFIG_OPEN; | |
44 | - fd_param_.facial_fea_point_config = SY_CONFIG_OPEN; | |
45 | - fd_param_.pose_config = SY_CONFIG_OPEN; | |
46 | - fd_param_.quality_config = SY_CONFIG_OPEN; | |
47 | - fd_param_.score_config = SY_CONFIG_OPEN; | |
48 | - fd_param_.max_result_count = 100; | |
49 | - fd_param_.max_batch_size_detect = 10; | |
50 | - fd_param_.max_batch_size_ldmk = 10; | |
51 | - fd_param_.max_batch_size_pose = 10; | |
52 | - fd_param_.max_batch_size_score = 10; | |
53 | - fd_param_.max_batch_size_blurglass = 10; | |
54 | - fd_param_.max_batch_size_occlusion = 10; | |
55 | - fd_param_.serialize_file = "./serialize_file/FD"; | |
56 | - fd_param_.auth_license = "sy_tsl_aiplatform_sdk_2021"; | |
57 | - | |
58 | - // fd_param param; | |
59 | - // param.thresld = 0.6; | |
60 | - // param.gpuid = gpuid; | |
61 | - // param.mode = DEVICE_GPU; | |
62 | - // param.log = SY_CONFIG_OPEN; | |
63 | - // param.facial_fea_point_config = SY_CONFIG_OPEN; //�Ƿ������ؼ����� | |
64 | - // param.pose_config = SY_CONFIG_OPEN; //�Ƿ�������̬�� | |
65 | - // param.quality_config = SY_CONFIG_OPEN; //�Ƿ������������ | |
66 | - // param.score_config = SY_CONFIG_OPEN; //�Ƿ������������Ŷ� //SY_CONFIG_OPEN SY_CONFIG_CLOSE | |
67 | - // param.max_result_count = 100; | |
68 | - // param.auth_license = "sy_tsl_aiplatform_sdk_2021"; | |
69 | - | |
70 | - // if (SUCCESS != fd_init(&m_face_det_handle, fd_param_, "")) | |
71 | - if (SUCCESS != fd_init(&m_face_det_handle, fd_param_)) // 220512 | |
38 | + fd_param param; | |
39 | + param.thresld = 0.6; | |
40 | + param.gpuid = 0; | |
41 | + param.mode = DEVICE_GPU; | |
42 | + param.log = SY_CONFIG_OPEN; | |
43 | + param.facial_fea_point_config = SY_CONFIG_OPEN; //�Ƿ������ؼ����� | |
44 | + param.pose_config = SY_CONFIG_OPEN; //�Ƿ�������̬�� | |
45 | + param.quality_config = SY_CONFIG_OPEN; //�Ƿ������������ | |
46 | + param.score_config = SY_CONFIG_OPEN; //�Ƿ������������Ŷ� //SY_CONFIG_OPEN SY_CONFIG_CLOSE | |
47 | + param.max_result_count = 100; | |
48 | + param.auth_license = "sy_va_sub_sdk_2023"; | |
49 | + // param.max_batch_size_detect = 10; | |
50 | + // param.max_batch_size_ldmk = 10; | |
51 | + // param.max_batch_size_pose = 10; | |
52 | + // param.max_batch_size_score = 10; | |
53 | + // param.max_batch_size_blurglass = 10; | |
54 | + // //param.max_batch_size_hat = 4; | |
55 | + // param.max_batch_size_occlusion = 10; | |
56 | + param.serialize_file = "./serialize_file/FD"; | |
57 | + | |
58 | + | |
59 | + int flagFD = fd_init(&m_face_det_handle, param); | |
60 | + if(flagFD != 0) | |
72 | 61 | { |
73 | 62 | printf("fd_init failed\n"); |
74 | 63 | return FAILED; | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp
... | ... | @@ -4,42 +4,44 @@ |
4 | 4 | #include "opencv2/opencv.hpp" |
5 | 5 | #include "opencv2/highgui/highgui.hpp" |
6 | 6 | |
7 | -//string up[12] = { "TÐô", "Âí¼×/µõ´ø/±³ÐÄ", "³ÄÉÀ", "Î÷·þ", "ëÒÂ", "ƤÒÂ/¼Ð¿Ë", "ÓðÈÞ·þ", "´óÒÂ/·çÒÂ", "ÍâÌ×", "Á¬ÒÂȹ", "ÎÞÉÏÒÂ", "ÆäËû" }; | |
8 | -//string up_color[12] = { "ºÚ", "°×", "ºì", "»Æ", "À¶", "ÂÌ", "×Ï", "ר", "»Ò", "³È", "¶àÉ«", "ÆäËû" }; | |
9 | -//string down[6] = { "³¤¿ã", "¶Ì¿ã", "³¤È¹", "¶Ìȹ", "Á¬ÒÂȹ", "ÆäËû" }; | |
10 | -//string down_color[12] = { "ºÚ", "°×", "ºì", "»Æ", "À¶", "ÂÌ", "×Ï", "ר", "»Ò", "³È", "¶àÉ«", "ÆäËû" }; | |
11 | -//string bao[5] = { "ÎÞ°ü", "µ¥¼ç°ü", "Ë«¼ç°ü", "ÆäËû", "Ç®°ü" }; | |
12 | -//string bag_color[12] = { "ºÚ", "°×", "ºì", "»Æ", "À¶", "ÂÌ", "×Ï", "ר", "»Ò", "³È", "¶àÉ«", "ÆäËû" }; | |
13 | -//string head[6] = { "³¤·¢", "¶Ì·¢", "¹âÍ·", "ñ×Ó", "Í·¿ø", "ÆäËû" }; | |
14 | -//string clothing_text[5] = { "´¿É«", "Ë黨", "ÌõÎÆ", "¸ñ×Ó", "ÆäËû" }; | |
15 | -//string sex[3] = { "ÄÐ", "Å®", "²»Ã÷" }; | |
16 | -//string figure[3] = { "ÅÖ", "ÊÝ", "ÖÐ" }; | |
17 | -//string nationality[5] = { "ºº×å", "ά×å", "ºÚÈË", "°×ÈË", "ÆäËû" }; | |
18 | -//string age[6] = { "Ó×¶ù", "¶ùͯ", "ÇàÄê", "ÖÐÄê", "ÀÏÄê", "²»Ã÷" }; | |
19 | -//string eye[4] = { "Õý³£ÑÛ¾¦", "ÑÛ¾µ", "Ä«¾µ", "ÆäËû" }; | |
20 | -//string mouth[3] = { "Õý³£×ì", "´÷¿ÚÕÖ", "ÆäËû" }; | |
21 | -//string weibo[3] = { "ÎÞΧ½í", "ÆÕͨΧ½í", "°üͷΧ½í" }; | |
7 | +#include "../../FFNvDecoder/logger.hpp" | |
8 | + | |
9 | +//string up[12] = { "Tæ¤", "马甲/åŠå¸¦/背心", "衬衫", "西æœ", "毛衣", "皮衣/夹克", "羽绒æœ", "大衣/风衣", "外套", "连衣裙", "æ— ä¸Šè¡£", "å…¶ä»–" }; | |
10 | +//string up_color[12] = { "黑", "白", "红", "黄", "è“", "绿", "ç´«", "棕", "ç°", "æ©™", "多色", "å…¶ä»–" }; | |
11 | +//string down[6] = { "长裤", "çŸè£¤", "长裙", "çŸè£™", "连衣裙", "å…¶ä»–" }; | |
12 | +//string down_color[12] = { "黑", "白", "红", "黄", "è“", "绿", "ç´«", "棕", "ç°", "æ©™", "多色", "å…¶ä»–" }; | |
13 | +//string bao[5] = { "æ— åŒ…", "å•肩包", "åŒè‚©åŒ…", "å…¶ä»–", "钱包" }; | |
14 | +//string bag_color[12] = { "黑", "白", "红", "黄", "è“", "绿", "ç´«", "棕", "ç°", "æ©™", "多色", "å…¶ä»–" }; | |
15 | +//string head[6] = { "é•¿å‘", "çŸå‘", "光头", "帽å", "头盔", "å…¶ä»–" }; | |
16 | +//string clothing_text[5] = { "纯色", "碎花", "æ¡çº¹", "æ ¼å", "å…¶ä»–" }; | |
17 | +//string sex[3] = { "ç”·", "女", "䏿˜Ž" }; | |
18 | +//string figure[3] = { "胖", "瘦", "ä¸" }; | |
19 | +//string nationality[5] = { "汉æ—", "ç»´æ—", "黑人", "白人", "å…¶ä»–" }; | |
20 | +//string age[6] = { "幼儿", "å„¿ç«¥", "é’å¹´", "ä¸å¹´", "è€å¹´", "䏿˜Ž" }; | |
21 | +//string eye[4] = { "æ£å¸¸çœ¼ç›", "眼镜", "墨镜", "å…¶ä»–" }; | |
22 | +//string mouth[3] = { "æ£å¸¸å˜´", "戴å£ç½©", "å…¶ä»–" }; | |
23 | +//string weibo[3] = { "æ— å›´å·¾", "普通围巾", "包头围巾" }; | |
22 | 24 | // |
23 | -//string carColor[13] = { "ºÚ", "°×", "ºì", "»Æ", "À¶", "ÂÌ", "×Ï", "ר", "»Ò", "³È", "¶àÉ«", "ÆäËû", "Òø" }; | |
24 | -//string orient[3] = { "ÕýÃæ", "±³Ãæ", "²àÃæ" }; | |
25 | -//string drivenum[4] = { "0ÈË", "1ÈË", "2ÈË", "¸ü¶àÈË" }; | |
26 | -//string dasan[2] = { "ÎÞ", "ÓÐ" }; | |
27 | -//string take[2] = { "ÎÞ", "ÎïÆ·" }; | |
28 | - | |
29 | -//static std::string hcp_head[] = { "³¤·¢", "¶Ì·¢", "Í·¿ø", "ÆäËû" }; | |
30 | -//static std::string hcp_eye[] = { "δ´÷ÑÛ¾µ", "´÷ÑÛ¾µ" }; | |
31 | -//static std::string hcp_mouth[] = { "δ´÷¿ÚÕÖ", "´÷¿ÚÕÖ" }; | |
32 | -//static std::string hcp_weibo[] = { "δ´øÎ§½í", "´øÎ§½í" }; | |
33 | -//static std::string hcp_up[] = { "TÐô/±³ÐÄ", "³ÄÉÀ", "ëÒÂ", "ÍâÌ×", "Á¬ÒÂȹ", "ÆäËû" }; | |
34 | -//static std::string hcp_up_color[] = { "ºÚ", "°×", "»Ò", "ºì", "À¶", "»Æ", "ÂÌ", "¶àÉ«", "²»Ã÷" }; | |
35 | -//static std::string hcp_clothing_text[] = { "´¿É«", "Ë黨", "ÌõÎÆ¸ñ×Ó", "ÆäËû" }; | |
36 | -//static std::string hcp_bao[] = { "ÎÞ°ü", "±³°ü" }; | |
37 | -//static std::string hcp_sex[] = { "ÄÐ", "Å®", "²»Ã÷" }; | |
38 | -//static std::string hcp_age[] = { "Сº¢", "³ÉÈË", "²»Ã÷" }; | |
39 | -//static std::string hcp_carColor[] = { "ºÚ", "°×", "ºì", "ÆäËû" }; | |
40 | -//static std::string hcp_orient[] = { "ÕýÃæ", "±³Ãæ", "²àÃæ" }; | |
41 | -//static std::string hcp_dasan[] = { "ÎÞ", "ÓÐ" }; | |
42 | -//static std::string hcp_take[] = { "ÎÞ", "ÓÐ" }; | |
25 | +//string carColor[13] = { "黑", "白", "红", "黄", "è“", "绿", "ç´«", "棕", "ç°", "æ©™", "多色", "å…¶ä»–", "é“¶" }; | |
26 | +//string orient[3] = { "æ£é¢", "背é¢", "ä¾§é¢" }; | |
27 | +//string drivenum[4] = { "0人", "1人", "2人", "更多人" }; | |
28 | +//string dasan[2] = { "æ— ", "有" }; | |
29 | +//string take[2] = { "æ— ", "物å“" }; | |
30 | + | |
31 | +//static std::string hcp_head[] = { "é•¿å‘", "çŸå‘", "头盔", "å…¶ä»–" }; | |
32 | +//static std::string hcp_eye[] = { "未戴眼镜", "戴眼镜" }; | |
33 | +//static std::string hcp_mouth[] = { "未戴å£ç½©", "戴å£ç½©" }; | |
34 | +//static std::string hcp_weibo[] = { "未带围巾", "带围巾" }; | |
35 | +//static std::string hcp_up[] = { "Tæ¤/背心", "衬衫", "毛衣", "外套", "连衣裙", "å…¶ä»–" }; | |
36 | +//static std::string hcp_up_color[] = { "黑", "白", "ç°", "红", "è“", "黄", "绿", "多色", "䏿˜Ž" }; | |
37 | +//static std::string hcp_clothing_text[] = { "纯色", "碎花", "æ¡çº¹æ ¼å", "å…¶ä»–" }; | |
38 | +//static std::string hcp_bao[] = { "æ— åŒ…", "背包" }; | |
39 | +//static std::string hcp_sex[] = { "ç”·", "女", "䏿˜Ž" }; | |
40 | +//static std::string hcp_age[] = { "å°å©", "æˆäºº", "䏿˜Ž" }; | |
41 | +//static std::string hcp_carColor[] = { "黑", "白", "红", "其他" }; | |
42 | +//static std::string hcp_orient[] = { "æ£é¢", "背é¢", "ä¾§é¢" }; | |
43 | +//static std::string hcp_dasan[] = { "æ— ", "有" }; | |
44 | +//static std::string hcp_take[] = { "æ— ", "有" }; | |
43 | 45 | |
44 | 46 | const int FIR_INDEX_SIZE = 14; |
45 | 47 | 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) |
64 | 66 | #include <fstream> |
65 | 67 | int HumanCarParsing_Process(void * handle, sy_img * batch_img, int batch_size, hcp_analysis_result *&result) |
66 | 68 | { |
67 | - //ctools_result *result=NULL; | |
69 | + // vector<sy_img> vec_batch_img(batch_size); | |
70 | + // for (int i = 0; i < batch_size; i++) | |
71 | + // { | |
72 | + // if (batch_img[i].data_ == NULL) { | |
73 | + // cout << i << " data null" << endl; | |
74 | + // return -1; | |
75 | + // } | |
76 | + // int data_size = batch_img[i].c_ * batch_img[i].h_ * batch_img[i].w_ ; | |
77 | + // cout << "data size:" << data_size << endl; | |
78 | + // unsigned char *snapshotDataHost = new unsigned char[data_size] {}; | |
79 | + // cudaMemcpy(snapshotDataHost, batch_img[i].data_, data_size * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
80 | + | |
81 | + // sy_img tmp_img = batch_img[i]; | |
82 | + // tmp_img.data_ = snapshotDataHost; | |
83 | + | |
84 | + // vec_batch_img.push_back(tmp_img); | |
85 | + // } | |
86 | + | |
87 | + sy_img cpu_batch_img[batch_size]; | |
68 | 88 | for (int i = 0; i < batch_size; i++) |
69 | 89 | { |
70 | 90 | if (batch_img[i].data_ == NULL) |
91 | + { | |
71 | 92 | cout << i << " data null" << endl; |
93 | + LOG_ERROR("") | |
94 | + return FAILED; | |
95 | + } | |
96 | + cpu_batch_img[i].data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char)); | |
97 | + 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); | |
98 | + cpu_batch_img[i].w_ = batch_img[i].w_; | |
99 | + cpu_batch_img[i].h_ = batch_img[i].h_; | |
100 | + cpu_batch_img[i].c_ = batch_img[i].c_; | |
72 | 101 | } |
73 | 102 | |
74 | 103 | //cout << "begin hcp ProcessBatch" << endl; |
75 | - hcp_batch(handle, batch_img, batch_size, result); | |
104 | + hcp_batch(handle, cpu_batch_img, batch_size, result); | |
76 | 105 | |
77 | 106 | for (int b = 0; b < batch_size; b++) |
78 | 107 | { |
... | ... | @@ -93,6 +122,8 @@ int HumanCarParsing_Process(void * handle, sy_img * batch_img, int batch_size, |
93 | 122 | //printf("HumanCarParsing_Process ERROR!!!!!!!!!!!! %d %d %d\n", i, cur_result.res_objs[i].res_index, SEC_INDEX_SIZE[i]); |
94 | 123 | } |
95 | 124 | } |
125 | + | |
126 | + free(cpu_batch_img[b].data_) ; | |
96 | 127 | } |
97 | 128 | |
98 | 129 | //cout << "end hcp ProcessBatch" << endl; |
... | ... | @@ -124,7 +155,7 @@ int HumanCarParsing_Process(void * handle, sy_img * batch_img, int batch_size, |
124 | 155 | // //int resIndex = result[j][i].index; |
125 | 156 | // int resIndex = index_score.data_[i * 2]; |
126 | 157 | //cout << "resIndex" << endl; |
127 | - // //Êä³ö½á¹û | |
158 | + // //������ | |
128 | 159 | // switch (i) |
129 | 160 | // { |
130 | 161 | // case 0: | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFeatures.cppbk deleted
1 | -#include "HumanFeatures.h" | |
2 | -#include <iostream> | |
3 | -#include "sy_errorinfo.h" | |
4 | -using namespace std; | |
5 | - | |
6 | -int human_features_init(void *&handle, char*dbpath, int gpuid) | |
7 | -{ | |
8 | - hf_param params; | |
9 | - params.gpuid = gpuid; | |
10 | - params.mode = DEVICE_GPU; | |
11 | -// params.db_path = dbpath; | |
12 | - if (hf_init(&handle, params) !=0) | |
13 | - { | |
14 | - cout << "Init HF Failed!" << endl; | |
15 | - return FAILED; | |
16 | - | |
17 | - } | |
18 | - return SUCCESS; | |
19 | -} | |
20 | - | |
21 | -int human_features_process(void * handle, sy_img * batch_img, int batch_size, hf_result*& result) | |
22 | -{ | |
23 | - for (int i = 0; i < batch_size; i++) | |
24 | - { | |
25 | - if (batch_img[i].data_ == NULL) | |
26 | - cout << i << " data null" << endl; | |
27 | - } | |
28 | - | |
29 | - hf_feature_batch(handle, batch_img, batch_size, result); | |
30 | - return SUCCESS; | |
31 | -} | |
32 | - | |
33 | -int human_feature_release(void *& handle) | |
34 | -{ | |
35 | - hf_release(&handle); | |
36 | - return SUCCESS; | |
37 | -} |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanFeatures.hbk deleted
1 | -#ifndef _HUMANFEATURES_H_ | |
2 | -#define _HUMANFEATURES_H_ | |
3 | -#include "human_features.h" | |
4 | - | |
5 | -int human_features_init(void *&handle, char*dbpath, int gpuid); | |
6 | - | |
7 | -int human_features_process(void * handle, sy_img * batch_img, int batch_size, hf_result*& result); | |
8 | - | |
9 | -int human_feature_release(void *& handle); | |
10 | -#endif |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/CycleQueue.h deleted
1 | -#include <iostream> | |
2 | - | |
3 | -using namespace std; | |
4 | - | |
5 | -#define MAX_LENGTH 100 | |
6 | - | |
7 | -typedef struct TRACK_POINT | |
8 | -{ | |
9 | - int x; | |
10 | - int y; | |
11 | -}TRACK_POINT; | |
12 | - | |
13 | -//template <class T> | |
14 | -class cycleQueue | |
15 | -{ | |
16 | -private: | |
17 | - unsigned int m_size; | |
18 | - int m_front; | |
19 | - int m_rear; | |
20 | - TRACK_POINT m_data[MAX_LENGTH]; | |
21 | - | |
22 | - bool firstPush; | |
23 | - bool full_size; | |
24 | - | |
25 | -public: | |
26 | - | |
27 | - cycleQueue() {} | |
28 | - | |
29 | - cycleQueue(unsigned size) | |
30 | - :m_size(size), | |
31 | - m_front(0), | |
32 | - m_rear(0) | |
33 | - { | |
34 | - //m_data = new TRACK_POINT[size]; | |
35 | - full_size = false; | |
36 | - firstPush = true; | |
37 | - } | |
38 | - | |
39 | - void set_param(unsigned size) | |
40 | - { | |
41 | - m_size = size; | |
42 | - //m_data = new TRACK_POINT[size]; | |
43 | - full_size = false; | |
44 | - firstPush = true; | |
45 | - m_front = 0; | |
46 | - m_rear = 0; | |
47 | - } | |
48 | - | |
49 | - ~cycleQueue() | |
50 | - { | |
51 | - //delete[] m_data; | |
52 | - } | |
53 | - | |
54 | - bool isEmpty() | |
55 | - { | |
56 | - return m_front == m_rear; | |
57 | - } | |
58 | - | |
59 | - bool isFull() | |
60 | - { | |
61 | - return m_front == (m_rear + 1) % m_size; | |
62 | - } | |
63 | - | |
64 | - int getFront() | |
65 | - { | |
66 | - return m_front; | |
67 | - } | |
68 | - | |
69 | - int getRear() | |
70 | - { | |
71 | - return m_rear; | |
72 | - } | |
73 | - | |
74 | - int size() | |
75 | - { | |
76 | - if (full_size) return m_size; | |
77 | - else if (m_rear == m_front && firstPush == false) return m_size; | |
78 | - else return m_rear - m_front; | |
79 | - } | |
80 | - | |
81 | - void push(TRACK_POINT ele)throw(bad_exception) | |
82 | - { | |
83 | - if (m_front == m_rear && firstPush==false) | |
84 | - { | |
85 | - m_front = (m_front + 1) % m_size; | |
86 | - full_size = true; | |
87 | - //cout << "full_size" << endl; | |
88 | - } | |
89 | - | |
90 | - m_data[m_rear] = ele; | |
91 | - m_rear = (m_rear + 1) % m_size; | |
92 | - firstPush = false; | |
93 | - } | |
94 | - | |
95 | - TRACK_POINT pop() throw(bad_exception) | |
96 | - { | |
97 | - if (isEmpty()) | |
98 | - { | |
99 | - throw bad_exception(); | |
100 | - } | |
101 | - TRACK_POINT tmp = m_data[m_front]; | |
102 | - m_front = (m_front + 1) % m_size; | |
103 | - return tmp; | |
104 | - } | |
105 | - | |
106 | - TRACK_POINT& get(int i) | |
107 | - { | |
108 | - //T tmp = m_data[i]; | |
109 | - return m_data[i]; | |
110 | - } | |
111 | -}; | |
112 | 0 | \ No newline at end of file |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/HungarianAlgorithm.cpp deleted
1 | -#include <vector> | |
2 | -#include <assert.h> | |
3 | -#include "HungarianAlgorithm.h" | |
4 | - | |
5 | -using namespace std; | |
6 | - | |
7 | - | |
8 | -// B = A( extractRows, extractCols ) | |
9 | -// Require: | |
10 | -// extractRows.size()==A.rows, extractCols.size()==A.cols | |
11 | -// sum(extractRows)==B.rows, sum(extractCols)==B.cols | |
12 | -void extractGrids(const cv::Mat &A, const vector<bool> &extractRows, const vector<bool> &extractCols, cv::Mat &B) | |
13 | -{ | |
14 | - typedef float ValueType; | |
15 | - ValueType *pt1 = (ValueType*)A.data, *pt2 = (ValueType*)B.data, *pt3, *pt4; | |
16 | - const int step1 = A.step1(), rows = A.rows, cols = A.cols, step2 = B.step1(); | |
17 | - vector<bool>::const_iterator it1, it2, it3 = extractRows.end(), it4 = extractCols.end(); | |
18 | - for (it1 = extractRows.begin(); it1 != it3; pt1 += step1){ | |
19 | - pt3 = pt1; | |
20 | - if (*(it1++)){ | |
21 | - pt4 = pt2; | |
22 | - for (it2 = extractCols.begin(); it2 != it4; pt3++) | |
23 | - if (*(it2++)) | |
24 | - *(pt4++) = *pt3; | |
25 | - pt2 += step2; | |
26 | - } | |
27 | - } | |
28 | -} | |
29 | - | |
30 | -// B = A( extract ) | |
31 | -// Require: | |
32 | -// min(A.rows,A.cols) ==1 | |
33 | -// if(A.rows)==1, then require: A.cols==extract.size(), B.rows==1, sum(extract)==B.cols | |
34 | -// if(A.cols)==1, then require: A.rows==extract.size(), B.cols==1, sum(extract)==B.rows | |
35 | -void extractDots(const cv::Mat &A, const vector<bool> &extract, cv::Mat &B) | |
36 | -{ | |
37 | - assert(A.rows == 1 || A.cols == 1); | |
38 | - typedef float ValueType; | |
39 | - ValueType *pt1 = (ValueType*)A.data, *pt2 = (ValueType*)B.data; | |
40 | - vector<bool>::const_iterator it = extract.begin(), it2 = extract.end(); | |
41 | - if (A.rows == 1){ | |
42 | - for (; it != it2; pt1++) | |
43 | - if (*(it++)) | |
44 | - *(pt2++) = *pt1; | |
45 | - } | |
46 | - else{ | |
47 | - int step1 = A.step1(), step2 = B.step1(); | |
48 | - for (; it != it2; pt1 += step1) | |
49 | - if (*(it++)){ | |
50 | - *pt2 = *pt1; | |
51 | - pt2 += step2; | |
52 | - } | |
53 | - } | |
54 | -} | |
55 | - | |
56 | - | |
57 | -/* Initial Matlab code comes from: | |
58 | -http://www.mathworks.com/matlabcentral/fileexchange/20652-hungarian-algorithm-for-linear-assignment-problems--v2-3- | |
59 | - | |
60 | -Hungarian algorithm for matrix assignment problem. | |
61 | -costMat: there are (rows) works and (cols) jobs. costMat(i,j) means the cost of assigning job (j) to worker (i). | |
62 | -The problem is to solve a holistic optimization problem of assigning each worker a job! | |
63 | -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). | |
64 | - | |
65 | -Negatives in costMat means the corresponding assignments are forbidden. | |
66 | -*/ | |
67 | -void munkres(cv::Mat &IoUMat, vector<int> &assignment) | |
68 | -{ | |
69 | - assert(IoUMat.type() == CV_32FC1); | |
70 | - const int rows = IoUMat.rows, cols = IoUMat.cols; | |
71 | - assignment.assign(rows, -1); | |
72 | - // modify input port O - IoU = cost | |
73 | - cv::Mat O = cv::Mat::ones(rows, cols, CV_32FC1); | |
74 | - cv::Mat costMat(rows, cols, CV_32FC1); | |
75 | - absdiff(O, IoUMat, costMat); | |
76 | - | |
77 | - cv::Mat validMat(rows, cols, CV_8UC1); | |
78 | - compare(costMat, cv::Scalar(0), validMat, cv::CMP_GE); | |
79 | - | |
80 | - float *ptF, *ptF2; | |
81 | - uchar *ptU, *ptU2; | |
82 | - int stepGap; | |
83 | - int r, c, i; | |
84 | - unsigned j; | |
85 | - vector<bool>::iterator it1, it2; | |
86 | - vector<int>::iterator it3, it4; | |
87 | - | |
88 | - // validCol & validRow | |
89 | - vector<bool> validRow(rows, false); | |
90 | - ptU = validMat.data; | |
91 | - for (r = 0; r<rows; r++){ | |
92 | - ptU2 = ptU; | |
93 | - for (c = 0; c<cols; c++) if (*(ptU2++)) break; | |
94 | - if (c<cols) validRow[r] = true; | |
95 | - ptU += validMat.step; | |
96 | - } | |
97 | - vector<bool> validCol(cols, false); | |
98 | - ptU = validMat.data; | |
99 | - for (c = 0; c<cols; c++){ | |
100 | - ptU2 = ptU; | |
101 | - for (r = 0; r<rows; r++) if (*ptU2) break; else ptU2 += validMat.step; | |
102 | - if (r<rows) validCol[c] = true; | |
103 | - ptU++; | |
104 | - } | |
105 | - | |
106 | - // nRows & nCols | |
107 | - int nRows = 0, nCols = 0; | |
108 | - it1 = validRow.begin(), it2 = validCol.begin(); | |
109 | - r = 0; while (r++<rows) if (*(it1++)) nRows++; | |
110 | - c = 0; while (c++<cols) if (*(it2++)) nCols++; | |
111 | - const int n = nRows>nCols ? nRows : nCols; | |
112 | - if (!n) | |
113 | - return; | |
114 | - | |
115 | - // sumValid & maxValid | |
116 | - float sumValid = 0, maxValid = -1.f; | |
117 | - ptF = (float*)costMat.data; | |
118 | - ptU = validMat.data; | |
119 | - stepGap = validMat.step - validMat.cols; | |
120 | - r = 0; while (r++<rows){ | |
121 | - c = 0; while (c++<cols){ | |
122 | - if (*(ptU++)){ | |
123 | - float v = *(ptF++); sumValid += v; | |
124 | - if (v>maxValid) maxValid = v; | |
125 | - } | |
126 | - else ptF++; | |
127 | - } ptU += stepGap; | |
128 | - } | |
129 | - | |
130 | - // bigM & maxValid | |
131 | - maxValid *= 10.f; | |
132 | - float bigM = log10f(sumValid); | |
133 | - int power = (int)ceilf(bigM) + 1; | |
134 | - bigM = 1.f; //bigM = pow( 10, power ); | |
135 | - for (i = 0; i<power; i++) | |
136 | - bigM *= 10; | |
137 | - | |
138 | - // costMat(~validMat) = bigM; | |
139 | - validMat = ~validMat; // validMat 其实已经是 invalidMat! | |
140 | - costMat.setTo(bigM, validMat); | |
141 | - | |
142 | - // dMat | |
143 | - cv::Mat dMat(n, n, CV_32FC1, cv::Scalar(maxValid)); | |
144 | - | |
145 | - | |
146 | - cv::Mat temp = dMat(cv::Rect(0, 0, nCols, nRows)); //by zl | |
147 | - extractGrids(costMat, validRow, validCol, temp); | |
148 | - | |
149 | - //extractGrids(costMat, validRow, validCol, dMat(cv::Rect(0, 0, nCols, nRows))); | |
150 | - | |
151 | - //************************************************* | |
152 | - // Munkres' Assignment Algorithm starts here | |
153 | - //************************************************* | |
154 | - | |
155 | - // some storage for temporary usage | |
156 | - cv::Mat tmp1(n, n, CV_32FC1); // size and type accords with dMat | |
157 | - cv::Mat tmp2(n, n, CV_32FC1); | |
158 | - cv::Mat tmp3(n, n, CV_32FC1); | |
159 | - cv::Mat tmp4(n, n, CV_8UC1); | |
160 | - cv::Mat tmp5(n, 1, CV_32FC1); | |
161 | - cv::Mat tmp6(1, n, CV_32FC1); | |
162 | - | |
163 | - // STEP 1: Subtract the row minimum from each row. | |
164 | - // minR & minC | |
165 | - cv::Mat minR, minC; | |
166 | - reduce(dMat, minR, 1, cv::REDUCE_MIN); | |
167 | - repeat(minR, 1, n, tmp1); | |
168 | - tmp2 = dMat - tmp1; | |
169 | - reduce(tmp2, minC, 0, cv::REDUCE_MIN); | |
170 | - repeat(minC, n, 1, tmp2); | |
171 | - | |
172 | - // STEP 2: Find a zero of dMat. If there are no starred zeros in its column or row start the zero. Repeat for each zero | |
173 | - // zP | |
174 | - cv::Mat zP(n, n, CV_8UC1); | |
175 | - tmp3 = tmp1 + tmp2; | |
176 | - compare(dMat, tmp3, zP, cv::CMP_EQ); | |
177 | - | |
178 | - // starZ | |
179 | - vector<int> starZ(n, -1); | |
180 | - ptU = zP.data; | |
181 | - for (r = 0; r<n; r++){ | |
182 | - ptU2 = ptU; | |
183 | - for (c = 0; c<n; c++){ | |
184 | - if (*(ptU2++)){ | |
185 | - starZ[r] = c; | |
186 | - memset(ptU, 0, r); // zP(r,:)=false; | |
187 | - zP.col(c) = cv::Scalar(0); // zP(:,c)=false; | |
188 | - break; | |
189 | - } | |
190 | - } | |
191 | - ptU += zP.step; | |
192 | - } | |
193 | - | |
194 | - int uZc, uZr; | |
195 | - | |
196 | - while (1){ // STEP 3 | |
197 | - // Cover each column with a starred zero. If all the columns are covered then the matching is maximum | |
198 | - it3 = starZ.begin(); | |
199 | - for (; it3 != starZ.end(); it3++) if (*it3<0) break; | |
200 | - if (it3 == starZ.end()) break; | |
201 | - | |
202 | - // validColumn & validRow & primeZ | |
203 | - vector<bool> noncoverColumn(n, true); | |
204 | - for (it3 = starZ.begin(); it3 != starZ.end(); it3++){ | |
205 | - if (*it3<0) continue; | |
206 | - noncoverColumn[*it3] = false; | |
207 | - } | |
208 | - vector<bool> noncoverRow(n, true); | |
209 | - vector<int> primeZ(n, -1); | |
210 | - | |
211 | - // minC_uncovered & minR_uncovered | |
212 | - int cnt1 = 0, cnt2 = 0; | |
213 | - it1 = noncoverColumn.begin(), it2 = noncoverRow.begin(); | |
214 | - i = 0; while (i++<n){ | |
215 | - if (*(it1++)) cnt1++; // number of non-covered columns | |
216 | - if (*(it2++)) cnt2++; // number of non-covered rows | |
217 | - } | |
218 | - cv::Mat minR_uncovered = tmp5.rowRange(0, cnt2); | |
219 | - cv::Mat minC_uncovered = tmp6.colRange(0, cnt1); | |
220 | - extractDots(minR, noncoverRow, minR_uncovered); | |
221 | - extractDots(minC, noncoverColumn, minC_uncovered); | |
222 | - | |
223 | - // rIdx & cIdx | |
224 | - cv::Mat temp1 = tmp1(cv::Rect(0, 0, cnt1, cnt2)); | |
225 | - cv::Mat temp2 = tmp2(cv::Rect(0, 0, cnt1, cnt2)); | |
226 | - cv::Mat temp3 = tmp3(cv::Rect(0, 0, cnt1, cnt2)); | |
227 | - cv::Mat temp4 = tmp4(cv::Rect(0, 0, cnt1, cnt2)); | |
228 | - repeat(minR_uncovered, 1, cnt1, temp1); | |
229 | - repeat(minC_uncovered, cnt2, 1, temp2); | |
230 | - temp2 = temp1 + temp2; | |
231 | - extractGrids(dMat, noncoverRow, noncoverColumn, temp3); | |
232 | - compare(temp2, temp3, temp4, cv::CMP_EQ); | |
233 | - vector<int> rIdx, cIdx; // [rIdx,cIdx] = find(temp4); | |
234 | - ptU = temp4.data; | |
235 | - stepGap = temp4.step - temp4.cols; | |
236 | - for (r = 0; r<temp4.rows; r++){ | |
237 | - for (c = 0; c<temp4.cols; c++){ | |
238 | - if (*(ptU++)){ | |
239 | - rIdx.push_back(r); | |
240 | - cIdx.push_back(c); | |
241 | - } | |
242 | - } | |
243 | - ptU += stepGap; | |
244 | - } | |
245 | - | |
246 | - while (1){ // STEP 4 | |
247 | - // Find a non-covered zero and prime it. If there is no starred zero in the row containing this primed zero, Go to Step 5. | |
248 | - // Otherwise, cover this row and uncover the column containing the starred zero. Continue in this manner until there are no | |
249 | - // uncovered zeros left. Save the smallest uncovered value and Go to Step 6. | |
250 | - | |
251 | - // cR & cC | |
252 | - vector<int> cR, cC; | |
253 | - for (j = 0; j<noncoverRow.size(); j++) | |
254 | - if (noncoverRow[j]) | |
255 | - cR.push_back(j); | |
256 | - for (j = 0; j<noncoverColumn.size(); j++) | |
257 | - if (noncoverColumn[j]) | |
258 | - cC.push_back(j); | |
259 | - | |
260 | - // rIdx = cR(rIdx), cIdx = cC(cIdx); | |
261 | - for (j = 0; j<rIdx.size(); j++){ | |
262 | - rIdx[j] = cR[rIdx[j]]; | |
263 | - cIdx[j] = cC[cIdx[j]]; | |
264 | - } | |
265 | - | |
266 | - int Step = 6; | |
267 | - while (!cIdx.empty()){ | |
268 | - uZr = rIdx[0]; | |
269 | - uZc = cIdx[0]; | |
270 | - primeZ[uZr] = uZc; | |
271 | - int stz = starZ[uZr]; | |
272 | - if (stz<0){ | |
273 | - Step = 5; | |
274 | - break; | |
275 | - } | |
276 | - noncoverRow[uZr] = false; | |
277 | - noncoverColumn[stz] = true; | |
278 | - // rIdx(rIdx==uZr) = [] | |
279 | - vector<int> rIdx2, cIdx2; | |
280 | - for (it3 = rIdx.begin(), it4 = cIdx.begin(); it3 != rIdx.end(); it3++, it4++) | |
281 | - if (*it3 != uZr){ | |
282 | - rIdx2.push_back(*it3); | |
283 | - cIdx2.push_back(*it4); | |
284 | - } | |
285 | - rIdx = rIdx2, cIdx = cIdx2; | |
286 | - // cR = find(~coverRow); | |
287 | - cR.clear(); | |
288 | - for (j = 0; j<noncoverRow.size(); j++) | |
289 | - if (noncoverRow[j]) | |
290 | - cR.push_back(j); | |
291 | - // z = dMat(~coverRow,stz) == minR(~coverRow) + minC(stz); | |
292 | - int sz = cR.size(); | |
293 | - minR_uncovered = tmp5.rowRange(0, sz); | |
294 | - extractDots(minR, noncoverRow, minR_uncovered); | |
295 | - minR_uncovered = minR_uncovered + cv::Scalar(minC.at<float>(stz)); | |
296 | - temp1 = tmp1(cv::Rect(0, 0, 1, sz)); | |
297 | - extractDots(dMat.col(stz), noncoverRow, temp1); | |
298 | - temp4 = tmp4(cv::Rect(0, 0, 1, sz)); | |
299 | - compare(temp1, minR_uncovered, temp4, cv::CMP_EQ); | |
300 | - // rIdx = [rIdx(:);cR(z)]; | |
301 | - for (i = 0, ptU = temp4.data; i<temp4.rows; i++, ptU += temp4.step) | |
302 | - if (*ptU){ | |
303 | - rIdx.push_back(cR[i]); | |
304 | - cIdx.push_back(stz); | |
305 | - } | |
306 | - } | |
307 | - | |
308 | - if (Step == 6){ | |
309 | - // STEP 6: Add the minimum uncovered value to every element of each covered | |
310 | - // row, and subtract it from every element of each uncovered column. | |
311 | - // Return to Step 4 without altering any stars, primes, or covered lines. | |
312 | - cnt1 = 0, cnt2 = 0; | |
313 | - it1 = noncoverColumn.begin(), it2 = noncoverRow.begin(); | |
314 | - i = 0; while (i++<n){ | |
315 | - if (*(it1++)) cnt1++; // number of non-covered columns | |
316 | - if (*(it2++)) cnt2++; // number of non-covered rows | |
317 | - } | |
318 | - temp1 = tmp1(cv::Rect(0, 0, cnt1, cnt2)); | |
319 | - minR_uncovered = tmp5.rowRange(0, cnt2); | |
320 | - minC_uncovered = tmp6.colRange(0, cnt1); | |
321 | - extractGrids(dMat, noncoverRow, noncoverColumn, temp1); | |
322 | - extractDots(minR, noncoverRow, minR_uncovered); | |
323 | - extractDots(minC, noncoverColumn, minC_uncovered); | |
324 | - | |
325 | - // minVal & rIdx & cIdx | |
326 | - temp2 = tmp2(cv::Rect(0, 0, cnt1, cnt2)); | |
327 | - temp3 = tmp3(cv::Rect(0, 0, cnt1, cnt2)); | |
328 | - repeat(minR_uncovered, 1, cnt1, temp2); | |
329 | - repeat(minC_uncovered, cnt2, 1, temp3); | |
330 | - temp3 = temp1 - temp2 - temp3; | |
331 | - double minVal; | |
332 | - cv::Point minLoc; | |
333 | - minMaxLoc(temp3, &minVal, 0, &minLoc); | |
334 | - rIdx.resize(1), cIdx.resize(1); | |
335 | - rIdx[0] = minLoc.y, cIdx[0] = minLoc.x; | |
336 | - | |
337 | - // minC(~coverColumn) = minC(~coverColumn) + minval; | |
338 | - ptF = (float*)minC.data, ptF2 = (float*)minR.data; | |
339 | - it1 = noncoverColumn.begin(), it2 = noncoverRow.begin(); | |
340 | - float minval = (float)minVal; | |
341 | - i = 0; while (i++<n) if (*(it1++)) *(ptF++) += minval; else ptF++; | |
342 | - // minR(coverRow) = minR(coverRow) - minval; | |
343 | - i = 0; while (i++<n) if (*(it2++)) ptF2++; else *(ptF2++) -= minval; | |
344 | - } | |
345 | - else | |
346 | - break; | |
347 | - } | |
348 | - | |
349 | - // STEP 5 | |
350 | - // Construct a series of alternating primed and starred zeros as follows: | |
351 | - // Let Z0 represent the uncovered primed zero found in Step 4. | |
352 | - // Let Z1 denote the starred zero in the column of Z0 (if any). | |
353 | - // Let Z2 denote the primed zero in the row of Z1 (there will always | |
354 | - // be one). Continue until the series terminates at a primed zero | |
355 | - // that has no starred zero in its column. Unstar each starred | |
356 | - // zero of the series, star each primed zero of the series, erase | |
357 | - // all primes and uncover every line in the matrix. Return to Step 3. | |
358 | - int rowZ1; | |
359 | - for (j = 0; j<starZ.size(); j++) | |
360 | - if (starZ[j] == uZc) | |
361 | - break; | |
362 | - if (j<starZ.size()) | |
363 | - rowZ1 = j; | |
364 | - else | |
365 | - rowZ1 = -1; | |
366 | - starZ[uZr] = uZc; | |
367 | - while (rowZ1 >= 0){ | |
368 | - starZ[rowZ1] = -1; | |
369 | - uZc = primeZ[rowZ1]; | |
370 | - uZr = rowZ1; | |
371 | - for (j = 0; j<starZ.size(); j++) | |
372 | - if (starZ[j] == uZc) | |
373 | - break; | |
374 | - if (j<starZ.size()) | |
375 | - rowZ1 = j; | |
376 | - else | |
377 | - rowZ1 = -1; | |
378 | - starZ[uZr] = uZc; | |
379 | - } | |
380 | - } | |
381 | - | |
382 | - // assignment | |
383 | - // rowIdx = find(validRow); colIdx = find(validCol); | |
384 | - vector<int> rowIdx(nRows), colIdx(nCols); | |
385 | - it1 = validRow.begin(), it2 = validCol.begin(); | |
386 | - for (i = 0, it3 = rowIdx.begin(); i<rows; i++) if (*(it1++)) *(it3++) = i; | |
387 | - for (i = 0, it3 = colIdx.begin(); i<cols; i++) if (*(it2++)) *(it3++) = i; | |
388 | - // vIdx = starZ(1:nRows) <= nCols; | |
389 | - vector<bool> vIdx(nRows, false); | |
390 | - it1 = vIdx.begin(), it3 = starZ.begin(); | |
391 | - i = 0; while (i++<nRows) if (*(it3++)<nCols) *(it1++) = true; else it1++; | |
392 | - // assignment(rowIdx(vIdx)) = colIdx(starZ(vIdx)); | |
393 | - for (j = 0, it1 = vIdx.begin(); j<vIdx.size(); j++){ | |
394 | - if (*(it1++)){ | |
395 | - r = rowIdx[j], c = starZ[j]; | |
396 | - assignment[r] = colIdx[c]; | |
397 | - } | |
398 | - } | |
399 | - for (j = 0; j<assignment.size(); j++){ | |
400 | - int job = assignment[j]; | |
401 | - if (job>-1){ | |
402 | - uchar isInvalid = validMat.at<uchar>(j, job); // validMat is now "invalidMat" | |
403 | - if (isInvalid) | |
404 | - assignment[j] = -1; | |
405 | - } | |
406 | - } | |
407 | -} | |
408 | 0 | \ No newline at end of file |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/HungarianAlgorithm.h deleted
1 | -#ifndef HUNGARIANALGORITHM_H_ | |
2 | -#define HUNGARIANALGORITHM_H_ | |
3 | - | |
4 | -#include <vector> | |
5 | -#ifdef _MSC_VER | |
6 | - #include <cv.h> | |
7 | -#else | |
8 | - #include <opencv2/core/core.hpp> | |
9 | - #include <opencv2/highgui/highgui.hpp> | |
10 | - #include <opencv2/imgproc/imgproc.hpp> | |
11 | -#endif | |
12 | - | |
13 | -#include <assert.h> | |
14 | -#include <iostream> | |
15 | - | |
16 | -using namespace std; | |
17 | - | |
18 | - | |
19 | - | |
20 | -void extractGrids(const cv::Mat &A, const vector<bool> &extractRows, const vector<bool> &extractCols, cv::Mat &B); | |
21 | -void extractDots(const cv::Mat &A, const vector<bool> &extract, cv::Mat &B); | |
22 | -void munkres(cv::Mat &IoUMat, vector<int> &assignment); | |
23 | - | |
24 | -#endif |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/KalmanBoxTracker.cpp deleted
1 | -#include "KalmanBoxTracker.h" | |
2 | - | |
3 | - | |
4 | -float IoU(vector<float> &bb_test, vector<float> &bb_gt) | |
5 | -{ | |
6 | - float xx1, yy1, xx2, yy2, w, h, wh, o; | |
7 | - xx1 = max(bb_test[0], bb_gt[0]); | |
8 | - yy1 = max(bb_test[1], bb_gt[1]); | |
9 | - xx2 = min(bb_test[2], bb_gt[2]); | |
10 | - yy2 = min(bb_test[3], bb_gt[3]); | |
11 | - w = max(float(0), (xx2 - xx1)); | |
12 | - h = max(float(0), (yy2 - yy1)); | |
13 | - wh = w * h; | |
14 | - o = wh / ((bb_test[2] - bb_test[0])*(bb_test[3] - bb_test[1]) | |
15 | - + (bb_gt[2] - bb_gt[0])*(bb_gt[3] - bb_gt[1]) - wh); | |
16 | - return o; | |
17 | -} | |
18 | - | |
19 | -void convert_bbox_to_z(vector<float> &bbox, vector<float> &z) | |
20 | -{ | |
21 | - float w, h, x, y, s, r; | |
22 | - w = bbox[2] - bbox[0]; | |
23 | - h = bbox[3] - bbox[1]; | |
24 | - x = bbox[0] + w / 2; | |
25 | - y = bbox[1] + h / 2; | |
26 | - s = w * h; //scale is just area | |
27 | - r = w / h; | |
28 | - z.push_back(x); | |
29 | - z.push_back(y); | |
30 | - z.push_back(s); | |
31 | - z.push_back(r); | |
32 | - | |
33 | -} | |
34 | - | |
35 | -void convert_x_to_bbox(cv::Mat &x, vector<float> &bbox) | |
36 | -{ | |
37 | - float w, h; | |
38 | - w = sqrt(x.at<float>(2) * x.at<float>(3)); | |
39 | - h = x.at<float>(2) / w; | |
40 | - //bbox[x1,y1,x2,y2]; | |
41 | - bbox.push_back(x.at<float>(0) - w / 2); | |
42 | - bbox.push_back(x.at<float>(1) - h / 2); | |
43 | - bbox.push_back(x.at<float>(0) + w / 2); | |
44 | - bbox.push_back(x.at<float>(1) + h / 2); | |
45 | -} | |
46 | - | |
47 | - | |
48 | - | |
49 | -KalmanBoxTracker::KalmanBoxTracker(vector<float> &bbox, int trackLength) | |
50 | -{ | |
51 | - KF.init(7, 4, 0); //初始化卡尔曼滤波器对象KF | |
52 | - state = cv::Mat::zeros(7, 1, CV_32F); | |
53 | - processNoise = cv::Mat::zeros(7, 1, CV_32F); | |
54 | - measurement = cv::Mat::zeros(4, 1, CV_32F); //定义测量值 | |
55 | - | |
56 | - KF.transitionMatrix = (cv::Mat_<float>(7, 7) << \ | |
57 | - 1, 0, 0, 0, 1, 0, 0, \ | |
58 | - 0, 1, 0, 0, 0, 1, 0, \ | |
59 | - 0, 0, 1, 0, 0, 0, 1, \ | |
60 | - 0, 0, 0, 1, 0, 0, 0, \ | |
61 | - 0, 0, 0, 0, 1, 0, 0, \ | |
62 | - 0, 0, 0, 0, 0, 1, 0, \ | |
63 | - 0, 0, 0, 0, 0, 0, 1); //状态转移矩阵A | |
64 | - | |
65 | - KF.measurementMatrix = (cv::Mat_<float>(4, 7) << \ | |
66 | - 1, 0, 0, 0, 0, 0, 0, \ | |
67 | - 0, 1, 0, 0, 0, 0, 0, \ | |
68 | - 0, 0, 1, 0, 0, 0, 0, \ | |
69 | - 0, 0, 0, 1, 0, 0, 0); //测量矩阵H | |
70 | - | |
71 | - KF.measurementNoiseCov = (cv::Mat_<float>(4, 4) << \ | |
72 | - 1, 0, 0, 0, \ | |
73 | - 0, 1, 0, 0, \ | |
74 | - 0, 0, 10, 0, \ | |
75 | - 0, 0, 0, 10); //测量噪声方差矩阵R | |
76 | - | |
77 | - KF.errorCovPost = (cv::Mat_<float>(7, 7) << \ | |
78 | - 10, 0, 0, 0, 0, 0, 0, \ | |
79 | - 0, 10, 0, 0, 0, 0, 0, \ | |
80 | - 0, 0, 10, 0, 0, 0, 0, \ | |
81 | - 0, 0, 0, 10, 0, 0, 0, \ | |
82 | - 0, 0, 0, 0, 10000, 0, 0, \ | |
83 | - 0, 0, 0, 0, 0, 10000, 0, \ | |
84 | - 0, 0, 0, 0, 0, 0, 10000); //后验错误估计协方差矩阵P | |
85 | - | |
86 | - KF.processNoiseCov = (cv::Mat_<float>(7, 7) << \ | |
87 | - 1, 0, 0, 0, 0, 0, 0, \ | |
88 | - 0, 1, 0, 0, 0, 0, 0, \ | |
89 | - 0, 0, 1, 0, 0, 0, 0, \ | |
90 | - 0, 0, 0, 1, 0, 0, 0, \ | |
91 | - 0, 0, 0, 0, 0.01, 0, 0, \ | |
92 | - 0, 0, 0, 0, 0, 0.01, 0, \ | |
93 | - 0, 0, 0, 0, 0, 0, 0.0001); //系统噪声方差矩阵Q | |
94 | - | |
95 | - vector<float> z; | |
96 | - convert_bbox_to_z(bbox, z); | |
97 | - KF.statePost = (cv::Mat_<float>(7, 1) << z[0], z[1], z[2], z[3], 0, 0, 0); //corrected state | |
98 | - state = (cv::Mat_<float>(7, 1) << z[0], z[1], z[2], z[3], 0, 0, 0); | |
99 | - time_since_update = 0; | |
100 | - cls = bbox[5]; | |
101 | - //history | |
102 | - //hits = 0; | |
103 | - hit_streak = 0; | |
104 | - age = 0; | |
105 | - | |
106 | - m_trackLength = trackLength; | |
107 | - //history = new cycleQueue<vector<float>>(trackLength); | |
108 | - history.set_param(trackLength); | |
109 | -} | |
110 | - | |
111 | -KalmanBoxTracker::~KalmanBoxTracker() | |
112 | -{ | |
113 | - | |
114 | - /*int trackerSize = history.size(); | |
115 | - | |
116 | - for (int i = 0; i < trackerSize; i++) | |
117 | - { | |
118 | - history.get(i).clear(); | |
119 | - vector<float>().swap(history.get(i)); | |
120 | - | |
121 | - }*/ | |
122 | - | |
123 | - /*if (history != NULL) | |
124 | - { | |
125 | - delete history; | |
126 | - history = NULL; | |
127 | - }*/ | |
128 | -} | |
129 | - | |
130 | -void KalmanBoxTracker::update(vector<float> &bbox) | |
131 | -{ | |
132 | - time_since_update = 0; | |
133 | - //history | |
134 | - //hits += 1; | |
135 | - hit_streak += 1; | |
136 | - vector<float> z; | |
137 | - convert_bbox_to_z(bbox, z); | |
138 | - measurement = (cv::Mat_<float>(4, 1) << z[0], z[1], z[2], z[3]); | |
139 | - KF.correct(measurement); | |
140 | -} | |
141 | - | |
142 | -vector<float> KalmanBoxTracker::predict(bool isUseDet) | |
143 | -{ | |
144 | - if ((KF.statePost.at<float>(6) + KF.statePost.at<float>(2)) <= 0) | |
145 | - KF.statePost.at<float>(6) *= 0.0; | |
146 | - | |
147 | - KF.predict(); | |
148 | - | |
149 | - age += 1; | |
150 | - //cout << "33333FusionInterval:" << FusionInterval << endl; | |
151 | - if (time_since_update >= FusionInterval) | |
152 | - hit_streak = 0; | |
153 | - if (isUseDet) | |
154 | - time_since_update += 1; | |
155 | - vector<float> bbox; | |
156 | - convert_x_to_bbox(KF.statePost, bbox); | |
157 | - //history.push_back(bbox); | |
158 | - | |
159 | - TRACK_POINT tmp_point; | |
160 | - tmp_point.x = bbox[0] + (bbox[2] - bbox[0]) / 2; | |
161 | - tmp_point.y = bbox[1] + (bbox[3] - bbox[1]) / 2; | |
162 | - history.push(tmp_point); | |
163 | - | |
164 | - return bbox; | |
165 | -} | |
166 | - | |
167 | -vector<float> KalmanBoxTracker::get_state() | |
168 | -{ | |
169 | - vector<float> bbox; | |
170 | - convert_x_to_bbox(KF.statePost, bbox); | |
171 | - return bbox; | |
172 | -} | |
173 | - |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/KalmanBoxTracker.h deleted
1 | -#ifndef KALMANBOXTRACKER_H_ | |
2 | -#define KALMANBOXTRACKER_H_ | |
3 | - | |
4 | -#include <opencv2/video/tracking.hpp> | |
5 | -#include <highgui.hpp> | |
6 | -#include <iostream> | |
7 | -#include <stdio.h> | |
8 | -#include <math.h> | |
9 | -#include <vector> | |
10 | -#include "CycleQueue.h" | |
11 | - | |
12 | -using namespace std; | |
13 | - | |
14 | -//#define FusionInterval 5 //控制算法跳帧 | |
15 | -class KalmanBoxTracker | |
16 | -{ | |
17 | -public: | |
18 | - //int count = 0; | |
19 | - int time_since_update = 0; | |
20 | - int FusionInterval = 5; // 221007 | |
21 | - int id = 0; | |
22 | - int cls = 0; | |
23 | - float score = 0.00; | |
24 | - //vector< vector<float> > history; | |
25 | - | |
26 | - cycleQueue history; //固定大小的轨迹 | |
27 | - | |
28 | - //int hits; | |
29 | - int hit_streak = 0; | |
30 | - int age = 0; | |
31 | - int m_trackLength = 0; | |
32 | - | |
33 | -public: | |
34 | - KalmanBoxTracker(vector<float> &bbox, int trackLength); | |
35 | - ~KalmanBoxTracker(); | |
36 | - void update(vector<float> &bbox); | |
37 | - vector<float> predict(bool isUseDet); | |
38 | - vector<float> get_state(); | |
39 | -private: | |
40 | - cv::KalmanFilter KF; //创建卡尔曼滤波器对象KF | |
41 | - cv::Mat measurement; | |
42 | - cv::Mat state;// (7, 1, CV_32F); //state = x | |
43 | - cv::Mat processNoise; | |
44 | -}; | |
45 | - | |
46 | -float IoU(vector<float> &bb_test, vector<float> &bb_gt); | |
47 | -void convert_bbox_to_z(vector<float> &bbox, vector<float> &z); | |
48 | -void convert_x_to_bbox(cv::Mat &x, vector<float> &bbox); | |
49 | - | |
50 | - | |
51 | -#endif | |
52 | 0 | \ No newline at end of file |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/Sort.cpp deleted
1 | -#include "Sort.h" | |
2 | -#include <opencv2/opencv.hpp> | |
3 | -#include "../../DxDecoder/ImageSaveGPU.h" | |
4 | - | |
5 | -#ifdef _MSC_VER | |
6 | -#include <io.h> | |
7 | -#include <direct.h> | |
8 | -#define _ACCESS _access | |
9 | -#define _MKDIR(a) _mkdir((a)) | |
10 | -#else | |
11 | -#include <unistd.h> | |
12 | -#include <stdarg.h> | |
13 | -#include <sys/stat.h> | |
14 | -#define _ACCESS access | |
15 | -#define _MKDIR(a) mkdir((a),0755) | |
16 | -#endif | |
17 | -#include <time.h> | |
18 | - | |
19 | -const int color[11][3] = { { 255, 0, 0 }, { 255, 128, 255 }, { 255, 128, 0 }, { 255, 215, 0 }, { 154, 205, 50 }, { 0, 128, 0 }, \ | |
20 | - {0, 128, 255}, { 186, 85, 211 }, { 91, 46, 0 }, { 0, 0, 0 }, { 255, 255, 255 } }; | |
21 | - | |
22 | - | |
23 | -Sort::Sort() | |
24 | -{ | |
25 | - // max_age = 10; | |
26 | - max_lost_times = 1; | |
27 | - min_hits = 1; | |
28 | - input_det_count = 0; | |
29 | - WORK = true; | |
30 | - //-----------------by zl---------------------// | |
31 | - istraffic = false; //by zl 不统计交通量 | |
32 | - trackcount = 0; | |
33 | - //-----------------by zl---------------------// | |
34 | - | |
35 | - max_track_length = MAX_LENGTH; | |
36 | - trackers.clear(); | |
37 | -} | |
38 | - | |
39 | - | |
40 | -int Sort::update(int width, int height, bool isUseDet, vector< vector<float> > &dets, VPT_ObjInfo *result, vector<int> &deleteObjectID) | |
41 | -{ | |
42 | - //get predicted locations from existing trackers. | |
43 | - vector< vector<float> > trks; | |
44 | - vector<float> pos; | |
45 | - int ObjCount = 0; //by zl 本帧图像中的有效前景个数 | |
46 | - vector<float> bbox; | |
47 | - | |
48 | - //cout << "trackers size: " << trackers.size() << endl; | |
49 | - for (int i = 0; i < trackers.size(); i++ ) | |
50 | - { | |
51 | - pos = trackers[i].predict(isUseDet); | |
52 | - pos.push_back(1); | |
53 | - pos.push_back(trackers[i].cls); | |
54 | - trks.push_back(pos); | |
55 | - pos.clear(); | |
56 | - } | |
57 | - | |
58 | - if (isUseDet == true) | |
59 | - { | |
60 | - vector< vector<int> > matched; | |
61 | - vector<int> unmatched_dets; | |
62 | - vector<int> unmatched_trks; | |
63 | - | |
64 | - Sort::associate_detections_to_trackers(matched, unmatched_dets, unmatched_trks, dets, trks, 0.3); | |
65 | - | |
66 | - //update matched trackers with assigned detections | |
67 | - for (int matched_number = 0; matched_number < matched.size(); matched_number++) | |
68 | - { | |
69 | - trackers[matched[matched_number][1]].update(dets[matched[matched_number][0]]); | |
70 | - trackers[matched[matched_number][1]].score = dets[matched[matched_number][0]][4]; | |
71 | - trackers[matched[matched_number][1]].cls = dets[matched[matched_number][0]][5]; | |
72 | - } | |
73 | - | |
74 | - //create and initialise new trackers for unmatched detections | |
75 | - for (int unmatched_dets_number = 0; unmatched_dets_number < unmatched_dets.size(); unmatched_dets_number++) | |
76 | - { | |
77 | - KalmanBoxTracker tracker = KalmanBoxTracker(dets[unmatched_dets[unmatched_dets_number]], max_track_length); | |
78 | - tracker.id = -1; | |
79 | - // tracker.FusionInterval = FusionInterval; //221007 | |
80 | - trackers.push_back(tracker); | |
81 | - trackers[trackers.size() - 1].score = dets[unmatched_dets[unmatched_dets_number]][4];//by zl 20170525 解决第一次检测时置信度为0问题 | |
82 | - // cout << "trackers size: " << trackers.size() << endl; | |
83 | - } | |
84 | - | |
85 | - for (int trackers_number = 0; trackers_number < trackers.size();) | |
86 | - { | |
87 | - //cout << trackers[trackers_number].id << " " <<trackers[trackers_number].time_since_update << " " << trackers[trackers_number].hit_streak << " " << min_hits << " " << frame_count << endl; | |
88 | - // if (trackers[trackers_number].time_since_update > max_age) | |
89 | - if (trackers[trackers_number].time_since_update > max_lost_times) | |
90 | - { | |
91 | - if (trackers[trackers_number].id != -1) | |
92 | - { | |
93 | - deleteObjectID.push_back(trackers[trackers_number].id); | |
94 | - } | |
95 | - trackcount++; | |
96 | - trackers.erase(trackers.begin() + trackers_number); | |
97 | - continue; | |
98 | - } | |
99 | - //cout << "22222FusionInterval:" << trackers[trackers_number].FusionInterval << endl; | |
100 | - 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))) | |
101 | - // 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 | |
102 | - { | |
103 | - | |
104 | - if (trackers[trackers_number].id == -1) | |
105 | - trackers[trackers_number].id = trackcount++; | |
106 | - result[ObjCount].id = trackers[trackers_number].id; | |
107 | - bbox = trackers[trackers_number].get_state(); | |
108 | - result[ObjCount].left = bbox[0]; // bbout[i][0]; | |
109 | - result[ObjCount].top = bbox[1]; //bbout[i][1]; | |
110 | - result[ObjCount].right = bbox[2]; //bbout[i][2]; | |
111 | - result[ObjCount].bottom = bbox[3]; //bbout[i][3]; | |
112 | - result[ObjCount].confidence = trackers[trackers_number].score; // bbout[i][4]; | |
113 | - // result[ObjCount].index = trackers[trackers_number].cls - 1; //针对FPN检测模型 id底层给出的值大了1 所以此处-1 | |
114 | - result[ObjCount].index = trackers[trackers_number].cls; // 针对检测模型 底层库给出正确的index值 此处无须特殊处理 | |
115 | - RectboundCheck(width, height, &result[ObjCount]); | |
116 | - result[ObjCount].center_x = result[ObjCount].left + (result[ObjCount].right - result[ObjCount].left) * 0.5; // 中心点 add by 20170227 | |
117 | - result[ObjCount].center_y = result[ObjCount].top + (result[ObjCount].bottom - result[ObjCount].top) * 0.5; // 中心点 | |
118 | - //if(trackers[trackers_number].age==2*FusionInterval) | |
119 | - if (trackers[trackers_number].age == 2 * trackers[trackers_number].FusionInterval) //221007 | |
120 | - { | |
121 | - result[ObjCount].snap_flag = 1; // 中心点 | |
122 | - } | |
123 | - else | |
124 | - { | |
125 | - result[ObjCount].snap_flag = 0; // 中心点 | |
126 | - } | |
127 | - | |
128 | -#if _Debug | |
129 | - 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); | |
130 | -#endif | |
131 | - ObjCount++; | |
132 | - } | |
133 | - trackers_number++;//共多少条轨迹 | |
134 | - | |
135 | - } | |
136 | - | |
137 | - input_det_count += 1; //帧数加一 | |
138 | - } | |
139 | - else | |
140 | - { | |
141 | - for (int trackers_number = 0; trackers_number < trackers.size() && ObjCount < MAX_OBJ_COUNT; trackers_number++) | |
142 | - { | |
143 | - // printf("trackers_number: %d\n", trackers_number); | |
144 | - //cout << "44444FusionInterval:" << trackers[trackers_number].FusionInterval << endl; | |
145 | - if (trackers[trackers_number].id == -1) | |
146 | - trackers[trackers_number].id = trackcount++; | |
147 | - bbox = trackers[trackers_number].get_state(); | |
148 | - result[trackers_number].id = trackers[trackers_number].id; | |
149 | - result[trackers_number].left = bbox[0]; // bbout[i][0]; | |
150 | - result[trackers_number].top = bbox[1]; //bbout[i][1]; | |
151 | - result[trackers_number].right = bbox[2]; //bbout[i][2]; | |
152 | - result[trackers_number].bottom = bbox[3]; //bbout[i][3]; | |
153 | - result[trackers_number].confidence = trackers[trackers_number].score; // bbout[i][4]; | |
154 | - // result[trackers_number].index = trackers[trackers_number].cls - 1;//bbox[5] - 1;// trackers[trackers_number].cls - 1; // bbout[i][5] - 1; | |
155 | - result[trackers_number].index = trackers[trackers_number].cls;//bbox[5] - 1;// trackers[trackers_number].cls - 1; // bbout[i][5] - 1; | |
156 | - RectboundCheck(width, height, &result[trackers_number]); | |
157 | - result[trackers_number].center_x = (int)(result[trackers_number].left + (result[trackers_number].right - result[trackers_number].left) * 0.5); // 中心点 add by 20170227 | |
158 | - result[trackers_number].center_y = (int)(result[trackers_number].top + (result[trackers_number].bottom - result[trackers_number].top) * 0.5); // 中心点 | |
159 | - | |
160 | - result[ObjCount].snap_flag = 0; // 中心点 | |
161 | - | |
162 | - ObjCount++; | |
163 | - } | |
164 | - } | |
165 | - | |
166 | - //---------------------------注释掉了这步操作 用了新的绘制轨迹的函数 需要绘制调用addTracker(Mat *img)方法 by lm---------------------------------------------/ | |
167 | - //addTracker(result, ObjCount); | |
168 | - | |
169 | - | |
170 | - return ObjCount; | |
171 | - | |
172 | -} | |
173 | - | |
174 | -// | |
175 | -////---------------------------by zl ---------------------------------------------/ | |
176 | -//int Sort::addTracker(VPT_ObjInfo *result, int resultcount) | |
177 | -//{ | |
178 | -// for (int i = 0; i < resultcount; i++) | |
179 | -// { | |
180 | -// bool flag = false; | |
181 | -// for (int j = 0; j < tracker.size(); j++) | |
182 | -// { | |
183 | -// if (result[i].id == tracker[j].id) //若有匹配的 则更新 | |
184 | -// { | |
185 | -// tracker[j].listinfo.push_back(result[i]); | |
186 | -// tracker[j].lost = 0; | |
187 | -// tracker[j].isupdate = true; | |
188 | -// tracker[j].num++; //每个ID的计数 | |
189 | -// result[i].num = tracker[j].num; | |
190 | -// | |
191 | -// if (tracker[j].istraffic == false && istraffic) | |
192 | -// { | |
193 | -// int listmax = tracker[j].listinfo.size() - 1; | |
194 | -// } | |
195 | -// flag = true; | |
196 | -// break; | |
197 | -// } | |
198 | -// } | |
199 | -// if (!flag) //没有找到匹配项 新添加 | |
200 | -// { | |
201 | -// mylist m_list; | |
202 | -// m_list.listinfo.push_back(result[i]); | |
203 | -// m_list.isupdate = true; | |
204 | -// m_list.lost = 0; | |
205 | -// m_list.id = result[i].id; | |
206 | -// m_list.index = result[i].index;; | |
207 | -// m_list.istraffic = false; | |
208 | -// m_list.num = 0; //20170306 | |
209 | -// result[i].num = 0; | |
210 | -// m_list.startframe = frame_count; | |
211 | -//#if _Debug | |
212 | -// 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); | |
213 | -//#endif | |
214 | -// tracker.push_back(m_list); | |
215 | -// } | |
216 | -// } | |
217 | -// //绘制轨迹部分 | |
218 | -// | |
219 | -// for (vector <mylist>::iterator iter = tracker.begin(); iter != tracker.end();) | |
220 | -// { | |
221 | -// if (iter->isupdate == false) //未更新的不绘制轨迹 | |
222 | -// { | |
223 | -// iter->lost++; | |
224 | -// if (iter->lost > LOSTMAXFRAMECCOUNT) //若丢失太多 则删除该轨迹 | |
225 | -// { | |
226 | -// iter->endframe = frame_count; //结束帧 | |
227 | -// iter = tracker.erase(iter);//删除 | |
228 | -// continue; | |
229 | -// } | |
230 | -// } | |
231 | -// else //只对更新后的绘制轨迹 | |
232 | -// { | |
233 | -// ; | |
234 | -// } | |
235 | -// iter->isupdate = false; | |
236 | -// iter++; | |
237 | -// } | |
238 | -// | |
239 | -// return 1; | |
240 | -//} | |
241 | - | |
242 | - | |
243 | -//---------------------------利用trackers中的history 绘制路径 -by lm ---------------------------------------------/ | |
244 | -//固定长度的轨迹,采用循环队列,仅保存目前最前N length的轨迹,避免对于停留在画面中目标 导致的内存一直增长 | |
245 | -int Sort::addTracker(cv::Mat *img) | |
246 | -{ | |
247 | - map<int, pair<int, int>> tracker; | |
248 | - vector<float> bbox; | |
249 | - | |
250 | - | |
251 | - int x_1, y_1, x_2, y_2; | |
252 | - for (auto iter : trackers) | |
253 | - { | |
254 | - //if (iter.time_since_update < FusionInterval) | |
255 | - //cout << "55555FusionInterval:" << iter.FusionInterval << endl; | |
256 | - if (iter.time_since_update < iter.FusionInterval) //221007 | |
257 | - { | |
258 | - int index = iter.history.getFront(); | |
259 | - int trackerSize = iter.history.size(); | |
260 | - | |
261 | - for (int i = 0; i < trackerSize; i++) | |
262 | - { | |
263 | - if (i == 0) | |
264 | - { | |
265 | - x_1 = iter.history.get(index).x; | |
266 | - y_1 = iter.history.get(index).y; | |
267 | - } | |
268 | - else | |
269 | - { | |
270 | - x_2 = iter.history.get(index).x; | |
271 | - y_2 = iter.history.get(index).y; | |
272 | - int colorIndex = iter.id % 11; | |
273 | - 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); | |
274 | - | |
275 | - //drawLineOnGPU() | |
276 | - | |
277 | - x_1 = x_2; | |
278 | - y_1 = y_2; | |
279 | - } | |
280 | - | |
281 | - //if (i == 0) | |
282 | - //{ | |
283 | - // x_1 = iter.history.get(index)[0] + (iter.history.get(index)[2] - iter.history.get(index)[0]) / 2; | |
284 | - // y_1 = iter.history.get(index)[1] + (iter.history.get(index)[3] - iter.history.get(index)[1]) / 2; | |
285 | - //} | |
286 | - //else | |
287 | - //{ | |
288 | - // x_2 = iter.history.get(index)[0] + (iter.history.get(index)[2] - iter.history.get(index)[0]) / 2; | |
289 | - // y_2 = iter.history.get(index)[1] + (iter.history.get(index)[3] - iter.history.get(index)[1]) / 2; | |
290 | - // int colorIndex = iter.id % 11; | |
291 | - // cv::line(*img, cvPoint(x_1, y_1), cvPoint(x_2, y_2), cvScalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 1); | |
292 | - | |
293 | - // //drawLineOnGPU() | |
294 | - | |
295 | - // x_1 = x_2; | |
296 | - // y_1 = y_2; | |
297 | - //} | |
298 | - | |
299 | - index = (index + 1) % trackerSize; | |
300 | - } | |
301 | - | |
302 | - //int index = iter.history->getFront(); | |
303 | - //int trackerSize = iter.history->size(); | |
304 | - | |
305 | - //for (int i = 0; i < trackerSize; i++) | |
306 | - //{ | |
307 | - // if (i == 0) | |
308 | - // { | |
309 | - // x_1 = iter.history->get(index)[0] + (iter.history->get(index)[2] - iter.history->get(index)[0]) / 2; | |
310 | - // y_1 = iter.history->get(index)[1] + (iter.history->get(index)[3] - iter.history->get(index)[1]) / 2; | |
311 | - // } | |
312 | - // else | |
313 | - // { | |
314 | - // x_2 = iter.history->get(index)[0] + (iter.history->get(index)[2] - iter.history->get(index)[0]) / 2; | |
315 | - // y_2 = iter.history->get(index)[1] + (iter.history->get(index)[3] - iter.history->get(index)[1]) / 2; | |
316 | - // int colorIndex = iter.id % 11; | |
317 | - // cv::line(*img, cvPoint(x_1, y_1), cvPoint(x_2, y_2), cvScalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 1); | |
318 | - | |
319 | - // //drawLineOnGPU() | |
320 | - | |
321 | - // x_1 = x_2; | |
322 | - // y_1 = y_2; | |
323 | - // } | |
324 | - | |
325 | - // index = (index + 1) % trackerSize; | |
326 | - //} | |
327 | - } | |
328 | - | |
329 | - } | |
330 | - | |
331 | - return 1; | |
332 | -} | |
333 | - | |
334 | -//不固定长度的轨迹版本 采用vector,轨迹一直保留,对于停留在画面中的物体,会有内存一直增长的隐患 | |
335 | -//int Sort::addTracker(cv::Mat *img) | |
336 | -//{ | |
337 | -// map<int, pair<int, int>> tracker; | |
338 | -// vector<float> bbox; | |
339 | -// | |
340 | -// | |
341 | -// int x_1, y_1, x_2, y_2; | |
342 | -// for (auto iter : trackers) | |
343 | -// { | |
344 | -// if (iter.time_since_update < FusionInterval) | |
345 | -// { | |
346 | -// for (int i = 0; i < iter.history.size(); i++) | |
347 | -// { | |
348 | -// | |
349 | -// if (i == 0) | |
350 | -// { | |
351 | -// x_1 = iter.history[i][0] + (iter.history[i][2] - iter.history[i][0]) / 2; | |
352 | -// y_1 = iter.history[i][1] + (iter.history[i][3] - iter.history[i][1]) / 2; | |
353 | -// } | |
354 | -// else | |
355 | -// { | |
356 | -// x_2 = iter.history[i][0] + (iter.history[i][2] - iter.history[i][0]) / 2; | |
357 | -// y_2 = iter.history[i][1] + (iter.history[i][3] - iter.history[i][1]) / 2; | |
358 | -// int colorIndex = iter.id % 11; | |
359 | -// cv::line(*img, cvPoint(x_1, y_1), cvPoint(x_2, y_2), cvScalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 1); | |
360 | -// | |
361 | -// //drawLineOnGPU() | |
362 | -// | |
363 | -// x_1 = x_2; | |
364 | -// y_1 = y_2; | |
365 | -// } | |
366 | -// } | |
367 | -// } | |
368 | -// | |
369 | -// } | |
370 | -// | |
371 | -// return 1; | |
372 | -//} | |
373 | - | |
374 | -void Sort::Release() | |
375 | -{ | |
376 | - //tracker.clear(); | |
377 | - //vector <mylist>().swap(tracker); | |
378 | - trackers.clear(); | |
379 | - vector<KalmanBoxTracker>().swap(trackers); | |
380 | -} | |
381 | -bool Sort::GetState() | |
382 | -{ | |
383 | - return WORK; | |
384 | -} | |
385 | - | |
386 | -void Sort::Pause() | |
387 | -{ | |
388 | - WORK = false; | |
389 | -} | |
390 | - | |
391 | -void Sort::ReSet() | |
392 | -{ | |
393 | - WORK = true; | |
394 | - //Release(); | |
395 | - //max_age = 1; | |
396 | - //min_hits = 3; | |
397 | - //frame_count = 0; | |
398 | - | |
399 | - ////-----------------by zl---------------------// | |
400 | - //istraffic = false; //by zl 不统计交通量 | |
401 | - //trackcount = 0; | |
402 | - ////-----------------by zl---------------------// | |
403 | -} | |
404 | - | |
405 | -//---------------------------by zl ---------------------------------------------/ | |
406 | -bool line_rect_intersection(cv::Point start_p, cv::Point end_p, int left, int top, int right, int bottom) | |
407 | -{ | |
408 | - int a = start_p.y - end_p.y; | |
409 | - int b = end_p.x - start_p.x; | |
410 | - int c = start_p.x* end_p.y - end_p.x* start_p.y; | |
411 | - | |
412 | - ////思路:先看线段所在直线是否与矩形相交,如果不相交则必为 “F”, | |
413 | - ////如果相交,则看线段的两个点是否在矩形的同一边(即两点的 x(y) 坐标都比矩形的小 x(y) 坐标小,或者大), | |
414 | - ////若在同一边则为“F”,否则就是相交的情况。 | |
415 | - if ((a* left + b*top + c >= 0 && a* right + b* bottom + c <= 0) || | |
416 | - (a* left + b*top + c <= 0 && a* right + b* bottom + c >= 0) || | |
417 | - (a* left + b*bottom + c >= 0 && a* right + b* top + c <= 0) || | |
418 | - (a* left + b*bottom + c >= 0 && a* right + b* top + c <= 0)) | |
419 | - { | |
420 | - if (left > right) | |
421 | - { | |
422 | - swap(left, right); | |
423 | - } | |
424 | - if (top < bottom) | |
425 | - { | |
426 | - swap(top, bottom); | |
427 | - } | |
428 | - if ((start_p.x < left && end_p.x < left) || | |
429 | - (start_p.x > right && end_p.x < left) || | |
430 | - (start_p.y > top && end_p.y > top) || | |
431 | - (start_p.y < bottom && end_p.y < bottom)) ///判断线段是否在矩形一侧 | |
432 | - { | |
433 | - return false; | |
434 | - } | |
435 | - else | |
436 | - { | |
437 | - return true; | |
438 | - } | |
439 | - } | |
440 | - else | |
441 | - { | |
442 | - return false; | |
443 | - } | |
444 | -} | |
445 | -void RectboundCheck(int Width, int Height, VPT_ObjInfo * result) //防止坐标越界 by zl | |
446 | -{ | |
447 | - if (result->left < 0) | |
448 | - result->left = 0; | |
449 | - if (result->left >= Width) | |
450 | - result->left = Width; | |
451 | - | |
452 | - if (result->top < 0) | |
453 | - result->top = 0; | |
454 | - if (result->top >= Height) | |
455 | - result->top = Height; | |
456 | - | |
457 | - if (result->right <= result->left) | |
458 | - result->right = result->left + 1; | |
459 | - if (result->right >= Width) | |
460 | - result->right = Width; | |
461 | - | |
462 | - if (result->bottom < result->top) | |
463 | - result->bottom = result->top + 1; | |
464 | - if (result->bottom >= Height) | |
465 | - result->bottom = Height; | |
466 | - | |
467 | - | |
468 | -} | |
469 | -//------------------------------------其他函数----------------------------------------// | |
470 | -void Sort::associate_detections_to_trackers(vector< vector<int> > &matched, vector<int> &unmatched_dets, vector<int> &unmatched_trks, vector< vector<float> > &dets, vector< vector<float> > &trks, float iou_threshold) | |
471 | -{ | |
472 | - | |
473 | - if (0 == trks.size()) | |
474 | - { | |
475 | - for (int x = 0; x < dets.size(); x++) | |
476 | - { | |
477 | - unmatched_dets.push_back(x); | |
478 | - } | |
479 | - } | |
480 | - else if (0 == dets.size()) | |
481 | - { | |
482 | - for (int x = 0; x < trks.size(); x++) | |
483 | - { | |
484 | - unmatched_trks.push_back(x); | |
485 | - } | |
486 | - } | |
487 | - else | |
488 | - { | |
489 | - cv::Mat IoUMat(dets.size(), trks.size(), CV_32FC1); | |
490 | - for (int i = 0; i < dets.size(); i++) | |
491 | - for (int j = 0; j < trks.size(); j++) | |
492 | - { | |
493 | - //cls区分 | |
494 | - if (1) | |
495 | - //if (dets[i][5] == trks[j][5]) | |
496 | - { | |
497 | - IoUMat.at<float>(i, j) = IoU(dets[i], trks[j]); | |
498 | - } | |
499 | - else | |
500 | - { | |
501 | - IoUMat.at<float>(i, j) = 0; | |
502 | - } | |
503 | - | |
504 | - } | |
505 | - | |
506 | - //匈牙利算法 | |
507 | - vector<int> assignment; | |
508 | - munkres(IoUMat, assignment); | |
509 | - | |
510 | - vector<int>::iterator iter; | |
511 | - for (int trackers_indices = 0; trackers_indices < trks.size(); trackers_indices++) | |
512 | - { | |
513 | - iter = find(assignment.begin(), assignment.end(), trackers_indices); | |
514 | - if (iter == assignment.end()) | |
515 | - { | |
516 | - //assignment中不存在trackers_indices值 | |
517 | - unmatched_trks.push_back(trackers_indices); | |
518 | - } | |
519 | - } | |
520 | - | |
521 | - vector<int> matched_row_col; | |
522 | - for (int detections_indices = 0; detections_indices < assignment.size(); detections_indices++) | |
523 | - { | |
524 | - if (assignment[detections_indices] == -1) | |
525 | - { | |
526 | - unmatched_dets.push_back(detections_indices); | |
527 | - } | |
528 | - else if (IoUMat.at<float>(detections_indices, assignment[detections_indices]) > iou_threshold) | |
529 | - { | |
530 | - matched_row_col.push_back(detections_indices); | |
531 | - matched_row_col.push_back(assignment[detections_indices]); | |
532 | - matched.push_back(matched_row_col); | |
533 | - matched_row_col.clear(); | |
534 | - } | |
535 | - else | |
536 | - { | |
537 | - unmatched_dets.push_back(detections_indices); | |
538 | - unmatched_trks.push_back(assignment[detections_indices]); | |
539 | - } | |
540 | - } | |
541 | - } | |
542 | -} | |
543 | -//判断两条线是否相交 | |
544 | - | |
545 | -///------------alg 2------------ | |
546 | -//叉积 | |
547 | -double mult(cv::Point a, cv::Point b, cv::Point c) | |
548 | -{ | |
549 | - return (a.x - c.x)*(b.y - c.y) - (b.x - c.x)*(a.y - c.y); | |
550 | -} | |
551 | - | |
552 | -//aa, bb为一条线段两端点 cc, dd为另一条线段的两端点 相交返回true, 不相交返回false | |
553 | -bool intersect(cv::Point aa, cv::Point bb, cv::Point cc, cv::Point dd) | |
554 | -{ | |
555 | - if (max(aa.x, bb.x)<min(cc.x, dd.x)) | |
556 | - { | |
557 | - return false; | |
558 | - } | |
559 | - if (max(aa.y, bb.y)<min(cc.y, dd.y)) | |
560 | - { | |
561 | - return false; | |
562 | - } | |
563 | - if (max(cc.x, dd.x)<min(aa.x, bb.x)) | |
564 | - { | |
565 | - return false; | |
566 | - } | |
567 | - if (max(cc.y, dd.y)<min(aa.y, bb.y)) | |
568 | - { | |
569 | - return false; | |
570 | - } | |
571 | - if (mult(cc, bb, aa)*mult(bb, dd, aa)<0) | |
572 | - { | |
573 | - return false; | |
574 | - } | |
575 | - if (mult(aa, dd, cc)*mult(dd, bb, cc)<0) | |
576 | - { | |
577 | - return false; | |
578 | - } | |
579 | - return true; | |
580 | -} | |
581 | -///------------alg 2------------ |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort1/Sort.h deleted
1 | -#ifndef SORT_H_ | |
2 | -#define SORT_H_ | |
3 | - | |
4 | -#include "KalmanBoxTracker.h" | |
5 | -#include "HungarianAlgorithm.h" | |
6 | -#include <opencv2/video/tracking.hpp> | |
7 | -#include <highgui.hpp> | |
8 | -#include <iostream> | |
9 | -#include <stdio.h> | |
10 | -#include <math.h> | |
11 | -#include<vector> | |
12 | -#include "../VPTProcess.h" | |
13 | - | |
14 | - | |
15 | -using namespace std; | |
16 | - | |
17 | - | |
18 | -#define LOSTMAXFRAMECCOUNT 5 //by zl | |
19 | -#define SNAPSHOTFRAMECOUNT 24 //下标从0开始 取第十帧为快照帧 | |
20 | - | |
21 | -struct TrackerResult | |
22 | -{ | |
23 | - vector< vector<float> > trackers_box; | |
24 | - vector< vector< vector<float> > > trackers_history; | |
25 | -}; | |
26 | - | |
27 | - | |
28 | -typedef struct mylist | |
29 | -{ | |
30 | - vector <VPT_ObjInfo> listinfo; | |
31 | - int lost; //丢失的帧数 >LOSTMAXFRAMECCOUNT 则认为彻底丢失目标 | |
32 | - long id; | |
33 | - bool isupdate; | |
34 | - bool istraffic; | |
35 | - int index;// 行人类别 | |
36 | - int num; // 该ID序列下的第num帧 20170306 从0开始计数 | |
37 | - int startframe; //轨迹开始帧 | |
38 | - int endframe; //轨迹结束帧 | |
39 | -}mylist; | |
40 | - | |
41 | - | |
42 | - | |
43 | -class Sort | |
44 | -{ | |
45 | -public: | |
46 | - Sort(); | |
47 | - int update(int width, int height, bool isUseDet, vector< vector<float> > &dets, VPT_ObjInfo *result, vector<int> &deleteObjectID); | |
48 | - void Release(); | |
49 | - void ReSet(); | |
50 | - void Pause(); | |
51 | - bool GetState(); | |
52 | - int addTracker(cv::Mat *img); | |
53 | -public: | |
54 | - vector<KalmanBoxTracker> trackers; | |
55 | - //int FusionInterval = 5; // 221007 | |
56 | - //int max_age = 0; | |
57 | - int max_lost_times = 3; | |
58 | - int min_hits = 0; | |
59 | - int input_det_count =0; | |
60 | - int trackcount = 0; | |
61 | - int max_track_length = 0; | |
62 | - | |
63 | -private: | |
64 | - int linecount = 0; | |
65 | - bool istraffic = 0; //by zl 是否统计交通量 | |
66 | - //vector <mylist> tracker; | |
67 | - bool WORK = false; | |
68 | - | |
69 | -private: | |
70 | - void associate_detections_to_trackers(vector< vector<int> > &matched, vector<int> &unmatched_dets, vector<int> &unmatched_trks, vector< vector<float> > &dets, vector< vector<float> > &trks, float iou_threshold = 0.3); | |
71 | - //int addTracker(VPT_ObjInfo *result, int resultcount); | |
72 | - int Traffic(); | |
73 | -}; | |
74 | -//辅助函数 | |
75 | -void RectboundCheck(int Width, int Height, VPT_ObjInfo * result); //防止坐标越界 by zl | |
76 | -bool intersect(cv::Point aa, cv::Point bb, cv::Point cc, cv::Point dd); //判断两个线条是否相交 暂时未用到 | |
77 | -bool line_rect_intersection(cv::Point start_p, cv::Point end_p, int left, int top, int right, int bottom); //判断矩形框与线条是否相交 | |
78 | -#endif | |
79 | 0 | \ No newline at end of file |