MSRegionSurveilance.h 5.12 KB
// 下列 ifdef 块是创建使从 DLL 导出更简单的
// 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 MSREGIONSURVEILANCE_EXPORTS
// 符号编译的。在使用此 DLL 的
// 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
// MSREGIONSURVEILANCE_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
// 符号视为是被导出的。
#ifdef MSREGIONSURVEILANCE_EXPORTS
#define MSREGIONSURVEILANCE_API __declspec(dllexport)
#else
#define MSREGIONSURVEILANCE_API __declspec(dllimport)
#endif
#include <vector>

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数

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;
	}
};

class CMPoint
{
public:
	int x;
	int y;
	bool operator == (const CMPoint& InOne)
	{
		if (x == InOne.x && y== InOne.y)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	CMPoint(int inX, int inY)
	{
		x = inX;
		y = inY;
	}

	CMPoint()
	{
		x = 0;
		y = 0;
	}
};

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;
			pbAlarmType[i] = -1;
		}

		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 pbAlarmState[MAXROINUM];   // 对应区域是否报警
	int  pbAlarmType[MAXROINUM];    // 对应区域是哪种报警

	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];    // 对应区域是哪种报警
}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;

	// 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;
};


#endif