/************************************************************************* * 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 #include #include #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 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 m_TargetArray; vector 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