diff --git a/src/left_over/ConExtraction.cpp b/src/left_over/ConExtraction.cpp index 13c4225..bb094f2 100644 --- a/src/left_over/ConExtraction.cpp +++ b/src/left_over/ConExtraction.cpp @@ -55,6 +55,7 @@ CConExtraction::~CConExtraction() *******************************************************************************/ vector CConExtraction::ExtractContours( unsigned char *pSrcImage,// the point to the source imagedata +float *MaskImgCfd, const int &width, // the pixel number of each coloum const int &height, // the pixel number of each row(列) const int &step // the byte number of each colum @@ -124,7 +125,7 @@ const int &step // the byte number of each colum origin.x = x; origin.y = y; - m_contour = FetchContour(img + step * y + x, step, origin); + m_contour = FetchContour(img + step * y + x, MaskImgCfd, step, origin); // for debug use //m_contour.label=0; @@ -240,6 +241,7 @@ const int &step *******************************************************************************/ CContour CConExtraction::FetchContour( unsigned char *pImage, // the pointer to the starting pixel position value of the external contour +float * cfg, const int &step, // the byte number of each colum iCPoint &pt // the starting point position of the external contour ) @@ -339,7 +341,25 @@ iCPoint &pt // the starting point position of the external contour m_Contour.bottom = m_rect.bottom; m_Contour.xCenter = (m_Contour.left + m_Contour.right) / 2; m_Contour.yCenter = (m_Contour.top + m_Contour.bottom) / 2; - m_Contour.label = true; + int count = 0; + double totalCfd = 0; + for (auto item : m_Pointvec) + { + if (cfg[item.y * step + item.x] > 0.001) + { + totalCfd += cfg[item.y * step + item.x]; + ++count; + } + } + if (count) + { + m_Contour.cfd = totalCfd / count; + m_Contour.label = true; + } + else + { + m_Contour.label = false; + } } else { @@ -349,6 +369,7 @@ iCPoint &pt // the starting point position of the external contour m_Contour.bottom = 0; m_Contour.xCenter = 0; m_Contour.yCenter = 0; + m_Contour.cfd = 0; m_Contour.label = false; } } @@ -360,6 +381,7 @@ iCPoint &pt // the starting point position of the external contour m_Contour.bottom = 0; m_Contour.xCenter = 0; m_Contour.yCenter = 0; + m_Contour.cfd = 0; m_Contour.label = false; } diff --git a/src/left_over/ConExtraction.h b/src/left_over/ConExtraction.h index bf40143..6b6c6f6 100644 --- a/src/left_over/ConExtraction.h +++ b/src/left_over/ConExtraction.h @@ -35,6 +35,7 @@ typedef struct CContour int bottom; int xCenter; int yCenter; + float cfd; bool label; }CContour; // the detected target external contour of the current frame @@ -63,7 +64,7 @@ public: virtual ~CConExtraction(); public: - vector ExtractContours (unsigned char *pSrcImage, const int &width, const int &height, const int &step); + vector ExtractContours (unsigned char *pSrcImage, float *MaskImgCfd, const int &width, const int &height, const int &step); //vector DetectTarget(unsigned char *pSrcImage, const int &width, const int &height, const int &step); @@ -77,7 +78,7 @@ private: iRect m_rect; //the rectangle of the contour private: - CContour FetchContour(unsigned char *pImage, const int &step, iCPoint &pt); + CContour FetchContour(unsigned char *pImage, float * cfg, const int &step, iCPoint &pt); void BoundingRect(vector Pointvec); //get the corresponding rectangle of a point set diff --git a/src/left_over/MSRegionSurveilance.h b/src/left_over/MSRegionSurveilance.h index 4406837..0186978 100644 --- a/src/left_over/MSRegionSurveilance.h +++ b/src/left_over/MSRegionSurveilance.h @@ -99,6 +99,7 @@ struct CForeground { CMRect m_rtConnect; CMPoint m_ptCenter; + float m_cfd; }; typedef struct CTarget @@ -152,6 +153,7 @@ typedef struct CTarget long nFrameCurr; // 记录当前逗留帧数 int lastFrame; // 上次监测到逗留距离当前的帧数 CMRect m_TarBox; + float cfd; int dwGlobalID; }CTarget; @@ -177,6 +179,7 @@ typedef struct MS_ObjectInfo { MS_Trace trace; // 轨迹及报警状态 int UniqueID; // 当前目标的特点ID CMRect TarBox; // 目标外接矩形 + float confidence; // 置信度 bool pbAlarmState[MAXROINUM]; // 对应区域是否报警 int pbAlarmType[MAXROINUM]; // 对应区域是哪种报警 }MS_ObjectInfo; @@ -190,6 +193,7 @@ public: int OBJECT_AREA_MAX; //默认最小过滤面积 by zl 20160304 int stay_dis; unsigned char* MaskImgData; + float* MaskImgCfd; int gWinSize; bool gfiltFlag; diff --git a/src/left_over/MSRegionSurveilanceCpu.cpp b/src/left_over/MSRegionSurveilanceCpu.cpp index d6ec434..8404129 100644 --- a/src/left_over/MSRegionSurveilanceCpu.cpp +++ b/src/left_over/MSRegionSurveilanceCpu.cpp @@ -78,7 +78,7 @@ int IRegionSurveillanceCpu::rs_detect(const sy_img &img_data, region_info* regio { result->obj_infos[totalObjCount].curPos.x_ = ObjInfo[i].curPos.x+rect[k].left_; // 当前坐标 result->obj_infos[totalObjCount].curPos.y_ = ObjInfo[i].curPos.y+rect[k].top_; // 当前坐标 - + result->obj_infos[totalObjCount].confidence = ObjInfo[i].confidence; result->obj_infos[totalObjCount].trace.trace_num = ObjInfo[i].trace.nTraceNum; // 轨迹及报警状态 //printf("nTraceNum = %d\n", ObjInfo[i].trace.nTraceNum); for (int j = 0; j < MAXTRACENUM; ++j) @@ -115,7 +115,7 @@ int IRegionSurveillanceCpu::rs_detect(const sy_img &img_data, region_info* regio { result->del_infos[totalDelCount].curPos.x_ = DelInfo[i].curPos.x + rect[k].left_; // 当前坐标 result->del_infos[totalDelCount].curPos.y_ = DelInfo[i].curPos.y + rect[k].top_; // 当前坐标 - + result->del_infos[totalDelCount].confidence = DelInfo[i].confidence; result->del_infos[totalDelCount].trace.trace_num = DelInfo[i].trace.nTraceNum; // 轨迹及报警状态 //printf("del_infos nTraceNum = %d\n", DelInfo[i].trace.nTraceNum); for (int j = 0; j < MAXTRACENUM; ++j) diff --git a/src/left_over/RegionSurveillanceProcess.h b/src/left_over/RegionSurveillanceProcess.h index bdb6aa5..83c71e8 100644 --- a/src/left_over/RegionSurveillanceProcess.h +++ b/src/left_over/RegionSurveillanceProcess.h @@ -2,7 +2,9 @@ #include "left_over_det.h" #include #include "header.h" +#ifndef _MSC_VER #include "checkAuthor.h" +#endif #define DEVICE_GPU 10 typedef struct rs_params { @@ -63,7 +65,9 @@ public: bool init_flag = false; sy_rect rect[MAXVERTEXNUM]; //有效区域 unsigned char rect_num; //有效区域数量 +#ifndef _MSC_VER CheckAuthor * auth = nullptr; +#endif private: //int mode; //运行模式0 cpu //MS_RegionSurveillance MS1; diff --git a/src/left_over/left_over_det.h b/src/left_over/left_over_det.h index 1f52fcd..820aada 100644 --- a/src/left_over/left_over_det.h +++ b/src/left_over/left_over_det.h @@ -92,7 +92,9 @@ typedef struct rs_param double scale; //缩小比例 sy_rect rect[MAXVERTEXNUM]; //有效区域 unsigned char rect_num; //有效区域数量 +#ifndef _MSC_VER rs_auth_config auth; +#endif rs_auth_type type; }rs_param; #endif @@ -111,12 +113,13 @@ typedef struct ms_trace { #ifndef __RS_INFO__ #define __RS_INFO__ typedef struct ms_object_info { - sy_point curPos; // 当前坐标 + sy_point curPos; // 当前坐标 ms_trace trace; // 轨迹及报警状态 int unique_id; // 当前目标的特点ID - sy_rect tar_box; // 目标外接矩形 - bool pb_alarm_state[MAXROINUM]; // 对应区域是否报警 - int pb_alarm_type[MAXROINUM]; // 对应区域是哪种报警 + sy_rect tar_box; // 目标外接矩形 + float confidence; // 置信度 + bool pb_alarm_state[MAXROINUM]; // 对应区域是否报警 + int pb_alarm_type[MAXROINUM]; // 对应区域是哪种报警 }ms_object_info; #endif diff --git a/src/left_over/ms_region_surveilance.cpp b/src/left_over/ms_region_surveilance.cpp index d73f5f3..1eca4fb 100644 --- a/src/left_over/ms_region_surveilance.cpp +++ b/src/left_over/ms_region_surveilance.cpp @@ -124,13 +124,18 @@ int rs_init(void **handle, rs_param param) bool auth_type = false; if(param.type == PRODUCT_ID) { +#ifndef _MSC_VER char uuid[36] = {}; FILE *Uuid = fopen("/proc/sys/kernel/random/uuid", "r"); fgets(uuid, 36, Uuid); fclose(Uuid); + regin->auth = new CheckAuthor; regin->auth->Init(param.auth.url, param.auth.port, uuid, productSN, 1); auth_type = regin->auth->GetAuthorStatus(); +#else + auth_type = true; +#endif } if (param.type == TIME) { @@ -237,11 +242,13 @@ int rs_process(void *handle, sy_img img_data, rs_result *result) return -1; } RegionSurveillanceProcess* regin = (RegionSurveillanceProcess*)handle; +#ifndef _MSC_VER if (regin->type == PRODUCT_ID && (regin->auth && 0 == regin->auth->GetAuthorStatus())) { printf("auth error \n"); return -1; } +#endif region_info pRegionInfo; pRegionInfo.alarm_info = 6; pRegionInfo.frame_num = regin->frame_num; @@ -383,11 +390,13 @@ void rs_release(void **handle) printf("handle is NULL \n"); return; } +#ifndef _MSC_VER if (regin->type == PRODUCT_ID && regin->auth) { regin->auth->Uninit(); delete regin->auth; } +#endif delete regin; regin = nullptr; } diff --git a/src/left_over/svibe.cpp b/src/left_over/svibe.cpp index a202f79..fb6cd84 100644 --- a/src/left_over/svibe.cpp +++ b/src/left_over/svibe.cpp @@ -157,9 +157,11 @@ int RegionSurveillance::RSinit(int nWidth, int nHeight, int widthstep, unsigned } */ - MaskImgData = (unsigned char*) malloc(sizeof(unsigned char*) * GlobelWidth * GlobelHeight); - memset(MaskImgData, 0, sizeof(unsigned char*)* GlobelWidth * GlobelHeight); + MaskImgData = (unsigned char*) malloc(sizeof(unsigned char) * GlobelWidth * GlobelHeight); + memset(MaskImgData, 0, sizeof(unsigned char)* GlobelWidth * GlobelHeight); + MaskImgCfd = (float *)malloc(sizeof(float) * GlobelWidth * GlobelHeight); + memset(MaskImgCfd, 0, sizeof(float)* GlobelWidth * GlobelHeight); if (!vbM) { // 初始化模型 @@ -371,7 +373,7 @@ VibeModel_t* RegionSurveillance::VibeModelInitC3(uint8_t *image_data) return vbM; } -void RegionSurveillance::VibeModelUpdateC1(VibeModel_t *model, uint8_t *image, uint8_t *output) +void RegionSurveillance::VibeModelUpdateC1(VibeModel_t *model, uint8_t *image, uint8_t *output, float * confidence) { int32_t x, y, xNG, yNG, count, index, dist, sampleOffset, imageOffset; uint32_t rand; @@ -402,7 +404,7 @@ void RegionSurveillance::VibeModelUpdateC1(VibeModel_t *model, uint8_t *image, u if (count < model->nMatch) { output[imageOffset] = VBPARAM->DEFAULT_COLOR_FOREGROUND; - + confidence[imageOffset] = 1.00 - ((float)count / (float)model->nMatch); if (g_frameCount < model->nSample) { rand = GetRand() % (model->nSample); @@ -415,7 +417,7 @@ void RegionSurveillance::VibeModelUpdateC1(VibeModel_t *model, uint8_t *image, u else { output[imageOffset] = VBPARAM->DEFAULT_COLOR_BACKGROUND; - + confidence[imageOffset] = 0.00; if (g_frameCount < model->nSample) { rand = GetRand() % (model->nSample); @@ -699,7 +701,7 @@ void RegionSurveillance::RSDetect(unsigned char* frameImgData, RegionInfo* pRegi delete[] inputData; } - VibeModelUpdateC1(vbM, greyImgData, MaskImgData); + VibeModelUpdateC1(vbM, greyImgData, MaskImgData, MaskImgCfd); } else { @@ -729,7 +731,7 @@ void RegionSurveillance::RSDetect(unsigned char* frameImgData, RegionInfo* pRegi delete[] inputData; } - VibeModelUpdateC1(vbM, frameImgData, MaskImgData); + VibeModelUpdateC1(vbM, frameImgData, MaskImgData, MaskImgCfd); } //VibeModelUpdateC1(vbM, greyImgData, MaskImgData); @@ -748,7 +750,7 @@ void RegionSurveillance::RSDetect(unsigned char* frameImgData, RegionInfo* pRegi */ //get trace - VibeModelGetTrace(MaskImgData, frameImgData, pRegionInfo); + VibeModelGetTrace(MaskImgData, MaskImgCfd, frameImgData, pRegionInfo); } @@ -1104,7 +1106,7 @@ void RegionSurveillance::SortForeground(vector &ForegroundArray) std::sort(ForegroundArray.begin(),ForegroundArray.end(), SortByPoint); } - +#include int RegionSurveillance::dwGlobalID; /****************************************************************************** * Function: VibeModelGetTrace @@ -1134,7 +1136,7 @@ int RegionSurveillance::dwGlobalID; m_AlarmNum 报警编号 //m_TarBox 目标的外接矩形 *******************************************************************************/ -void RegionSurveillance::VibeModelGetTrace(unsigned char* pSourceImg, unsigned char* pRGBIn, RegionInfo* pRegionInfo) +void RegionSurveillance::VibeModelGetTrace(unsigned char* pSourceImg, float *MaskImgCfd, unsigned char* pRGBIn, RegionInfo* pRegionInfo) { /* memset(regionAlarm, 0, sizeof(bool) * MAXROINUM); @@ -1157,11 +1159,11 @@ void RegionSurveillance::VibeModelGetTrace(unsigned char* pSourceImg, unsigned c // 满足条件的(像素点 面积等条件100)前景外接矩形 if (channel_num == 3) { - foreContours = pConExtraction->ExtractContours(pSourceImg, GlobelWidth, GlobelHeight, GlobelWidthstep / 3); + foreContours = pConExtraction->ExtractContours(pSourceImg, MaskImgCfd,GlobelWidth, GlobelHeight, GlobelWidthstep / 3); } else { - foreContours = pConExtraction->ExtractContours(pSourceImg, GlobelWidth, GlobelHeight, GlobelWidthstep); + foreContours = pConExtraction->ExtractContours(pSourceImg, MaskImgCfd, GlobelWidth, GlobelHeight, GlobelWidthstep); } //轨迹匹配-zhm @@ -1176,8 +1178,8 @@ void RegionSurveillance::VibeModelGetTrace(unsigned char* pSourceImg, unsigned c testTarget.m_rtConnect.bottom = foreContours[i].bottom; testTarget.m_ptCenter.x = (testTarget.m_rtConnect.left + testTarget.m_rtConnect.right) / 2; testTarget.m_ptCenter.y = (testTarget.m_rtConnect.top + testTarget.m_rtConnect.bottom) / 2; - - + testTarget.m_cfd = foreContours[i].cfd; + //大于最小过滤面积且小于最大过滤面积 by zl 20160304 int targetArea = abs((testTarget.m_rtConnect.left - testTarget.m_rtConnect.right) * (testTarget.m_rtConnect.top - testTarget.m_rtConnect.bottom)); if ( targetArea > OBJECT_AREA_MIN && targetArea < OBJECT_AREA_MAX) @@ -1318,7 +1320,7 @@ void RegionSurveillance::VibeModelGetTrace(unsigned char* pSourceImg, unsigned c //m_TargetArray[dwBestMatch].m_AlarmState5 = false; m_TargetArray[dwBestMatch].m_dwLostFrame = 0; m_TargetArray[dwBestMatch].m_ptArray.push_back(ForegroundArray[i].m_ptCenter); - + m_TargetArray[dwBestMatch].cfd = ForegroundArray[i].m_cfd; // Update current reference point int dwPointCount = m_TargetArray[dwBestMatch].m_ptArray.size(); @@ -1395,6 +1397,7 @@ void RegionSurveillance::VibeModelGetTrace(unsigned char* pSourceImg, unsigned c m_TargetArray[dwBestMatch].m_CurRefPoint.y += (double)ForegroundArray[i].m_ptCenter.y / m_dwFrameWnd; m_TargetArray[dwBestMatch].m_TarBox = ForegroundArray[i].m_rtConnect; + m_TargetArray[dwBestMatch].cfd = ForegroundArray[i].m_cfd; } @@ -2102,6 +2105,8 @@ void RegionSurveillance::getObjectInfo(int ObjCount, MS_ObjectInfo* ObjInfo) { int dwPointCount = m_FinalArray[i].m_ptArray.size(); ObjInfo[i].curPos = m_FinalArray[i].m_ptArray[dwPointCount - 1]; + ObjInfo[i].confidence = m_FinalArray[i].cfd; + int temp_dwPointCount = dwPointCount; if (dwPointCount > MAXTRACENUM) { @@ -2149,7 +2154,8 @@ void RegionSurveillance::getObjectInfo(int ObjCount, MS_ObjectInfo* ObjInfo) */ // unique ID for current object ObjInfo[i].TarBox = m_FinalArray[i].m_TarBox; //目标外接矩形 - ObjInfo[i].UniqueID = m_FinalArray[i].m_dwID; //当前目标的特点ID + ObjInfo[i].UniqueID = m_FinalArray[i].m_dwID; //当前目标的特点ID + //printf("UniqueID = %d, cfd = %f\n", ObjInfo[i].UniqueID, ObjInfo[i].confidence); } } @@ -2161,6 +2167,7 @@ void RegionSurveillance::getDeleteInfo(int DelCount, MS_ObjectInfo* ObjInfo) { int dwPointCount = m_DelArray[i].m_ptArray.size(); ObjInfo[i].curPos = m_DelArray[i].m_ptArray[dwPointCount - 1]; + int temp_dwPointCount = dwPointCount; if (dwPointCount > MAXTRACENUM) { @@ -2208,7 +2215,8 @@ void RegionSurveillance::getDeleteInfo(int DelCount, MS_ObjectInfo* ObjInfo) */ // unique ID for current object ObjInfo[i].TarBox = m_DelArray[i].m_TarBox; //目标外接矩形 - ObjInfo[i].UniqueID = m_DelArray[i].m_dwID; //当前目标的特点ID + ObjInfo[i].UniqueID = m_DelArray[i].m_dwID; //当前目标的特点ID + ObjInfo[i].confidence = m_DelArray[i].cfd; } } @@ -3340,6 +3348,13 @@ void RegionSurveillance::RSrelease() //m_TargetArray.swap(vector(0)); //m_FinalArray.swap(vector(0)); + + if (MaskImgCfd != NULL) + { + free(MaskImgCfd); + MaskImgCfd = NULL; + } + if (MaskImgData != NULL) { free(MaskImgData); diff --git a/src/left_over/svibe.h b/src/left_over/svibe.h index 66a6f74..a30bfcc 100644 --- a/src/left_over/svibe.h +++ b/src/left_over/svibe.h @@ -29,7 +29,7 @@ typedef struct VIBEPARAM //by zl 20160520 代替宏定义 目的:可修改 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) + VIBEPARAM(int samples = 20, int threshold = 35, int p_match = 20, int bgcolor = 0, int forecolor = 255, int upspeed = 16) { P_SAMPLES = samples; P_THRESHOLD = threshold; @@ -70,8 +70,8 @@ public: 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 VibeModelGetTrace(unsigned char* inputdata, float *MaskImgCfd, unsigned char* pRgbInData,RegionInfo* pRegionInfo); + void VibeModelUpdateC1(VibeModel_t *model, uint8_t *image, uint8_t *output, float * confidence); void VibeModelUpdateC3(VibeModel_t *model, uint8_t *image, uint8_t *output); int RSinit(int nWidth, int nHeight, int widthstep, unsigned char* frameImgData, @@ -119,6 +119,7 @@ public: stay_dis = 5; greyImgData = NULL; MaskImgData = NULL; + MaskImgCfd = NULL; gWinSize = 3; g_randTable = NULL; g_XTable = NULL;