Blame view

src/MSRegionSurveilance/svibe.h 6.4 KB
8805b950   Liu Meng   物品遗留效果优化
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
  #pragma once
  
  #ifndef _MY_SVIBE_H_
  #define _MY_SVIBE_H_
  
  #include <stdlib.h>
  #include <set>
  #include <list>
  #include "stdint.h"
  #include "MSRegionSurveilance.h"
  #include "ConExtraction.h"
  //#define P_SAMPLES	20
  //#define P_THRESHOLD 35
  
  //#define P_SAMPLES	35
  //#define P_THRESHOLD 18
  //#define P_MATCH		2
  //#define DEFAULT_COLOR_BACKGROUND 0
  //#define DEFAULT_COLOR_FOREGROUND 255
  //#define P_UPSPEED	16
  
  
  
  typedef struct VIBEPARAM	//by zl 20160520 代替宏定义 目的:可修改
  {
  	int P_SAMPLES;
  	int P_THRESHOLD;
  	int P_MATCH;
  	int DEFAULT_COLOR_BACKGROUND;
  	int DEFAULT_COLOR_FOREGROUND;
  	int P_UPSPEED;
  	VIBEPARAM(int samples = 20, int threshold = 35, int p_match = 2, int bgcolor = 0, int forecolor = 255, int upspeed = 16)
  	{
  		P_SAMPLES = samples;
  		P_THRESHOLD = threshold;
  		P_MATCH = p_match;
  		DEFAULT_COLOR_BACKGROUND = bgcolor;
  		DEFAULT_COLOR_FOREGROUND = forecolor;
  		P_UPSPEED = upspeed;
  	}
  	
  }VIBEPARAM;
  
  
  typedef struct VibeModel
  {
  	uint8_t *bg_samples;
  	int32_t width;
  	int32_t height; 
      int32_t nChannel;
  	int32_t widthstep;
  	int32_t nSample;      //number of samples in per pixel's background model
  	int32_t nMatch;       //number of close samples for being part of the background
  	int32_t threshold;    //radius of the sphere, the distance to compare current pixel with samples in its background model
  	int32_t upSpeed;      //random of update speed
  }VibeModel_t;
  bool CTargetFunc(CTarget &a, CTarget &b);
  class  RegionSurveillance:public IRegionSurveillance{
  public:
  	VIBEPARAM *VBPARAM;	//vibe基本参数
  	VibeModel* vbM ;
  	bool left_flag;       // 逗留标志 0 遗留 1移除
  	bool left_flag_now_w; // 逗留标志 0 遗留 1移除
  	bool left_flag_now_s; // 逗留标志 0 遗留 1移除
  	int channel_num;
  	//vector<CTarget> m_TargetArray;
  	//bool* regionAlarm;
  	//unsigned char* MaskImgData;
  
  	VibeModel_t* VibeModelInitC1(uint8_t *image_data);
  	VibeModel_t* VibeModelInitC3(uint8_t *image_data);
  
  	void VibeModelGetTrace(unsigned char* inputdata,unsigned char* pRgbInData,RegionInfo* pRegionInfo);
  	void VibeModelUpdateC1(VibeModel_t *model, uint8_t *image, uint8_t *output);
  	void VibeModelUpdateC3(VibeModel_t *model, uint8_t *image, uint8_t *output);
  	
  	int RSinit(int nWidth, int nHeight, int widthstep, unsigned char* frameImgData, 
  		int nChannel, int nChannel_deal, bool nfiltFlag, int minArea, int maxArea);	//1
  	int VPTinit(int mode, int gpuid, float threshold);
  	int RSRegion(int numROI, RegionInfo* pRegionInfo, bool iflog);
  	void vibeMask(int num, CMPoint *pPointList, bool *pRegion);
  	void RSDetect(unsigned char* frameImgData, RegionInfo* pRegionInfo);	
  
  	void RSinit_backgroud(int nWidth, int nHeight, int channels, unsigned char* frameImgData);
  
  	int  getObjectNum();
  	void getObjectInfo(int ObjCount, MS_ObjectInfo* ObjInfo);
  	
  	
  	int get_ArrowDir(CMPoint pROI0, CMPoint pROI1, CMPoint dir);//by zl
  
  	void RSrelease();	
  
  	void MonitoringAlarm(unsigned char* pRGBIn, CForeground ForegroundArray_i, int dwBestMatch, RegionInfo* pRegionInfo);
  	void AccessToRestrictedAreas(bool *pRegion_i, int dwBestMatch, int ForBottom, int ForTop, int ForLeft, int ForRight, int indexROI);
  	void LeaveTheRestrictedAreas(bool *pRegion_i, int dwBestMatch, int ForBottom, int ForTop, int ForLeft, int ForRight, int indexROI);
  	void OneWayCrossBorder(bool *pRegion_i, int dwBestMatch, int ForBottom, int ForTop, int ForLeft, int ForRight, int indexROI, RegionInfo* pRegionInfo);
  	void TwoWayCrossBorder(bool *pRegion_i, int dwBestMatch, int ForBottom, int ForTop, int ForLeft, int ForRight, int indexROI);
  	bool detectLeftRemove(unsigned char* pRGBIn, int ForBottom, int ForTop, int ForLeft, int ForRight);
  	void WanderMonitoring(bool *pRegion_i, int dwBestMatch, int ForBottom, int ForTop, int ForLeft, int ForRight, int indexROI, RegionInfo* pRegionInfo, unsigned char* pRGBIn);
  	void StayMonitoring(bool *pRegion_i, int dwBestMatch, int ForBottom, int ForTop, int ForLeft, int ForRight, int indexROI, RegionInfo* pRegionInfo, unsigned char* pRGBIn);
  	//void ExternalRectangle(unsigned char* pRGBIn, CForeground ForegroundArray_i, int dwBestMatch, int widthStep, 
  		//int rgb_b, int rgb_g, int rgb_r);
  	//void Trajectory(unsigned char* pRGBIn, CForeground ForegroundArray_i, int dwBestMatch, int width, int height, int widthStep);
  
  	RegionSurveillance()
  	{
  		vbM = NULL;
  		pAlarmInfo = NULL;
  		//regionAlarm = NULL;
  		pRegion = NULL;
  		GlobelWidth = 0;
  		GlobelHeight = 0;
  		g_frameCount = 0;
  		left_flag = 1; // 逗留标志 0 遗留 1移除
  		left_flag_now_s = 1;
  		left_flag_now_w = 1;
  		OBJECT_AREA_MIN = 1000000;		//默认最大过滤面积为1,000,000	by zl 20160304
  		OBJECT_AREA_MAX = 300;		//默认最小过滤面积为300	by zl 20160304
  	
  		stay_dis = 5;
  		greyImgData = NULL;
  		MaskImgData = NULL;
  		gWinSize = 3;
  		g_randTable = NULL;
  		g_XTable = NULL;
  		g_YTable = NULL;
  		maskImg = NULL;
  		VBPARAM = NULL;
  	}
  
  private:
  	CConExtraction *pConExtraction;
  	unsigned char* greyImgData;
  	unsigned char* maskImg;	// add by zl 20160519 用于腐蚀膨胀加速
  	int GlobelWidth;
  	int GlobelHeight;
  	int GlobelWidthstep;
  	std::list<CTarget> indexInWander;
  	//std::set<int> indexInWander;
  	CMPoint pStart, pEnd; //by zl 用于存储可通行方向箭头的两个端点
  	
  
  	//bool forInit = false;
  	int m_numROI;
  	int* pAlarmInfo;
  	bool** pRegion;
  	
  	void VibeModelFree(VibeModel_t *model);
  
  	//膨胀和腐蚀后带2的均为汇编加速版本
  	void VibeModelDilation2(unsigned char* inputdata,unsigned char *output, int width,int height);
  	void VibeModelErosion2(unsigned char* inputdata, unsigned char *output, int width,int height);	
  
  	void VibeModelDilation(unsigned char* inputdata,int width,int height);
  	void VibeModelErosion(unsigned char* inputdata,int width,int height);
      void VibeRGBToGray(unsigned char* RgbData, unsigned char* GrayData);
  	
  	//vector<CForeground> ForegroundArray;
      //vector<int> Foretest;
      //vector<CTarget> m_TargetArray;
      //vector<CTarget> m_FinalArray;
  
      int32_t g_frameCount;
  
  private:
  
  	uint32_t *g_randTable;
  	int32_t flag;
  	uint32_t i_rand;
  	int32_t *g_XTable;
  	int32_t *g_YTable;
  	int32_t g_XNeighborTable[8] ;
  	int32_t g_YNeighborTable[8] ;
  
  	//random num
  	void RandInit();
  	uint32_t GetRand();
  	void FreeRand();
  
  	//random neighbor
  	void RandNeighborInit(int32_t width, int32_t height);
  	void GetRandNeighborXY(int32_t x, int32_t y, int32_t *_x, int32_t *_y);
  
  	//get neighbor
  	void GetNeighborXY(int32_t x, int32_t y, int32_t *_x, int32_t *_y, int32_t flag);
  	void FreeRandNeighbor();
  
  public:
  	int dwGlobalID;	// object ID for Global use
  
  	//by zl 20160307
  	private:
  		void SortForeground(vector<CForeground> &ForegroundArray);
  
  		//by meng 20201215
  };
  
  #endif