#pragma once #ifndef _MY_SVIBE_H_ #define _MY_SVIBE_H_ #include #include #include #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 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 indexInWander; //std::set 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 ForegroundArray; //vector Foretest; //vector m_TargetArray; //vector 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 &ForegroundArray); //by meng 20201215 }; #endif