Blame view

src/VPT/snapshot_analysis/snapshot_helper.h 7.04 KB
e30d6793   Zou XiKun   v0.0.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
  #include <bitset>
  #include "../../DxDecoder/DxDecoderWrap.h"
  #include "common.h"
  #include <queue>
  #include <string>
  #include <set>
  #include <unordered_map>
  #include <boost/thread/thread.hpp>
  #include <mutex>
  #include <condition_variable>
  #include "ImageSaveCache.h"
  using namespace std;
  
  #define EDGESIZE 4
  #define HP_WIDTH 112
  #define HP_HEIGHT 224
  #define HCP_WIDTH 224
  #define HCP_HEIGHT 224
  #define VEHICLE_WIDTH 320
  #define VEHICLE_HEIGHT 320
  
  //#define OBJ_BATCH_COUNT 20//定义多少个目标组成一组batch送入二次分析的算法
  //#define OBJ_BATCH_COUNT_VEHICLE 10   //定义多少个目标组成一组batch送入二次分析的算法
  #define IMG_CHANNELS 3
  
  #ifndef _MSC_VER
  	#ifndef TRUE
  	#define    TRUE         1
  	#endif
  	#ifndef FALSE
  	#define    FALSE        0
  	#endif
  	#define Sleep(a) usleep((a)*1000)
  	//typedef    int    BOOL;
  #define BOOL bool
  	typedef    unsigned int    DWORD;
  	typedef    void*	LPVOID;
  #endif
  
  struct AABBBOX
  {
  	int left;
  	int top;
  	int right;
  	int bottom;
  };
  
  //struct OBJ_KEY {
  //	int videoID;
  //	int objID;
  //
  //	bool operator< (OBJ_KEY const& _A) const
  //	{
  //		if (videoID < _A.videoID)  return true;
  //		if (videoID == _A.videoID) return objID < _A.objID;
  //
  //		return false;
  //	}
  //	bool operator== (OBJ_KEY const& _A) const
  //	{
  //		if (videoID == _A.videoID && objID == _A.objID)
  //			return true;
  //		else
  //			return false;
  //	}
  //};
  
  struct OBJ_INDEX {
  	int index;
  	int count;  //用于对index的计数
  };
  
  struct OBJ_VALUE {
  	bool finishTracker;  //轨迹结束可以保存了
  	int frameCount;
  	bool isupdate;
  	int lost;
  	DxGPUFrame snapShot;
  	DxGPUFrame snapShotLittle;
  	AABBBOX box;
  	double confidence;	   	//	置信度
  							//int index;
  
  	float lastArea;
  	bitset<EDGESIZE>      flags;    //标志位,标记快照框应该如何判断,left:0  top:1  right:2  bottom:3
  
  	OBJ_INDEX index;
  };
  
  struct TASK_INFO {
  	char* image_folder;
  	char* snapshot_folder;
  	int task_total_framecount;
  	SNAPSHOT_CALLBACK obj_callback;
  
  	TASK_INFO() :image_folder(NULL), snapshot_folder(NULL), obj_callback(NULL) {}
  };
  
  struct OBJ_SIZE {
  	int original_width;
  	int original_height;
  };
  
  struct SNAPSHOT_IMAGE_UNIT {
  	cv::Mat image;
  	bool flag;
  	string file_name;
  	OBJ_SIZE original_size;
  	OBJ_KEY obj_key;
  	bool is_image;
  	SNAPSHOT_IMAGE_UNIT(int height, int width, int type, float* data) :image(height, width, type, data) {}
  	SNAPSHOT_IMAGE_UNIT(int height, int width, int type, unsigned char* data) :image(height, width, type, data) {}
  	SNAPSHOT_IMAGE_UNIT() {}
  };
  
  enum {
  	HP_ANALYSIS,
  	HCP_ANALYSIS,
  	VC_ANALYSIS
  };
  
  //enum class VC_ANALYSIS_TYPE {
  //	VC_ANALYSIS,
  //	VR_VF_ANALYSIS,
  //	VPDR_ANALYSIS
  //};
  
  enum class V_ANALYSIS_TYPE {
  	VC_ANALYSIS,
  	VR_VF_ANALYSIS,
  	VPDR_ANALYSIS
  };
  
  extern string ObjTypes[];
  extern string ObjTypesEnglish[];
  
  class snapshot_helper
  {
  private:
  	queue<OBJ_KEY> count_person;
  	queue<OBJ_KEY> count_bike;
  	queue<OBJ_KEY> count_vehicle; 
  	//map<OBJ_KEY, hp_result> snapShotInfo_hpf;
  	//map<OBJ_KEY, hcp_result> snapShotInfo_hcpf;
  
  	vector<OBJ_KEY> count_vehicle_v;   //车的二次属性分析拆为三部分时,不再使用队列,只能使用数组
  	
  	vector<vehicle_result> vehicle_result_v;
  
  	sy_img * batch_hp = nullptr;
  	sy_img * batch_hcp = nullptr;
  	sy_img * batch_vehicle = nullptr;
  	sy_img * batch_vehicle_vf = nullptr;
  
  	void * hp_handle = nullptr;
  	void * hcp_handle = nullptr;
  	void * vc_handle = nullptr;
  	void * vp_handle = nullptr;
  	void * vr_handle = nullptr;
  	void * vrr_handle = nullptr;
  	void * nvf_handle = nullptr;
  	void * vhd_handle = nullptr;
  	void * vf_handle = nullptr;
  	sy_command hp_analysis_cf;
  	sy_command hcp_analysis_cf;
  	sy_command vehicle_analysis_cf;
  	
  	sy_command hf_recg_cf;
  	sy_command hcf_recg_cf;
  	sy_command vcf_recg_cf;
  
  	void * hf_handle = nullptr;
  	void * hcf_handle = nullptr;
  	sy_command vehicle_recg_cf;
  	sy_command vehicle_plate_det_recg_cf;
  	int count_vehivle_finishanalysis = 0;
  	int OBJ_SCALE = 2;
  	int OBJ_BATCH_COUNT = 0;
  	int OBJ_BATCH_COUNT_VEHICLE = 0;
  
  	boost::thread ProcessSnapshotThread;
  	
  public:
  	std::mutex callback_tx;
  	map<OBJ_KEY, OBJ_VALUE> snapShotInfo;
  	queue<SNAPSHOT_IMAGE_UNIT> snapshotImageQueue;
  	map<OBJ_KEY, video_object_snapshot> finished_analysis_ss_info;
  	queue<OBJ_KEY> finished_save_ss_info_que;
  	set<OBJ_KEY> finished_save_ss_info;
  	unordered_map<int, TASK_INFO> m_task_info;
  	ImageSaveCache ImgSaveCache;
  	std::deque<SNAPSHOT_IMAGE_UNIT> cur_image_queue;
  	std::mutex threadMutex;
  	std::mutex writeThreadMutex;
  	std::mutex analysisThreadMutex;
  	std::mutex finishedThreadMutex;
  	//std::condition_variable writeThreadCondVar;
  	//VC_ANALYSIS_TYPE vc_analysis;
  	V_ANALYSIS_TYPE v_analysis;
  	void snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, sy_command hp_analysis_config, \
  		sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command vehicle_recg_config, sy_command vehicle_plate_det_recg_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config);
  	void snapshot_helper_release();
  	void add_task_info(int new_task_id, TASK_INFO new_task_info);
  	void delete_task_info(int new_task_id, TASK_INFO new_task_info);
  	int save_snapshot(bool is_image, OBJ_KEY obj_key, char* filename, char* mode, float* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom);
  	int save_snapshot(bool is_image, OBJ_KEY obj_key, char* filename, char* mode, unsigned char* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom);
  	int save_snapshot(OBJ_KEY obj_key);
  
  	void save_without_analysis(OBJ_KEY obj_key);
  	void erase_snapshotImage(OBJ_KEY obj_key);
  	//整体的三种二次属性分析
  	void hp_analysis(OBJ_KEY obj_key);
  	void hcp_analysis(OBJ_KEY obj_key);
  	void vehicle_analysis(OBJ_KEY obj_key);
  
  	void hp_analysis();
  	void hcp_analysis();
  	bool vehicle_color_analysis();
  	bool vehicle_recg_analysis();
  	bool vehicle_plate_dr_analysis();
  	void vf_feature();
  	void vf_feature(sy_img *batch_vehicle_f, int batch_size, map<int, OBJ_KEY> &mp_head);
  	void finish_task_ss_analysis(int task_id, sy_command hp_analysis_config, sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config);
  	//针对车拆开的二次属性分析
  	void VehicleRecog_Process(sy_img * batch_img, int batchsize, vr_result *&vresult, OBJ_KEY* obj_keys);
  	void object_attri_analysis();
  	void snapshot_res_callback(OBJ_KEY obj_key,/* OBJ_VALUE obj_value,*/ void* analysisRes = NULL);
  
  	void hp_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag);
  	void hcp_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag);
  	void vehicle_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag);
  	void vf_feature(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis);
  	void hf_features(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag);
  	void vehicle_color_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis);
  	void vehicle_plate_dr_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis);
  	void vehicle_recg_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis);
  
  };