From a74689b77248633e4cd19ecc3254709c24408c4c Mon Sep 17 00:00:00 2001 From: xkzou Date: Tue, 20 Oct 2020 14:50:29 +0800 Subject: [PATCH] 海思 --- src/left_over/MSRegionSurveilance.cpp | 5 +++-- src/left_over/MSRegionSurveilance.h | 3 +++ src/left_over/MSRegionSurveilanceBase.cpp | 1094 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/left_over/MSRegionSurveilanceBase.h | 77 ----------------------------------------------------------------------------- src/left_over/MSRegionSurveilanceCpu.cpp | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------- src/left_over/MSRegionSurveilanceCpu.h | 18 +++++++++++++----- src/left_over/MSRegionSurveilanceHst.cpp | 67 ------------------------------------------------------------------- src/left_over/MSRegionSurveilanceHst.h | 19 ------------------- src/left_over/MSRegionSurveilanceVpt.cpp | 93 --------------------------------------------------------------------------------------------- src/left_over/MSRegionSurveilanceVpt.h | 18 ------------------ src/left_over/RegionSurveillanceProcess.h | 10 ++++++---- src/left_over/helper.cpp | 8 ++++---- src/left_over/left_over_det.h | 25 ++++++++++++++++++------- src/left_over/ms_region_surveilance.cpp | 213 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------- src/left_over/svibe.cpp | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------- src/left_over/svibe.h | 2 +- src/test/demo.cpp | 36 ++++++++++++++++++++++++++---------- src/test/regionassist.h | 2 +- 18 files changed, 536 insertions(+), 1573 deletions(-) delete mode 100644 src/left_over/MSRegionSurveilanceBase.cpp delete mode 100644 src/left_over/MSRegionSurveilanceBase.h delete mode 100644 src/left_over/MSRegionSurveilanceHst.cpp delete mode 100644 src/left_over/MSRegionSurveilanceHst.h delete mode 100644 src/left_over/MSRegionSurveilanceVpt.cpp delete mode 100644 src/left_over/MSRegionSurveilanceVpt.h diff --git a/src/left_over/MSRegionSurveilance.cpp b/src/left_over/MSRegionSurveilance.cpp index 88a3468..c212679 100644 --- a/src/left_over/MSRegionSurveilance.cpp +++ b/src/left_over/MSRegionSurveilance.cpp @@ -7,8 +7,9 @@ IRegionSurveillance *MS_RegionSurveillance::GetMS_RS() { - if (!MS_RS) + //if (!MS_RS) { + RegionSurveillance * MS_RS = nullptr; if (checkTime() == 1 && (MS_RS = new RegionSurveillance())) return MS_RS; else @@ -25,7 +26,7 @@ void MS_RegionSurveillance::Destroy() { if (MS_RS) { - delete MS_RS; + delete[] MS_RS; MS_RS = NULL; } } diff --git a/src/left_over/MSRegionSurveilance.h b/src/left_over/MSRegionSurveilance.h index c766323..b255be9 100644 --- a/src/left_over/MSRegionSurveilance.h +++ b/src/left_over/MSRegionSurveilance.h @@ -17,6 +17,9 @@ #include #include #include "header.h" +#include "ConExtraction.h" +#include +#include using namespace std; #define MAXTRACENUM 200 //켣󳤶 diff --git a/src/left_over/MSRegionSurveilanceBase.cpp b/src/left_over/MSRegionSurveilanceBase.cpp deleted file mode 100644 index 0119ef1..0000000 --- a/src/left_over/MSRegionSurveilanceBase.cpp +++ /dev/null @@ -1,1094 +0,0 @@ -#include "MSRegionSurveilanceBase.h" - -IRegionSurveillanceBase::IRegionSurveillanceBase() -{ - pRegion = nullptr; - pAlarmInfo = nullptr; -} - -int IRegionSurveillanceBase::rs_init(const rs_param & param) -{ - GlobelWidth = param.image.w_; - GlobelHeight = param.image.h_; - - return init(param); - -} - -int IRegionSurveillanceBase::rs_init_region(int numROI, region_info* region_infos, bool iflog) -{ - fstream file;//־ - if (numROI > MAXROINUM) - { - return 0; - } - - for (int i = 0; i < numROI; i++) - { - if (iflog) - { - file.open("log.txt", ios::app); - file << i << ": "; - printAlarmType(&file, region_infos[i].alarm_info); - file << "P1(" << region_infos[i].p_roi[0].x_ << "," << region_infos[i].p_roi[0].y_ << "), P2(" - << region_infos[i].p_roi[1].x_ << "," << region_infos[i].p_roi[1].y_ << ")"; - } - if (region_infos[i].alarm_info == 3) - { - region_infos[i].finaldir = rs_get_arrowdir(region_infos[i].p_roi[0], region_infos[i].p_roi[1], region_infos[i].dir_point);//ȷ㣬ͷ˵ - - if (iflog) - file << ", DirPoint(" << region_infos[i].dir_point.x_ << "," << region_infos[i].dir_point.y_ << ")"; - - region_infos[i].arrow_start_point = pStart; //ͷʼ˵ ͷָ - region_infos[i].arrow_end_point = pEnd; //ͷֹ˵ ͷָ - } - if (iflog) - { - file << endl; - file.close(); - } - } - - m_numROI = numROI; - if (pRegion == NULL) - { - pRegion = new bool*[MAXROINUM]; - memset(pRegion, 0, sizeof(bool*) * MAXROINUM); - } - - if (pAlarmInfo == NULL) - { - pAlarmInfo = new int[MAXROINUM]; - memset(pAlarmInfo, 0, sizeof(int) * MAXROINUM); - } - - for (int i = 0; i < MAXROINUM; i++) - { - if (pRegion[i] == NULL) - { - pRegion[i] = new bool[GlobelHeight * GlobelWidth]; - } - memset(pRegion[i], 0, sizeof(bool) * GlobelWidth * GlobelHeight); - if (i <= m_numROI) - { - pAlarmInfo[i] = region_infos[i].alarm_info; - } - else - { - pAlarmInfo[i] = 0; - } - } - - - // ÿһ۲ROIм - for (int i = 0; i < numROI; i++) - { - // ÿһȤб־ ȤpRegionֵΪ1 Ϊ0 - vibeMask(region_infos[i].point_num, region_infos[i].p_roi, pRegion[i]); - } - - return 1; - -} - -void IRegionSurveillanceBase::RSrelease() -{ - for (int i = 0; i < MAXROINUM; i++) - { - if (pRegion[i] != NULL) - { - delete[] pRegion[i]; - } - } - - if (pRegion != NULL) - { - delete[] pRegion; - pRegion = NULL; - } - - if (pAlarmInfo != NULL) - { - delete[] pAlarmInfo; - pAlarmInfo = NULL; - } - release(); - vec_traceinfo.clear(); -} - -int IRegionSurveillanceBase::rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) -{ - - float distance = (float)abs(p_roi0.y_ - p_roi1.y_); - //ȡ - float k1, k2; //k1Ϊԭ߶εб - - if (p_roi0.y_ > p_roi1.y_) //ڰ߿ͼ·Ķ˵㴦ͷ - { - pStart.x_ = p_roi0.x_; - pStart.y_ = p_roi0.y_; - } - else - { - pStart.x_ = p_roi1.x_; - pStart.y_ = p_roi1.y_; - } - - if (p_roi0.x_ != p_roi1.x_) //Ϊһֱ - { - k1 = (float)(p_roi0.y_ - p_roi1.y_) / (float)(p_roi0.x_ - p_roi1.x_); - if (k1 != 0) //Ϊһƽ - { - k2 = -1 / k1; - - - float b = p_roi1.y_ - k1 * p_roi1.x_;//y = kx + b ϵһͼ϶Ϊԭ㣬Ϊx Ϊy - if ((k1 < 0 && (float)((float)dir.y_ - k1 * (float)dir.x_ - b) < 0) || (k1 > 0 && (float)((float)dir.y_ - k1 * (float)dir.x_ - b) > 0)) - { - if (distance < 30) //yֵСʱ߱Ƚ϶ ȥ20 ܵ¼ͷ̫ - { - pEnd.x_ = pStart.x_ - 2; - } - else - pEnd.x_ = pStart.x_ - 20; - } - else - { - if (distance < 30) - { - pEnd.x_ = pStart.x_ + 2; - } - else - pEnd.x_ = pStart.x_ + 20; - } - pEnd.y_ = (int)((pEnd.x_ - pStart.x_) * k2 + pStart.y_); - } - else //Ϊˮƽ - { - pEnd.x_ = pStart.x_; - if (dir.y_ > pStart.y_) - pEnd.y_ = pStart.y_ + 20; - else - pEnd.y_ = pStart.y_ - 20; - - } - - } - else //Ϊֱ - { - pEnd.y_ = pStart.y_; - if (dir.x_ > pStart.x_) - pEnd.x_ = pStart.x_ + 20; - else - pEnd.x_ = pStart.x_ - 20; - } - //ֹԽ - pEnd.x_ = pEnd.x_ >= 0 ? pEnd.x_ : 0; - pEnd.x_ = pEnd.x_ <= GlobelWidth ? pEnd.x_ : GlobelWidth; - pEnd.y_ = pEnd.y_ >= 0 ? pEnd.y_ : 0; - pEnd.y_ = pEnd.y_ <= GlobelHeight ? pEnd.y_ : GlobelHeight; - - if (p_roi0.x_ == p_roi1.x_) //Ϊֱ - { - if (pEnd.x_ > pStart.x_) - return 1; - else - return 0; - } - else if (k1 <= 0) //ΪֱбСڵ0ˮƽ - { - if ((pStart.x_ != pEnd.x_ && pEnd.x_ > pStart.x_) || (pStart.x_ == pEnd.x_ && pEnd.y_ > pStart.y_)) - return 0; - else - return 1; - } - else - { - if ((pStart.x_ != pEnd.x_ && pEnd.x_ > pStart.x_) || (pStart.x_ == pEnd.x_ && pEnd.y_ > pStart.y_)) - return 1; - else - return 0; - } -} - -void IRegionSurveillanceBase::vibeMask(int num, sy_point *pPointList, bool *pRegion) -{ - - if (num == 2) - { - double s; - int i, x, y; - int xs, ys; - int dx, dy; - - dx = pPointList[1].x_ - pPointList[0].x_; - if (dx < 0) - { - dx = -dx; - } - dy = pPointList[1].y_ - pPointList[0].y_; - if (dy < 0) - { - dy = -dy; - } - if (dy < dx) - { - //draw according to x-y - s = (double)(pPointList[1].y_ - pPointList[0].y_) / (pPointList[1].x_ - pPointList[0].x_); - - if (pPointList[0].x_ < pPointList[1].x_) - { - xs = pPointList[0].x_; - ys = pPointList[0].y_; - } - else - { - xs = pPointList[1].x_; - ys = pPointList[1].y_; - } - - for (i = 0; i <= dx; i++) - { - x = i + xs; - y = (int)((double)i * s) + ys; - if (x > -1 && x < GlobelWidth && y > -1 && y < GlobelHeight) - { - pRegion[GlobelWidth * y + x] = 1; - } - } - } - else - { - //draw according to y-x - s = (double)(pPointList[1].x_ - pPointList[0].x_) / (pPointList[1].y_ - pPointList[0].y_); - - if (pPointList[0].y_ < pPointList[1].y_) - { - xs = pPointList[0].x_; - ys = pPointList[0].y_; - } - else - { - xs = pPointList[1].x_; - ys = pPointList[1].y_; - } - for (i = 0; i <= dy; i++) - { - y = i + ys; - x = (int)((double)i * s) + xs; - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth) - { - pRegion[GlobelWidth * y + x] = 1; - } - } - } - } - else if (num >= 3) - { - - sy_point LineMin; - sy_point LineMax; - - for (int k = 0; k < num; k++) - { - int startp = k; - int endp = k + 1; - - if (startp == num - 1) - { - endp = 0; - } - - if (abs(pPointList[startp].x_ - pPointList[endp].x_) >= abs(pPointList[startp].y_ - pPointList[endp].y_)) - { - if (pPointList[startp].x_ < pPointList[endp].x_) - { - LineMin = pPointList[startp]; - LineMax = pPointList[endp]; - for (int x = LineMin.x_; x <= LineMax.x_; x++) - { - int y = (int)(((LineMin.y_ - LineMax.y_) / (double)(LineMin.x_ - LineMax.x_)) * (double)(x - LineMin.x_) + 0.5 + (double)LineMin.y_); - //pRegion[GlobelWidth * y + x] = 1; - - //ԭԽ ܿ޸ - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth) - { - pRegion[GlobelWidth * y + x] = 1; - } - } - } - else if (pPointList[startp].x_ > pPointList[endp].x_) - { - LineMin = pPointList[endp]; - LineMax = pPointList[startp]; - for (int x = LineMin.x_; x <= LineMax.x_; x++) - { - int y = (int)(((LineMin.y_ - LineMax.y_) / (double)(LineMin.x_ - LineMax.x_)) * (double)(x - LineMin.x_) + 0.5 + (double)LineMin.y_); - //pRegion[GlobelWidth * y + x] = 1; - - //ԭԽ ܿ޸ - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth) - { - pRegion[GlobelWidth * y + x] = 1; - } - } - } - else - { - int YMin = (pPointList[startp].y_ < pPointList[endp].y_) ? pPointList[startp].y_ : pPointList[endp].y_; - int YMax = (pPointList[startp].y_ < pPointList[endp].y_) ? pPointList[endp].y_ : pPointList[startp].y_; - for (int i = YMin; i <= YMax; i++) - { - //pRegion[GlobelWidth * i + pPointList[startp].x_] = 1; - - //ԭԽ ܿ޸ - if (i > -1 && i < GlobelHeight && pPointList[startp].x_ > -1 && pPointList[startp].x_ < GlobelWidth) - { - pRegion[GlobelWidth * i + pPointList[startp].x_] = 1; - } - } - } - } - else - { - if (pPointList[startp].y_ < pPointList[endp].y_) - { - LineMin = pPointList[startp]; - LineMax = pPointList[endp]; - for (int y = LineMin.y_; y <= LineMax.y_; y++) - { - int x = (int)(((LineMin.x_ - LineMax.x_) / (double)(LineMin.y_ - LineMax.y_)) * (double)(y - LineMin.y_) + 0.5 + (double)LineMin.x_); - //pRegion[GlobelWidth * y + x] = 1; - - //ԭԽ ܿ޸ - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth) - { - pRegion[GlobelWidth * y + x] = 1; - } - } - } - else if (pPointList[startp].y_ > pPointList[endp].y_) - { - LineMin = pPointList[endp]; - LineMax = pPointList[startp]; - for (int y = LineMin.y_; y <= LineMax.y_; y++) - { - int x = (int)(((LineMin.x_ - LineMax.x_) / (double)(LineMin.y_ - LineMax.y_)) * (double)(y - LineMin.y_) + 0.5 + (double)LineMin.x_); - //pRegion[GlobelWidth * y + x] = 1; - - //ԭԽ ܿ޸ - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth) - { - pRegion[GlobelWidth * y + x] = 1; - } - } - } - else - { - int XMin = (pPointList[startp].x_ < pPointList[endp].x_) ? pPointList[startp].x_ : pPointList[endp].x_; - int XMax = (pPointList[startp].x_ < pPointList[endp].x_) ? pPointList[endp].x_ : pPointList[startp].x_; - for (int i = XMin; i <= XMax; i++) - { - //pRegion[GlobelWidth * pPointList[startp].y_ + i] = 1; - - //ԭԽ ܿ޸ - if (pPointList[startp].y_ > -1 && pPointList[startp].y_ < GlobelHeight && i > -1 && i < GlobelWidth) - { - pRegion[GlobelWidth * pPointList[startp].y_ + i] = 1; - } - } - } - } - } - - // ޸ıǷʽ Ե־Ϊ0 - for (int i = 0; i < GlobelHeight; i++) - { - for (int j = 0; j < GlobelWidth; j++) - { - if (pRegion[GlobelWidth * i + j] == 0) - { - pRegion[GlobelWidth * i + j] = 1; - } - else - { - pRegion[GlobelWidth * i + j] = 0; - } - } - } - - sy_point StartPoint; - int SumX = 0; - int SumY = 0; - for (int k = 0; k < num; k++) - { - SumX = SumX + pPointList[k].x_; - SumY = SumY + pPointList[k].y_; - } - StartPoint.x_ = SumX / num; - StartPoint.y_ = SumY / num; - - bool *pMaskMap = new bool[GlobelWidth * GlobelHeight]; - bool *pMaskMapS = new bool[GlobelWidth * GlobelHeight]; - memset(pMaskMap, 0, sizeof(bool) * GlobelWidth * GlobelHeight); - memset(pMaskMapS, 0, sizeof(bool) * GlobelWidth * GlobelHeight); - pMaskMap[GlobelWidth * StartPoint.y_ + StartPoint.x_] = 1; - - int msum = 1; - while (msum != 0) - { - msum = 0; - for (int i = 0; i < GlobelHeight; i++) - { - for (int j = 0; j < GlobelWidth; j++) - { - msum = msum + pMaskMap[GlobelWidth * i + j] - pMaskMapS[GlobelWidth * i + j]; - pMaskMapS[GlobelWidth * i + j] = pMaskMap[GlobelWidth * i + j]; - } - } - for (int i = 0; i < GlobelHeight; i++) - { - for (int j = 0; j < GlobelWidth; j++) - { - if ((i <= 0) || (i >= GlobelHeight - 1) || (j <= 0) || (j >= GlobelWidth - 1)) - { - continue; - } - - if (pMaskMapS[GlobelWidth * i + j] == 1) - { - pMaskMap[GlobelWidth * i + j + 1] = 1; - pMaskMap[GlobelWidth * i + j - 1] = 1; - pMaskMap[GlobelWidth * (i + 1) + j] = 1; - pMaskMap[GlobelWidth * (i - 1) + j] = 1; - } - } - } - for (int i = 0; i < GlobelHeight; i++) - { - for (int j = 0; j < GlobelWidth; j++) - { - pMaskMap[GlobelWidth * i + j] = pMaskMap[GlobelWidth * i + j] && pRegion[GlobelWidth * i + j]; - } - } - } - - memcpy(pRegion, pMaskMap, sizeof(bool) * GlobelWidth * GlobelHeight); - - delete[] pMaskMap; - delete[] pMaskMapS; - } -} - -/****************************************************************************** -* Function: RSRegion -* Description: Ȥ -* Calls: vibeMask -* Called By: main -* Input: numROI ROI -pRegionInfo ROI -iflog true:־ false־ -* Output: pRegion 10ROIָ루boolÿСΪͼ*ͼߣȤֵΪ1 Ϊ0 -//regionAlarm 10ROI ־bool -pAlarmInfo 10ROI ־int -* Return: 3 1 -*******************************************************************************/ -void IRegionSurveillanceBase::printAlarmType(std::fstream *file, int style) -{ - switch (style) - { - case 1: - *file << ", "; - break; - case 2: - *file << "뿪, "; - break; - case 3: - *file << "Խ, "; - break; - case 4: - *file << "˫Խ, "; - break; - case 5: - *file << "ǻ, "; - break; - case 6: - *file << ", "; - break; - default: - break; - } -} - -void IRegionSurveillanceBase::AddTaskTracker(const int taskID, const double rWidth, const double rHeight) -{ - taskTrackers.TaskID = taskID; - taskTrackers.ratioWidth = rWidth; - taskTrackers.ratioHeight = rHeight; -} - -void IRegionSurveillanceBase::AccessToRestrictedAreas(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) // -{ - - // ֻҪĿӾһ򱨾 - for (int ii = 0; ii < m_numROI; ii++) // - { - for (int i = 0; i < vptResult.objCount; ++i) //Ŀ - { - if (pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x] && \ - pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x + 1] && \ - pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x - 1] && \ - pRegion[ii][GlobelWidth * (vptResult.obj[i].center_y + 1) + vptResult.obj[i].center_x] && \ - pRegion[ii][GlobelWidth * (vptResult.obj[i].center_y - 1) + vptResult.obj[i].center_x]) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 1; - } - - } - } - return; -} - -void IRegionSurveillanceBase::LeaveTheRestrictedAreas(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //뿪 -{ - for (int ii = 0; ii < m_numROI; ii++) // - { - for (int i = 0; i < vptResult.objCount; ++i) //Ŀ - { - int tar_size = result->obj_infos[i].trace.trace_num; - if (tar_size > 4) - { - sy_point PredictionPoint; - PredictionPoint.x_ = vptResult.obj[i].center_x - result->obj_infos[i].trace.obj_trace[tar_size - 4].x_ + vptResult.obj[i].center_x; - PredictionPoint.y_ = vptResult.obj[i].center_y - result->obj_infos[i].trace.obj_trace[tar_size - 4].y_ + vptResult.obj[i].center_y; - if (pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].left] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].left] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].right] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].right]) - { - if (pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x] == false && - pRegion[ii][GlobelWidth * PredictionPoint.y_ + PredictionPoint.x_] == false) - { - bool flag = 0; - int j; - - j = tar_size - 1; - while (j >= 0 && j >= tar_size - (vptResult.obj[i].right - vptResult.obj[i].left) / 2) - { - if (pRegion[ii][GlobelWidth * (int)(result->obj_infos[i].trace.obj_trace[j].y_) + (result->obj_infos[i].trace.obj_trace[j].x_)]) - { - flag = 1; - break; - } - - j--; - } - if (flag == 1) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 2; - return; - } - } - - - } - } - - - - } - } - return; -} - -void IRegionSurveillanceBase::OneWayCrossBorder(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //Խ -{ - for (int ii = 0; ii < m_numROI; ii++) // - { - for (int i = 0; i < vptResult.objCount; ++i) //Ŀ - { - int tar_size = result->obj_infos[i].trace.trace_num; - for (int iy = vptResult.obj[i].top; iy <= vptResult.obj[i].bottom; iy++) - { - for (int ix = vptResult.obj[i].left; ix <= vptResult.obj[i].right; ix++) - { - if (pRegion[ii][GlobelWidth * iy + ix] && tar_size >= 4) - { - int point_x, point_y; - point_x = result->obj_infos[i].trace.obj_trace[tar_size - 4].x_; - point_y = result->obj_infos[i].trace.obj_trace[tar_size - 4].y_; - if (ii >= 0 && ii < m_numROI && region_infos[ii].point_num >= 2) - { - if (abs(region_infos[ii].p_roi[0].x_ - region_infos[ii].p_roi[1].x_) >= 1) - { - double k, b; - k = (double)(region_infos[ii].p_roi[0].y_ - region_infos[ii].p_roi[1].y_) / (region_infos[ii].p_roi[0].x_ - region_infos[ii].p_roi[1].x_); - b = (double)(region_infos[ii].p_roi[0].x_ * region_infos[ii].p_roi[1].y_ - region_infos[ii].p_roi[1].x_ * region_infos[ii].p_roi[0].y_) / - (region_infos[ii].p_roi[0].x_ - region_infos[ii].p_roi[1].x_); - - double dist_c, dist_p; - - dist_c = fabs(k * result->obj_infos[i].trace.obj_trace[tar_size - 1].x_ - result->obj_infos[i].trace.obj_trace[tar_size - 1].y_ + b) / sqrt(k * k + 1.0); - dist_p = fabs(k * point_x - point_y + b) / sqrt(k * k + 1.0); - - if (abs(dist_c - dist_p) < 10) - { - int pre_index = tar_size - 5; - while (pre_index >= 0) - { - point_x = result->obj_infos[i].trace.obj_trace[pre_index].x_; - point_y = result->obj_infos[i].trace.obj_trace[pre_index].y_; - dist_p = fabs(k * point_x - point_y + b) / sqrt(k * k + 1.0); - pre_index = pre_index - 1; - if (abs(dist_c - dist_p) >= 10) - { - break; - } - } - } - - - if (abs(dist_c - dist_p) < 10) - { - result->obj_infos[i].pb_alarm_state[ii] = false; - result->obj_infos[i].pb_alarm_type[ii] = 0; - return; - } - - bool flag_c, flag_p; - if (k * result->obj_infos[i].trace.obj_trace[tar_size - 1].x_ + b >= result->obj_infos[i].trace.obj_trace[tar_size - 1].y_) - { - flag_c = 1; - } - else - { - flag_c = 0; - } - - if (k *point_x + b >= point_y) - { - flag_p = 1; - } - else - { - flag_p = 0; - } - - - //if (region_infos[ii].dir == 1) - if (region_infos[ii].finaldir == 1) //by zl 20150914 - { - if (flag_c * flag_p == 1) - { - if (dist_c <= dist_p) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - } - else if (flag_c == 0 && flag_p == 1) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - else if (flag_c == 0 && flag_p == 0) - { - if (dist_p <= dist_c) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - } - - } - else - { - if (flag_c == 0 && flag_p == 0) - { - if (dist_c <= dist_p) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - } - else if (flag_c == 1 && flag_p == 0) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - else if (flag_c == 1 && flag_p == 1) - { - if (dist_p <= dist_c) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - } - } - } - else - { - double k, b; - k = 0; - b = (double)(region_infos[ii].p_roi[0].x_); - - double dist_c, dist_p; - - dist_c = fabs(result->obj_infos[i].trace.obj_trace[tar_size - 1].x_ - b); - dist_p = fabs(point_x - b); - - if (abs(dist_c - dist_p) < 10) - { - int pre_index = tar_size - 5; - while (pre_index >= 0) - { - point_x = result->obj_infos[i].trace.obj_trace[pre_index].x_; - dist_p = fabs(point_x - b); - pre_index = pre_index - 1; - if (abs(dist_c - dist_p) >= 10) - { - break; - } - } - } - - bool flag_c, flag_p; - if (result->obj_infos[i].trace.obj_trace[tar_size - 1].x_ >= b) - { - flag_c = 1; - } - else - { - flag_c = 0; - } - - if (point_x >= b) - { - flag_p = 1; - } - else - { - flag_p = 0; - } - - if (abs(dist_c - dist_p) < 10) - { - result->obj_infos[i].pb_alarm_state[ii] = false; - result->obj_infos[i].pb_alarm_type[ii] = 0; - return; - } - //if (region_infos[ii].dir == 1) - if (region_infos[ii].finaldir == 1) //by zl 20150914 - { - if (flag_c * flag_p == 1) - { - if (dist_c <= dist_p) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - } - else if (flag_c == 0 && flag_p == 1) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - else if (flag_c == 0 && flag_p == 0) - { - if (dist_p <= dist_c) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - } - - } - else - { - if (flag_c == 0 && flag_p == 0) - { - if (dist_c <= dist_p) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - } - else if (flag_c == 1 && flag_p == 0) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - else if (flag_c == 1 && flag_p == 1) - { - if (dist_p <= dist_c) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 3; - return; - } - } - } - - - } - } - } - } - } - } - } - return; -} - -void IRegionSurveillanceBase::TwoWayCrossBorder(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //˫Խ -{ - // ֻҪĿӾһ򱨾 - for (int ii = 0; ii < m_numROI; ii++) // - { - for (int i = 0; i < vptResult.objCount; ++i) //Ŀ - { - for (int iy = vptResult.obj[i].top; iy <= vptResult.obj[i].bottom; iy++) - { - for (int ix = vptResult.obj[i].left; ix <= vptResult.obj[i].right; ix++) - { - if (pRegion[ii][GlobelWidth * iy + ix]) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 4; - } - } - } - } - } - return; -} - -void IRegionSurveillanceBase::WanderMonitoring(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //ǻ -{ - for (int ii = 0; ii < m_numROI; ii++) // - { - for (int i = 0; i < vptResult.objCount; ++i) //Ŀ - { - bool flag = 0; - if ((pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].left] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].left] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].right] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].right]) && (pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x])) - { - if (mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr == 0) - { - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr = 1; - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0; - } - else - { - if (mp_stayinfo[ii][vptResult.obj[i].id].lastFrame <= 5) - { - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr++; - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0; - } - else - { - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr = 0; - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0; - - } - } - if (mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr >= region_infos[ii].frame_num) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 5; - flag = 1; - } - - } - if (flag == 0) - { - result->obj_infos[i].pb_alarm_state[ii] = false; - result->obj_infos[i].pb_alarm_type[ii] = 0; - - } - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame++; - } - } - return; -} - -void IRegionSurveillanceBase::StayMonitoring(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) // -{ - for (int ii = 0; ii < m_numROI; ii++) // - { - for (int i = 0; i < vptResult.objCount; ++i) //Ŀ - { - int tar_size = result->obj_infos[i].trace.trace_num; - int cur_dis; - bool flag = 0; - if (pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].left] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].left] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].right] || \ - pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].right]) - { - if (pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x]) - { - if (mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr == 0) - { - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr = 1; - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0; - } - else - { - if (tar_size >= 2) - { - cur_dis = (result->obj_infos[i].trace.obj_trace[tar_size - 1].x_ - result->obj_infos[i].trace.obj_trace[tar_size - 2].x_)*(result->obj_infos[i].trace.obj_trace[tar_size - 1].x_ - result->obj_infos[i].trace.obj_trace[tar_size - 2].x_) + - (result->obj_infos[i].trace.obj_trace[tar_size - 1].y_ - result->obj_infos[i].trace.obj_trace[tar_size - 2].y_)*(result->obj_infos[i].trace.obj_trace[tar_size - 1].y_ - result->obj_infos[i].trace.obj_trace[tar_size - 2].y_); - } - else - { - cur_dis = 0; - } - if (mp_stayinfo[ii][vptResult.obj[i].id].lastFrame <= 5 && cur_dis <= tar_size * tar_size) - { - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr++; - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0; - } - else - { - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr = 0; - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0; - } - } - if (mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr >= region_infos[ii].frame_num) - { - result->obj_infos[i].pb_alarm_state[ii] = true; - result->obj_infos[i].pb_alarm_type[ii] = 6; - } - } - } - if (flag == 0) - { - result->obj_infos[i].pb_alarm_state[ii] = false; - result->obj_infos[i].pb_alarm_type[ii] = 0; - } - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame++; - } - } - return; -} - -int IRegionSurveillanceBase::rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result) -{ - - VPT_Result vptResult; - - detect(img_data, vptResult); - for (int i = 0; i < vptResult.objCount; i++) //¹켣 - { - bool matching = false; - for (auto &item : vec_traceinfo) - { - if (item.id == vptResult.obj[i].id) - { - if (item.num < MAXTRACENUM) - { - ++item.num; - sy_point point; - point.x_ = vptResult.obj[i].center_x; - point.y_ = vptResult.obj[i].center_y; - item.trace_obj.push_back(point); - } - else - { - sy_point point; - point.x_ = vptResult.obj[i].center_x; - point.y_ = vptResult.obj[i].center_y; - item.trace_obj.push_back(point); - item.trace_obj.pop_front(); - } - matching = true; - } - } - if (matching == false) - { - TraceInfo traceinf; - traceinf.id = vptResult.obj[i].id; - traceinf.num = 1; - sy_point point; - point.x_ = vptResult.obj[i].center_x; - point.y_ = vptResult.obj[i].center_y; - traceinf.trace_obj.push_back(point); - vec_traceinfo.push_back(traceinf); - } - } - - - result->obj_count = vptResult.objCount; - for (int i = 0; i < result->obj_count; i++) - { - memset(result->obj_infos[i].pb_alarm_state, 0, MAXROINUM * sizeof(bool)); - memset(result->obj_infos[i].pb_alarm_type, 0, MAXROINUM * sizeof(int)); - result->obj_infos[i].tar_box.left_ = vptResult.obj[i].left; - result->obj_infos[i].tar_box.top_ = vptResult.obj[i].top; - result->obj_infos[i].tar_box.width_ = vptResult.obj[i].right - vptResult.obj[i].left; - result->obj_infos[i].tar_box.height_ = vptResult.obj[i].bottom - vptResult.obj[i].top; - - result->obj_infos[i].curPos.x_ = vptResult.obj[i].center_x; - result->obj_infos[i].curPos.y_ = vptResult.obj[i].center_y; - result->obj_infos[i].unique_id = vptResult.obj[i].id; - for (auto &item : vec_traceinfo) - { - if (item.id == vptResult.obj[i].id) - { - result->obj_infos[i].trace.trace_num = item.num; - for (int j = 0; j < item.num; ++j) - { - result->obj_infos[i].trace.obj_trace[j] = item.trace_obj[j]; - } - } - } - - } - - for (int i = 0; i < m_numROI; i++) - { - // 1 2뿪 3Խ 4˫Խ 5ǻ 6 - switch (pAlarmInfo[i]) - { - case 1: - AccessToRestrictedAreas(vptResult, region_infos, result); // - break; - case 2: - LeaveTheRestrictedAreas(vptResult, region_infos, result); //뿪 - break; - case 3: - OneWayCrossBorder(vptResult, region_infos, result); //Խ - break; - case 4: - TwoWayCrossBorder(vptResult, region_infos, result); //˫Խ - break; - case 5: - WanderMonitoring(vptResult, region_infos, result); //ǻ - break; - case 6: - StayMonitoring(vptResult, region_infos, result); // - break; - default: - break; - } - - } - return 0; -} \ No newline at end of file diff --git a/src/left_over/MSRegionSurveilanceBase.h b/src/left_over/MSRegionSurveilanceBase.h deleted file mode 100644 index efea8c1..0000000 --- a/src/left_over/MSRegionSurveilanceBase.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once -#include "header.h" - -#include "RegionSurveillanceProcess.h" -#include -#include "Sort.h" -#include -#define MAX_OBJ_COUNT 100 -struct TaskTracker -{ - int TaskID; - double ratioWidth; - double ratioHeight; - Sort tracker; -}; - -typedef struct VPT_Result -{ - int objCount; - VPT_ObjInfo obj[MAX_OBJ_COUNT]; -}VPT_Result; - -class IRegionSurveillanceBase : public RegionSurveillanceProcess { -public: - IRegionSurveillanceBase(); - - // ģͳʼ - virtual int rs_init(const rs_param & param) override; - // ROIʼ - virtual int rs_init_region(int numROI, region_info* region_infos, bool iflog) override; - //// ÿһ֡ͼ - int rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result)override; - ////㷽ͼͷƵ˵ - virtual int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) override; -protected: - void vibeMask(int num, sy_point *pPointList, bool *pRegion); - void printAlarmType(std::fstream *file, int style); - void AddTaskTracker(const int taskID, const double rWidth, const double rHeight); -/*************************************************************************************************/ - void AccessToRestrictedAreas(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); // - void LeaveTheRestrictedAreas(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //뿪 - void OneWayCrossBorder(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //Խ - void TwoWayCrossBorder(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //˫Խ - void WanderMonitoring(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //ǻ - void StayMonitoring(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); // -/**********************************************************************************************************/ - virtual int init(const rs_param & param) = 0; //صʼģ - virtual int detect(const sy_img &img_data, VPT_Result & vptResult) = 0; //صȡ˳⣬ͷϢ //ص˳ͷ - virtual void release() = 0; //صͷ -private: - - void RSrelease(); -protected: - struct TraceInfo - { - unsigned int id; //ĿΨһid - unsigned int num; //Ŀ켣 - std::deque trace_obj; //Ŀ켣㼯 - }; - std::vector vec_traceinfo; - struct StayInfo - { - long nFrameCurr; // ¼ǰ֡ - int lastFrame; // ϴμ⵽뵱ǰ֡ - }; - std::map> mp_stayinfo; // ĿΨһid, Ŀ궺֡ - int GlobelWidth = 0; - int GlobelHeight = 0; - TaskTracker taskTrackers; - sy_point pStart, pEnd; //by zl ڴ洢ͨзͷ˵ - int m_numROI = 0; - bool** pRegion; - int* pAlarmInfo; -private: - - -}; diff --git a/src/left_over/MSRegionSurveilanceCpu.cpp b/src/left_over/MSRegionSurveilanceCpu.cpp index ffd4e1c..f589bde 100644 --- a/src/left_over/MSRegionSurveilanceCpu.cpp +++ b/src/left_over/MSRegionSurveilanceCpu.cpp @@ -1,9 +1,42 @@ #include "MSRegionSurveilanceCpu.h" #include "head.h" +#include +#include +#include +#include + +bool Screenshot(IplImage* src, IplImage* dst, sy_rect t) +{ + + CvRect rect; + rect.x = t.left_; + rect.y = t.top_; + rect.width = t.width_; + rect.height = t.height_; + cvSetImageROI(src, rect); + cvCopy(src, dst, 0); + cvResetImageROI(src); + //cvNamedWindow("Image", 1);// + //cvShowImage("Image", dst);//ʾͼ + //cvWaitKey(0); //ȴ + return 0; +} int IRegionSurveillanceCpu::rs_init(const rs_params ¶m) { - return IReginCpu->RSinit(param.image.w_, param.image.h_, param.image.w_, - (unsigned char*)(param.image.data_), 1/*param.image.c_*/, 1/*param.channel_deal*/, param.filt_flag, param.min_area, param.max_area); + int r = 0; + IplImage * gray = cvCreateImage(cvSize(param.image.w_, param.image.h_), 8, 1); + cvSetData(gray, param.image.data_, param.image.w_); + for (int i = 0; i < rect_num; ++i) + { + IplImage * img = cvCreateImage(cvSize(rect[i].width_, rect[i].height_), 8, 1); + Screenshot(gray, img, rect[i]); + //cv::Mat roi_img = cv::src_img(Range(0, 100), Range(50, 200)); + r = IReginCpu[i]->RSinit(img->width, img->height, img->width, + (unsigned char*)(img->imageData), 1/*param.image.c_*/, 1/*param.channel_deal*/, param.filt_flag, param.min_area, param.max_area); + cvReleaseImage(&img); + } + //cvReleaseImage(&gray); + return r; } int IRegionSurveillanceCpu::rs_init_region(int num_roi, region_info* region_infos/*, bool iflog*/) { @@ -24,7 +57,12 @@ int IRegionSurveillanceCpu::rs_init_region(int num_roi, region_info* region_info //reginifos.ArrowStartPoint.y = region_infos->arrow_start_point.y_; //reginifos.ArrowEndPoint.x = region_infos->arrow_end_point.x_; //ͷֹ˵ ͷָ //reginifos.ArrowEndPoint.y = region_infos->arrow_end_point.y_; //ͷֹ˵ ͷָ - return IReginCpu->RSRegion(num_roi, region_infos->alarm_info/*, iflog*/); + int r = 0; + for (int i = 0; i < rect_num; ++i) + { + r = IReginCpu[i]->RSRegion(num_roi, region_infos->alarm_info/*, iflog*/); + } + return r; } int IRegionSurveillanceCpu::rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result) { @@ -45,75 +83,93 @@ int IRegionSurveillanceCpu::rs_detect(const sy_img &img_data, region_info* regio //reginifos.ArrowStartPoint.y = region_infos->arrow_start_point.y_; //reginifos.ArrowEndPoint.x = region_infos->arrow_end_point.x_; //ͷֹ˵ ͷָ //reginifos.ArrowEndPoint.y = region_infos->arrow_end_point.y_; //ͷֹ˵ ͷָ - IReginCpu->RSDetect((unsigned char*)(img_data.data_), ®inifos); - auto ObjCount = IReginCpu->getObjectNum(); - result->obj_count = ObjCount; - auto * ObjInfo = new MS_ObjectInfo[ObjCount]; - IReginCpu->getObjectInfo(ObjCount, ObjInfo); - for (int i = 0; i < ObjCount; ++i) - { - result->obj_infos[i].curPos.x_ = ObjInfo[i].curPos.x; // ǰ - result->obj_infos[i].curPos.y_ = ObjInfo[i].curPos.y; // ǰ - result->obj_infos[i].trace.trace_num = ObjInfo[i].trace.nTraceNum; // 켣״̬ - for (int j = 0; j < MAXTRACENUM; ++j) - { - result->obj_infos[i].trace.obj_trace[j].x_ = ObjInfo[i].trace.pObjTrace[j].x; - result->obj_infos[i].trace.obj_trace[j].y_ = ObjInfo[i].trace.pObjTrace[j].y; - } - result->obj_infos[i].unique_id = ObjInfo[i].UniqueID; // ǰĿصID - result->obj_infos[i].tar_box.left_ = ObjInfo[i].TarBox.left; // ĿӾ - result->obj_infos[i].tar_box.top_ = ObjInfo[i].TarBox.top; - result->obj_infos[i].tar_box.height_ = ObjInfo[i].TarBox.Height(); - result->obj_infos[i].tar_box.width_ = ObjInfo[i].TarBox.Width(); - for (int j = 0; j < MAXROINUM; ++j) - { - result->obj_infos[i].pb_alarm_state[j] = ObjInfo[i].pbAlarmState[j]; - result->obj_infos[i].pb_alarm_type[j] = ObjInfo[i].pbAlarmType[j]; - } - } - delete ObjInfo; - auto delCount = IReginCpu->getDeleteNum(); - result->del_count = delCount; - auto * DelInfo = new MS_ObjectInfo[delCount]; - IReginCpu->getDeleteInfo(delCount, DelInfo); - for (int i = 0; i < delCount; ++i) + int totalObjCount = 0; + int totalDelCount = 0; + IplImage * gray = cvCreateImage(cvSize(img_data.w_, img_data.h_), 8, 1); + cvSetData(gray, img_data.data_, img_data.w_); + for (int k = 0; k < rect_num; ++k) + //int k = 0; { - result->del_infos[i].curPos.x_ = DelInfo[i].curPos.x; // ǰ - result->del_infos[i].curPos.y_ = DelInfo[i].curPos.y; // ǰ + IplImage * img = cvCreateImage(cvSize(rect[k].width_, rect[k].height_), 8, 1); + Screenshot(gray, img, rect[k]); + //cv::Mat roi_img = cv::src_img(Range(0, 100), Range(50, 200)); + IReginCpu[k]->RSDetect((unsigned char*)(img->imageData), ®inifos); + auto ObjCount = IReginCpu[k]->getObjectNum(); - result->del_infos[i].trace.trace_num = DelInfo[i].trace.nTraceNum; // 켣״̬ - for (int j = 0; j < MAXTRACENUM; ++j) + auto * ObjInfo = new MS_ObjectInfo[ObjCount]; + IReginCpu[k]->getObjectInfo(ObjCount, ObjInfo); + for (int i = 0; i < ObjCount; ++i) { - result->del_infos[i].trace.obj_trace[j].x_ = DelInfo[i].trace.pObjTrace[j].x; - result->del_infos[i].trace.obj_trace[j].y_ = DelInfo[i].trace.pObjTrace[j].y; + 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].trace.trace_num = ObjInfo[i].trace.nTraceNum; // 켣״̬ + for (int j = 0; j < MAXTRACENUM; ++j) + { + result->obj_infos[totalObjCount].trace.obj_trace[j].x_ = ObjInfo[i].trace.pObjTrace[j].x+rect[k].left_; + result->obj_infos[totalObjCount].trace.obj_trace[j].y_ = ObjInfo[i].trace.pObjTrace[j].y+rect[k].top_; + } + + result->obj_infos[totalObjCount].unique_id = ObjInfo[i].UniqueID; // ǰĿصID + result->obj_infos[totalObjCount].tar_box.left_ = ObjInfo[i].TarBox.left+rect[k].left_; // ĿӾ + result->obj_infos[totalObjCount].tar_box.top_ = ObjInfo[i].TarBox.top+rect[k].top_; + result->obj_infos[totalObjCount].tar_box.height_ = ObjInfo[i].TarBox.Height(); + result->obj_infos[totalObjCount].tar_box.width_ = ObjInfo[i].TarBox.Width(); + for (int j = 0; j < MAXROINUM; ++j) + { + result->obj_infos[totalObjCount].pb_alarm_state[j] = ObjInfo[i].pbAlarmState[j]; + result->obj_infos[totalObjCount].pb_alarm_type[j] = ObjInfo[i].pbAlarmType[j]; + } + ++totalObjCount; } + + delete ObjInfo; + auto delCount = IReginCpu[k]->getDeleteNum(); - result->del_infos[i].unique_id = DelInfo[i].UniqueID; // ǰĿصID - result->del_infos[i].tar_box.left_ = DelInfo[i].TarBox.left; // ĿӾ - result->del_infos[i].tar_box.top_ = DelInfo[i].TarBox.top; - result->del_infos[i].tar_box.height_ = DelInfo[i].TarBox.Height(); - result->del_infos[i].tar_box.width_ = DelInfo[i].TarBox.Width(); - for (int j = 0; j < MAXROINUM; ++j) + auto * DelInfo = new MS_ObjectInfo[delCount]; + IReginCpu[k]->getDeleteInfo(delCount, DelInfo); + for (int i = 0; i < delCount; ++i) { - result->del_infos[i].pb_alarm_state[j] = DelInfo[i].pbAlarmState[j]; - result->del_infos[i].pb_alarm_type[j] = DelInfo[i].pbAlarmType[j]; + 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].trace.trace_num = DelInfo[i].trace.nTraceNum; // 켣״̬ + for (int j = 0; j < MAXTRACENUM; ++j) + { + result->del_infos[totalDelCount].trace.obj_trace[j].x_ = DelInfo[i].trace.pObjTrace[j].x + rect[k].left_; + result->del_infos[totalDelCount].trace.obj_trace[j].y_ = DelInfo[i].trace.pObjTrace[j].y + rect[k].top_; + } + + result->del_infos[totalDelCount].unique_id = DelInfo[i].UniqueID; // ǰĿصID + result->del_infos[totalDelCount].tar_box.left_ = DelInfo[i].TarBox.left + rect[k].left_; // ĿӾ + result->del_infos[totalDelCount].tar_box.top_ = DelInfo[i].TarBox.top + rect[k].top_; + result->del_infos[totalDelCount].tar_box.height_ = DelInfo[i].TarBox.Height(); + result->del_infos[totalDelCount].tar_box.width_ = DelInfo[i].TarBox.Width(); + for (int j = 0; j < MAXROINUM; ++j) + { + result->del_infos[totalDelCount].pb_alarm_state[j] = DelInfo[i].pbAlarmState[j]; + result->del_infos[totalDelCount].pb_alarm_type[j] = DelInfo[i].pbAlarmType[j]; + } + ++totalDelCount; } + delete DelInfo; } - delete DelInfo; + result->obj_count = totalObjCount; + result->del_count = totalDelCount; return 1; } -int IRegionSurveillanceCpu::rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) -{ - CMPoint pROI0; - pROI0.x = p_roi0.x_; - pROI0.y = p_roi0.y_; - CMPoint pROI1; - pROI1.x = p_roi1.x_; - pROI1.y = p_roi1.y_; - CMPoint pdir; - pdir.x = dir.x_; - pdir.y = dir.y_; - return IReginCpu->get_ArrowDir(pROI0, pROI1, pdir); -} \ No newline at end of file +//int IRegionSurveillanceCpu::rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) +//{ +// CMPoint pROI0; +// pROI0.x = p_roi0.x_; +// pROI0.y = p_roi0.y_; +// CMPoint pROI1; +// pROI1.x = p_roi1.x_; +// pROI1.y = p_roi1.y_; +// CMPoint pdir; +// pdir.x = dir.x_; +// pdir.y = dir.y_; +// return IReginCpu->get_ArrowDir(pROI0, pROI1, pdir); +//} \ No newline at end of file diff --git a/src/left_over/MSRegionSurveilanceCpu.h b/src/left_over/MSRegionSurveilanceCpu.h index 9c1f9d2..3d45868 100644 --- a/src/left_over/MSRegionSurveilanceCpu.h +++ b/src/left_over/MSRegionSurveilanceCpu.h @@ -7,18 +7,26 @@ class IRegionSurveillanceCpu: public RegionSurveillanceProcess { public: IRegionSurveillanceCpu() { - IReginCpu = MS1.GetMS_RS(); + for(int i = 0; i < MAXVERTEXNUM; ++i ) + IReginCpu[i] = MS1.GetMS_RS(); }; ~IRegionSurveillanceCpu() { - IReginCpu->RSrelease(); - MS1.Destroy(); + for (int i = 0; i < MAXVERTEXNUM; ++i) + { + IReginCpu[i]->RSrelease(); + delete IReginCpu[i]; + } + + //MS1.Destroy(); }; int rs_init(const rs_params ¶m); int rs_init_region(int num_roi, region_info* region_infos/*, bool iflog*/); int rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result); - int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir); + //int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir); private: MS_RegionSurveillance MS1; - IRegionSurveillance * IReginCpu; + IRegionSurveillance * IReginCpu[MAXVERTEXNUM]; + + }; \ No newline at end of file diff --git a/src/left_over/MSRegionSurveilanceHst.cpp b/src/left_over/MSRegionSurveilanceHst.cpp deleted file mode 100644 index babf1e8..0000000 --- a/src/left_over/MSRegionSurveilanceHst.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "MSRegionSurveilanceHst.h" -#include "head_shoulder_det.h" -#include "sy_errorinfo.h" -#include -#include - - -int IRegionSurveillanceHst::init(const rs_param & param) -{ - hs_det_param hsparam; - hsparam.gpuid = 0; - hsparam.mode = DEVICE_GPU; - hsparam.thresld = 0.5; - hsparam.engine = ENGINE_MCAFFE2; - hsparam.max_batch = 10; - hsparam.trt_serialize_file = "HSD"; - if (hs_det_init(&hst_handle, &hsparam)) - { - printf("hs_det_init failed!\n"); - return VPT_DET_INIT_ERROR; - } - printf("finish init hst\n"); - AddTaskTracker(0, 1, 1); - return 0; -} - -int IRegionSurveillanceHst::detect(const sy_img &img_data, VPT_Result & vptResult) -{ - vector deleteObjectID; - hs_det_result * hsresult = new hs_det_result{}; - hsresult->objcount = 0; - sy_img batch_img_gpu; - unsigned char * data = NULL; - cudaMalloc(&data, img_data.w_ *img_data.h_*img_data.c_ * sizeof(unsigned char)); - cudaMemcpy(data, img_data.data_, img_data.w_ *img_data.h_ * img_data.c_ * sizeof(unsigned char), cudaMemcpyHostToDevice); - batch_img_gpu.set_data(img_data.w_, img_data.h_, img_data.c_, data); - auto ret = hs_det_process_batch(hst_handle, &batch_img_gpu, 1, hsresult); - cudaFree(data); - std::vector> detectResult; - for (int c = 0; c < hsresult->objcount&& c < MAX_OBJ_COUNT; c++) - { - vector obj; - - obj.push_back(hsresult->objinfo[c].left); - obj.push_back(hsresult->objinfo[c].top); - obj.push_back(hsresult->objinfo[c].right); - obj.push_back(hsresult->objinfo[c].bottom); - obj.push_back(hsresult->objinfo[c].confidence); - obj.push_back(0); - detectResult.push_back(obj); - } - - int objCount = taskTrackers.tracker.update(/*tools->param.w*/img_data.w_* taskTrackers.ratioWidth, /*tools->param.h*/img_data.h_* taskTrackers.ratioHeight, true, detectResult, vptResult.obj, deleteObjectID); - vptResult.objCount = objCount; - delete hsresult; - return ret; -} - -void IRegionSurveillanceHst::release() -{ - //1.VPT RELEASE - if (hst_handle) - { - hs_det_release(&hst_handle); - hst_handle = NULL; - } -} \ No newline at end of file diff --git a/src/left_over/MSRegionSurveilanceHst.h b/src/left_over/MSRegionSurveilanceHst.h deleted file mode 100644 index 90d7587..0000000 --- a/src/left_over/MSRegionSurveilanceHst.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "MSRegionSurveilanceBase.h" - - -class IRegionSurveillanceHst : public IRegionSurveillanceBase { -public: - - -private: - - virtual int init(const rs_param & param) override; - virtual int detect(const sy_img &img_data, VPT_Result & vptResult) override; - virtual void release() override; - -private: - void * hst_handle; - - -}; diff --git a/src/left_over/MSRegionSurveilanceVpt.cpp b/src/left_over/MSRegionSurveilanceVpt.cpp deleted file mode 100644 index 4a88df3..0000000 --- a/src/left_over/MSRegionSurveilanceVpt.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "MSRegionSurveilanceVpt.h" -#include "vpt.h" -#include "sy_errorinfo.h" -#include -#include - - - - - - - - -int IRegionSurveillanceVpt::init(const rs_param & param) -{ - vpt_param vptparam; - vptparam.mode = DEVICE_GPU; - vptparam.gpuid = 0; - vptparam.threshold = 0.6; - vptparam.engine = ENGINE_TENSORRT; - vptparam.preprocess_param = - "CopyData_CPU2GPU_U8;" - "TypeConvert_U8_F32;" - "ResizePad_F32_F32,test_size,720,test_max_size,1280,fpn_coarsest_stride,32," - "submean_b,103.94,submean_g,116.78,submean_r,123.68," - "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" - "NHWC2NCHW_F32" - ; - vptparam.serialize_file = "FPN_VPT"; - vptparam.max_batch = 20; - if (vpt_init(&vpt_handle, vptparam) != 0) - { - printf("vpt_init failed!\n"); - return VPT_DET_INIT_ERROR; - } - printf("finish init vpt\n"); - AddTaskTracker(0, 1, 1); - return 0; -} - - - - - - -int IRegionSurveillanceVpt::detect(const sy_img &img_data, VPT_Result & vptResult) -{ - vector deleteObjectID; - vpt_result * vptresult = new vpt_result{}; - vptresult->obj_count_ = 0; - vptresult->obj_results_ = new vpt_obj_result[MAX_DET_COUNT]; - sy_img batch_img_gpu; - unsigned char * data = NULL; - cudaMalloc(&data, img_data.w_ *img_data.h_*img_data.c_ * sizeof(unsigned char)); - cudaMemcpy(data, img_data.data_, img_data.w_ *img_data.h_ * img_data.c_ * sizeof(unsigned char), cudaMemcpyHostToDevice); - batch_img_gpu.set_data(img_data.w_, img_data.h_, img_data.c_, data); - auto ret = vpt_batch(vpt_handle, &batch_img_gpu, 1, &vptresult); - cudaFree(data); - std::vector> detectResult; - for (int c = 0; c < vptresult->obj_count_&& c < MAX_OBJ_COUNT; c++) - { - vector obj; - - obj.push_back(vptresult->obj_results_[c].obj_rect.left_); - obj.push_back(vptresult->obj_results_[c].obj_rect.top_); - obj.push_back(vptresult->obj_results_[c].obj_rect.left_ + vptresult->obj_results_[c].obj_rect.width_); - obj.push_back(vptresult->obj_results_[c].obj_rect.top_ + vptresult->obj_results_[c].obj_rect.height_); - obj.push_back(vptresult->obj_results_[c].obj_score); - obj.push_back(vptresult->obj_results_[c].obj_index); - detectResult.push_back(obj); - } - - int objCount = taskTrackers.tracker.update(/*tools->param.w*/img_data.w_* taskTrackers.ratioWidth, /*tools->param.h*/img_data.h_* taskTrackers.ratioHeight, true, detectResult, vptResult.obj, deleteObjectID); - vptResult.objCount = objCount; - delete[] vptresult->obj_results_; - delete vptresult; - return ret; -} - - - - -void IRegionSurveillanceVpt::release() -{ - - //1.VPT RELEASE - if (vpt_handle) - { - vpt_release(&vpt_handle); - vpt_handle = NULL; - } - -} \ No newline at end of file diff --git a/src/left_over/MSRegionSurveilanceVpt.h b/src/left_over/MSRegionSurveilanceVpt.h deleted file mode 100644 index 2ce15af..0000000 --- a/src/left_over/MSRegionSurveilanceVpt.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "MSRegionSurveilanceBase.h" - - -class IRegionSurveillanceVpt : public IRegionSurveillanceBase { -public: - - -private: - virtual int detect(const sy_img &img_data, VPT_Result & vptResult) override; - virtual int init(const rs_param & param) override; - virtual void release() override; - -private: - void * vpt_handle; - - -}; diff --git a/src/left_over/RegionSurveillanceProcess.h b/src/left_over/RegionSurveillanceProcess.h index e9e0212..715ff88 100644 --- a/src/left_over/RegionSurveillanceProcess.h +++ b/src/left_over/RegionSurveillanceProcess.h @@ -35,17 +35,19 @@ public: virtual int rs_init(const rs_params ¶m) = 0; virtual int rs_init_region(int num_roi, region_info* region_infos/*, bool iflog*/) = 0; virtual int rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result) = 0; - virtual int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) = 0; + //virtual int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) = 0; void* handle; int licence_status = -1; int thrd_status = -1; - int long_side; - int short_side; + double scale; + //int long_side; + //int short_side; std::atomic thrd_run; boost::thread thrd; long frame_num = 0; bool init_flag = false; - double scale; + sy_rect rect[MAXVERTEXNUM]; //Ч + unsigned char rect_num; //Ч private: //int mode; //ģʽ0 cpu //MS_RegionSurveillance MS1; diff --git a/src/left_over/helper.cpp b/src/left_over/helper.cpp index f4746c4..d6ea0da 100644 --- a/src/left_over/helper.cpp +++ b/src/left_over/helper.cpp @@ -63,8 +63,8 @@ void RegionSurveillance::RandNeighborInit(int32_t width, int32_t height) { g_YTable[i + 1] = i; } - g_XTable[0] = 0; //1 - g_XTable[height + 1] = height - 1; + g_YTable[0] = 0; //1 + g_YTable[height + 1] = height - 1; } } @@ -72,13 +72,13 @@ void RegionSurveillance::GetRandNeighborXY(int32_t x, int32_t y, int32_t *_x, in { uint32_t r = GetRand() & 0x07; *_x = g_XTable[x + g_XNeighborTable[r]]; - *_y = g_XTable[y + g_YNeighborTable[r]]; + *_y = g_YTable[y + g_YNeighborTable[r]]; } void RegionSurveillance::GetNeighborXY(int32_t x, int32_t y, int32_t *_x, int32_t *_y, int32_t flag) { *_x = g_XTable[x + g_XNeighborTable[flag]]; - *_y = g_XTable[y + g_YNeighborTable[flag]]; + *_y = g_YTable[y + g_YNeighborTable[flag]]; } void RegionSurveillance::FreeRandNeighbor() diff --git a/src/left_over/left_over_det.h b/src/left_over/left_over_det.h index 2600b6a..775ce2f 100644 --- a/src/left_over/left_over_det.h +++ b/src/left_over/left_over_det.h @@ -24,8 +24,8 @@ #define m_BOUNDING_BOX_RATEMIN 0.001 #define m_BOUNDING_BOX_RATEMAX 100 #define MAXROINUM 10 // 最大ROI数 -//#define MACDETECTOBJNUM 100 -#define MACDETECTOBJNUM 3 +#define MACDETECTOBJNUM 10 + #ifdef __cplusplus extern "C" { @@ -33,14 +33,25 @@ extern "C" #ifndef __RS_PARAM__ #define __RS_PARAM__ - - +#ifndef __SY_RECT__ +#define __SY_RECT__ + typedef struct sy_rect + { + int left_; + int top_; + int width_; + int height_; + sy_rect(int m_left, int m_top, int m_width, int m_height) :left_(m_left), top_(m_top), width_(m_width), height_(m_height) {}; + sy_rect() {}; + } sy_rect; +#endif +#define MAXVERTEXNUM 10 typedef struct rs_param { long frame_num; // 逗留时间 单位帧数 - int long_side; - int short_side; - + double scale; //缩小比例 + sy_rect rect[MAXVERTEXNUM]; //有效区域 + unsigned char rect_num; //有效区域数量 }rs_param; #endif diff --git a/src/left_over/ms_region_surveilance.cpp b/src/left_over/ms_region_surveilance.cpp index 7ed0556..4eb903e 100644 --- a/src/left_over/ms_region_surveilance.cpp +++ b/src/left_over/ms_region_surveilance.cpp @@ -2,9 +2,10 @@ #include "RegionSurveillanceProcess.h" #include "MSRegionSurveilanceCpu.h" #include +#include #include #include "head.h" -#include "authority.h" +//#include "authority.h" #include "sy_errorinfo.h" #include #ifdef _MSC_VER @@ -16,100 +17,172 @@ -void check_thread(RegionSurveillanceProcess* handle) +//void check_thread(RegionSurveillanceProcess* handle) +//{ +// int res = -1; +//#ifdef __linux__ +// char* wtime = new char[15]; +// memset(wtime, 0, 15); +//#endif +// while (1) +// { +// //printf("xxx check status on process...\n"); +//#ifdef _WIN32 +// res = sy_licence(productSN); +//#elif __linux__ +// res = sy_licence(productSN, &wtime); +// //printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status); +//#endif +// if (res < 0) +// { +// handle->licence_status = handle->licence_status - 1; +// } +// else +// { +// if (handle->licence_status < 0) +// { +// handle->licence_status = 0; +// } +// } +// boost::this_thread::sleep(boost::posix_time::seconds(300)); //5min +// } +//#ifdef __linux__ +// if (wtime) +// { +// delete[] wtime; +// wtime = NULL; +// } +//#endif +//} +#define RESIZE_SCALE 0.5 +inline std::chrono::system_clock::time_point makeTimePoint(int year, int mon, int day) { - int res = -1; -#ifdef __linux__ - char* wtime = new char[15]; - memset(wtime, 0, 15); -#endif - while (1) + std::tm t; + t.tm_year = year - 1900; + t.tm_mon = mon - 1; + t.tm_mday = day; + t.tm_hour = 0; + t.tm_min = 0; + t.tm_sec = 0; + t.tm_isdst = -1; + std::time_t tt = std::mktime(&t); + if (tt == -1) { - //printf("xxx check status on process...\n"); -#ifdef _WIN32 - res = sy_licence(productSN); -#elif __linux__ - res = sy_licence(productSN, &wtime); - //printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status); -#endif - if (res < 0) - { - handle->licence_status = handle->licence_status - 1; - } - else - { - if (handle->licence_status < 0) - { - handle->licence_status = 0; - } - } - boost::this_thread::sleep(boost::posix_time::seconds(300)); //5min + exit(-1); + } + return std::chrono::system_clock::from_time_t(tt); +} + +inline bool timecheck() +{ + std::chrono::system_clock::time_point limitTime = makeTimePoint(2020, 12, 31); + std::chrono::system_clock::time_point nowTime = std::chrono::system_clock::now(); + if (nowTime > limitTime) + { + return false; } -#ifdef __linux__ - if (wtime) + else { - delete[] wtime; - wtime = NULL; + return true; } -#endif } - - int rs_init(void **handle, rs_param param) { int ret = SUCCESS; -#ifdef AUTHORIZATION -#ifdef _WIN32 - if (SUCCESS == (ret = sy_licence(productSN))) -#elif __linux__ - char* wtime = new char[15]; - memset(wtime, 0, 15); - if (SUCCESS == (ret = sy_licence(productSN, &wtime))) -#endif -#else - ret = sy_time_check(2022, 1); - if (ret == SUCCESS) -#endif + + if (timecheck()) { RegionSurveillanceProcess* regin = nullptr; //if (param.mode == 0) - regin = new IRegionSurveillanceCpu; - regin->frame_num = param.frame_num; + regin = new IRegionSurveillanceCpu; + regin->frame_num = param.frame_num; if (!regin) { printf("model initial failed \n"); return -1; } - - regin->long_side = param.long_side; - regin->short_side = param.short_side; + + /* regin->long_side = param.long_side; + regin->short_side = param.short_side;*/ regin->licence_status = 0; -#ifdef AUTHORIZATION - regin->thrd_run = true; - regin->thrd = boost::thread(check_thread, regin); -#endif + regin->thrd_status = 0; - *handle = regin; -#ifdef AUTHORIZATION -#ifdef __linux__ - if (wtime) + regin->scale = param.scale; + regin->rect_num = param.rect_num; //Ч + for (int i = 0; i < regin->rect_num; ++i) { - delete[] wtime; - wtime = NULL; + regin->rect[i].left_ = param.rect[i].left_ / param.scale; + regin->rect[i].top_ = param.rect[i].top_ / param.scale; + regin->rect[i].width_ = param.rect[i].width_ / param.scale; + regin->rect[i].height_ = param.rect[i].height_ / param.scale; } -#endif -#endif + *handle = regin; return ret; } else { return AUTHOR_ERROR; } - + } +//int rs_init(void **handle, rs_param param) +//{ +// int ret = SUCCESS; +//#ifdef AUTHORIZATION +//#ifdef _WIN32 +// if (SUCCESS == (ret = sy_licence(productSN))) +//#elif __linux__ +// char* wtime = new char[15]; +// memset(wtime, 0, 15); +// if (SUCCESS == (ret = sy_licence(productSN, &wtime))) +//#endif +//#else +// ret = sy_time_check(2021, 1); +// if (ret == SUCCESS) +//#endif +// { +// +// RegionSurveillanceProcess* regin = nullptr; +// //if (param.mode == 0) +// regin = new IRegionSurveillanceCpu; +// regin->frame_num = param.frame_num; +// if (!regin) +// { +// printf("model initial failed \n"); +// return -1; +// } +// +// +// regin->long_side = param.long_side; +// regin->short_side = param.short_side; +// regin->licence_status = 0; +//#ifdef AUTHORIZATION +// regin->thrd_run = true; +// regin->thrd = boost::thread(check_thread, regin); +//#endif +// regin->thrd_status = 0; +// *handle = regin; +//#ifdef AUTHORIZATION +//#ifdef __linux__ +// if (wtime) +// { +// delete[] wtime; +// wtime = NULL; +// } +//#endif +//#endif +// return ret; +// } +// else +// { +// return AUTHOR_ERROR; +// } +// +//} + int rs_process(void *handle, sy_img img_data, rs_result *result) { RegionSurveillanceProcess* regin = (RegionSurveillanceProcess*)handle; @@ -135,12 +208,12 @@ int rs_process(void *handle, sy_img img_data, rs_result *result) //pRegionInfo.p_roi[3].y_ = img_data.h_; cv::Mat srcImage(img_data.h_, img_data.w_, CV_8UC3, img_data.data_); IplImage img = IplImage(srcImage); - int long_side = (img.width > img.height ? img.width : img.height); - int short_side = (img.width <= img.height ? img.width : img.height); - double scale_l = (double)long_side / (double)regin->long_side; - double scale_s = (double)short_side / (double)regin->short_side; - regin->scale = (scale_l > scale_s ? scale_l : scale_s); - regin->scale = 1.00; + //int long_side = (img.width > img.height ? img.width : img.height); + //int short_side = (img.width <= img.height ? img.width : img.height); + //double scale_l = (double)long_side / (double)regin->long_side; + //double scale_s = (double)short_side / (double)regin->short_side; + //regin->scale = (scale_l > scale_s ? scale_l : scale_s); + //regin->scale = param.scale; int width = img.width / regin->scale; int height = img.height / regin->scale; IplImage * srcscale = cvCreateImage(cvSize(width, height), 8, 3); // ǰȲ diff --git a/src/left_over/svibe.cpp b/src/left_over/svibe.cpp index 7ba6b67..64ad291 100644 --- a/src/left_over/svibe.cpp +++ b/src/left_over/svibe.cpp @@ -849,92 +849,253 @@ void RegionSurveillance::VibeModelErosion(unsigned char* inputdata, int width, i } } } +typedef union uEndianTest { + struct { + bool flittle_endian; + bool fill[3]; + }; + long value; +} EndianTest; +static const EndianTest __Endian_Test__ = { (long)1 }; +const bool platform_little_endian = __Endian_Test__.flittle_endian; + + +typedef struct _int_128 +{ + int64_t _n1; + int64_t _n2; +}_int_128; -void RegionSurveillance::VibeModelDilation2(unsigned char* inputdata,unsigned char *output, int width,int height) +const _int_128 & int_128_max(const _int_128 & n1, const _int_128 & n2) +{ + if (platform_little_endian) //С + { + if (n1._n2 > n2._n2) + { + return n1; + } + else if (n1._n2 < n2._n2) + { + return n2; + } + else + { + if (n1._n1 > n2._n1) + { + return n1; + } + else if (n1._n1 < n2._n1) + { + return n2; + } + else + { + return n1; + } + } + } + else + { + if (n1._n1 > n2._n1) // + { + return n1; + } + else if (n1._n1 < n2._n1) + { + return n2; + } + else + { + if (n1._n2 > n2._n2) + { + return n1; + } + else if (n1._n2 < n2._n2) + { + return n2; + } + else + { + return n1; + } + } + } +} + +void int_128_store(_int_128 * n1, _int_128 & n2) +{ + n1->_n1 = n2._n1; + n1->_n2 = n2._n2; +} +void RegionSurveillance::VibeModelDilation2(unsigned char* inputdata, unsigned char *output, int width, int height) { memset(output, 0, sizeof(output[0])*width*height); - if (width<32 || height<32 || inputdata==NULL || output==NULL) + if (width<32 || height<32 || inputdata == NULL || output == NULL) return; unsigned char *src = inputdata; unsigned char *dst = output; //memcpy(output, inputdata, width*height); - for (int i=0; i &ForegroundArray) } - +int RegionSurveillance::dwGlobalID; /****************************************************************************** * Function: VibeModelGetTrace * Description: diff --git a/src/left_over/svibe.h b/src/left_over/svibe.h index dc437c1..2627180 100644 --- a/src/left_over/svibe.h +++ b/src/left_over/svibe.h @@ -184,7 +184,7 @@ private: void FreeRandNeighbor(); public: - int dwGlobalID; // object ID for Global use + static int dwGlobalID; // object ID for Global use //by zl 20160307 private: diff --git a/src/test/demo.cpp b/src/test/demo.cpp index b6f4d8c..a44734a 100644 --- a/src/test/demo.cpp +++ b/src/test/demo.cpp @@ -78,23 +78,39 @@ void imag_ana_3channels() void *tools = nullptr; rs_param param; - param.frame_num = 30; - param.long_side = 1920; - param.short_side = 1080; + param.frame_num = 100; + //param.long_side = 1920; + //param.short_side = 1080; + param.scale = 2; + param.rect_num = 2; + + { + param.rect[0].left_ = 30; + param.rect[0].top_ = 0; + param.rect[0].width_ = 320; + param.rect[0].height_ = 480; + + param.rect[1].left_ = 320; + param.rect[1].top_ = 0; + param.rect[1].width_ = 319; + param.rect[1].height_ = 479; + } if (rs_init(&tools, param) != 0) cout << "hp_init ailed!" << endl; char imgpath[260]; + //CvCapture* video1 = cvCaptureFromFile("D:\\weixin\\ATM\\20200928\\192.0.0.209_8000_1_4_-1\\20200928_20200928103418_20200928104058_103413.mp4"); + //CvCapture* video1 = cvCaptureFromFile("E:\\vpt_pic\\MSRegion.git\\win\\MSRegionDemo\\test1.mp4"); CvCapture* video1 = cvCaptureFromFile("D:\\ruijinVideo\\192.168.1.10_01_2020072911472348.mp4"); // opencvȡƵһ֡ IplImage * src = cvQueryFrame(video1); - int long_side = (src->width > src->height ? src->width : src->height); - int short_side = (src->width <= src->height ? src->width : src->height); - double scale_l = (double)long_side / (double)param.long_side; - double scale_s = (double)short_side / (double)param.short_side; - double scale = (scale_l > scale_s ? scale_l : scale_s); - scale = 1.0; + //int long_side = (src->width > src->height ? src->width : src->height); + //int short_side = (src->width <= src->height ? src->width : src->height); + //double scale_l = (double)long_side / (double)param.long_side; + //double scale_s = (double)short_side / (double)param.short_side; + //double scale = (scale_l > scale_s ? scale_l : scale_s); + double scale = 1.0; int width = src->width / scale; int height = src->height / scale; //width = 1912; @@ -142,7 +158,7 @@ void imag_ana_3channels() //ExternalRectangle((unsigned char*)(srcscale1->imageData), srcscale1->width, srcscale1->height, result.obj_infos, result.obj_count, srcscale1->widthStep, 1); /*****************************************************/ - ExternalRectangle((unsigned char*)(srcscale->imageData), srcscale->width, srcscale->height, result.obj_infos, result.obj_count, srcscale->widthStep, 1); + ExternalRectangle((unsigned char*)(srcscale->imageData), srcscale->width, srcscale->height, result.obj_infos, result.obj_count, srcscale->widthStep,1); CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 2, 8); //cvPutText(srcscale, "1Hello World !", cvPoint(80, 40), &font, cvScalar(255, 0, 0, 1)); diff --git a/src/test/regionassist.h b/src/test/regionassist.h index 3e413d3..d67d9cb 100644 --- a/src/test/regionassist.h +++ b/src/test/regionassist.h @@ -16,5 +16,5 @@ void Trajectory(unsigned char* pRGBIn, ms_object_info *ObjInfo, int ObjCount, in //жϵⷽͻƼͷ void DrawArrow(IplImage * src, cv::Point pStart, cv::Point pEnd, int len, int alpha); -int get_ArrowDir(IplImage *frame, CMPoint pROI0, CMPoint pROI1, CMPoint dir, cv::Point &pt1, cv::Point &pt2); +//int get_ArrowDir(IplImage *frame, CMPoint pROI0, CMPoint pROI1, CMPoint dir, cv::Point &pt1, cv::Point &pt2); #endif \ No newline at end of file -- libgit2 0.21.4