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
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
|
/*************************************************************************
* Version: 区域监控SDK_v0.4.6
* CopyRight: 中科视语(北京)科技有限公司
* UpdateDate:20190917
* Content: 区域监控
*************************************************************************/
#ifdef _MSC_VER
#ifdef MSREGIONSURVEILANCE_EXPORTS
#define MSREGIONSURVEILANCE_API __declspec(dllexport)
#else
#define MSREGIONSURVEILANCE_API __declspec(dllimport)
#endif
#else
#define MSREGIONSURVEILANCE_API __attribute__ ((visibility ("default")))
#endif
#include <vector>
#include <cmath>
#include <cstdlib>
#include "header.h"
using namespace std;
#define MAXTRACENUM 200 //轨迹最大长度
#define m_BOUNDING_BOX_MIN 50
#define m_BOUNDING_BOX_MAX 500
#define m_BOUNDING_BOX_RATEMIN 0.001
#ifndef __MSREGIONSURVEILANCE_H__
#define __MSREGIONSURVEILANCE_H__
#define m_BOUNDING_BOX_RATEMAX 100
#define MAXVERTEXNUM 10
#define MAXROINUM 10 // 最大ROI数
#define ALARMTYPENUM 6 // 报警类型数量
#ifdef __cplusplus
extern "C"
{
#endif
struct CSizeDouble
{
double cx;
double cy;
};
class CMRect
{
public:
int left;
int top;
int right;
int bottom;
int Width()
{
return abs(right - left);
}
int Height()
{
return abs(bottom - top);
}
CMRect()
{
left = 0;
right = 0;
top = 0;
bottom = 0;
}
CMRect(int InLeft, int InTop, int InRight, int InBottom)
{
left = InLeft;
top = InTop;
right = InRight;
bottom = InBottom;
}
CMRect& operator = (const CMRect& Input)
{
left = Input.left;
top = Input.top;
right = Input.right;
bottom = Input.bottom;
return *this;
}
};
struct CMPointDouble
{
double x;
double y;
};
struct CForeground
{
CMRect m_rtConnect;
CMPoint m_ptCenter;
};
typedef struct CTarget
{
CTarget()
{
m_dwLostFrame = 0;
m_bCalc = true;
m_dwID = 0;
m_VectorDirection.cx = 0.0;
m_VectorDirection.cy = 0.0;
m_CurRefPoint.x = 0.0;
m_CurRefPoint.y = 0.0;
m_LastRefPoint.x = 0.0;
m_LastRefPoint.y = 0.0;
m_PredictionBasePoint.x = 0.0;
m_PredictionBasePoint.y = 0.0;
m_PredictionPoint.x = 0.0;
m_PredictionPoint.y = 0.0;
m_dwBestMatch = -1;
m_bHaveDirection = false;
for (int i = 0; i < MAXROINUM; i++)
{
pbAlarmState[i] = false;
for (int k = 0; k < ALARMTYPENUM; ++k)
{
pbAlarmType[i][k] = 0;
}
}
oneCross_flag = 0;
nFrameCurr = 0; // 记录当前逗留帧数
lastFrame = 0; // 上次监测到逗留距离当前的帧数
dwGlobalID = 0;
}
vector<CMPoint> m_ptArray;
CSizeDouble m_VectorDirection;
CMPointDouble m_CurRefPoint;
CMPointDouble m_LastRefPoint;
CMPointDouble m_PredictionBasePoint;
CMPointDouble m_PredictionPoint;
bool m_bHaveDirection;
int m_dwLostFrame;
int m_dwID;
int m_dwBestMatch;
bool m_bCalc;
bool m_bFirstInWander = true;
bool pbAlarmState[MAXROINUM]; // 对应区域是否报警
int pbAlarmType[MAXROINUM][ALARMTYPENUM]; // 对应区域是哪种报警
bool oneCross_flag;
long nFrameCurr; // 记录当前逗留帧数
int lastFrame; // 上次监测到逗留距离当前的帧数
CMRect m_TarBox;
int dwGlobalID;
}CTarget;
// 运动目标坐标及轨迹
typedef struct MS_Trace {
int nTraceNum; // 轨迹长度,描述pObjTrace的长度
CMPoint pObjTrace[MAXTRACENUM]; // 轨迹,点坐标
}MS_Trace;
typedef struct RegionInfo {
int AlarmInfo; // 1进入禁区 2离开禁区 3单向越界 4双向越界 5徘徊 6丢包
int nPointNum;
CMPoint pROI[MAXVERTEXNUM];
long nFrameNum; // 逗留时间 单位帧数
CMPoint dirPoint;
int finaldir; //无须用户指定
CMPoint ArrowStartPoint; //箭头的起始端点 箭头指向正方形
CMPoint ArrowEndPoint; //箭头的终止端点 箭头指向正方形
}RegionInfo;
typedef struct MS_ObjectInfo {
CMPoint curPos; // 当前坐标
MS_Trace trace; // 轨迹及报警状态
int UniqueID; // 当前目标的特点ID
CMRect TarBox; // 目标外接矩形
bool pbAlarmState[MAXROINUM]; // 对应区域是否报警
int pbAlarmType[MAXROINUM][ALARMTYPENUM]; // 对应区域是哪种报警
}MS_ObjectInfo;
class MSREGIONSURVEILANCE_API IRegionSurveillance {
public:
vector<CTarget> m_TargetArray;
vector<CTarget> m_FinalArray;
int OBJECT_AREA_MIN; //默认最大过滤面积 by zl 20160304
int OBJECT_AREA_MAX; //默认最小过滤面积 by zl 20160304
int stay_dis;
unsigned char* MaskImgData;
int gWinSize;
bool gfiltFlag;
// 模型初始化
virtual int RSinit(int nWidth, int nHeight, int widthstep, unsigned char* frameImgData, int nChannel, int nChannel_deal, bool nfiltFlag, int minArea = 0, int maxArea = 1000000) = 0;
// 背景图像初始化
virtual void RSinit_backgroud(int nWidth, int nHeight, int channels, unsigned char* frameImgData) = 0;
// ROI区域初始化
virtual int RSRegion(int numROI, RegionInfo* pRegionInfo, bool iflog) = 0;
// 每一帧图像检测
virtual void RSDetect(unsigned char* frameImgData, RegionInfo* pRegionInfo) = 0;
// 目标数获取
virtual int getObjectNum() = 0;
// 获取目标信息(包括目标框、轨迹、报警等信息)
virtual void getObjectInfo(int ObjCount, MS_ObjectInfo* ObjInfo) = 0;
//计算方向和箭头绘制的两个端点
virtual int get_ArrowDir(CMPoint pROI0, CMPoint pROI1, CMPoint dir) = 0;//by zl
//资源释放
virtual void RSrelease() = 0;
};
class MSREGIONSURVEILANCE_API MS_RegionSurveillance {
public:
MS_RegionSurveillance() :MS_RS(NULL) {};
IRegionSurveillance* GetMS_RS();
void Destroy();
private:
IRegionSurveillance *MS_RS;
};
#ifdef __cplusplus
}
#endif
#endif
|