Commit a74689b77248633e4cd19ecc3254709c24408c4c

Authored by Zou XiKun
1 parent e3429e30

海思

src/left_over/MSRegionSurveilance.cpp
... ... @@ -7,8 +7,9 @@
7 7 IRegionSurveillance *MS_RegionSurveillance::GetMS_RS()
8 8 {
9 9  
10   - if (!MS_RS)
  10 + //if (!MS_RS)
11 11 {
  12 + RegionSurveillance * MS_RS = nullptr;
12 13 if (checkTime() == 1 && (MS_RS = new RegionSurveillance()))
13 14 return MS_RS;
14 15 else
... ... @@ -25,7 +26,7 @@ void MS_RegionSurveillance::Destroy()
25 26 {
26 27 if (MS_RS)
27 28 {
28   - delete MS_RS;
  29 + delete[] MS_RS;
29 30 MS_RS = NULL;
30 31 }
31 32 }
... ...
src/left_over/MSRegionSurveilance.h
... ... @@ -17,6 +17,9 @@
17 17 #include <cmath>
18 18 #include <cstdlib>
19 19 #include "header.h"
  20 +#include "ConExtraction.h"
  21 +#include <list>
  22 +#include <map>
20 23 using namespace std;
21 24  
22 25 #define MAXTRACENUM 200 //¹ì¼£×î´ó³¤¶È
... ...
src/left_over/MSRegionSurveilanceBase.cpp deleted
1   -#include "MSRegionSurveilanceBase.h"
2   -
3   -IRegionSurveillanceBase::IRegionSurveillanceBase()
4   -{
5   - pRegion = nullptr;
6   - pAlarmInfo = nullptr;
7   -}
8   -
9   -int IRegionSurveillanceBase::rs_init(const rs_param & param)
10   -{
11   - GlobelWidth = param.image.w_;
12   - GlobelHeight = param.image.h_;
13   -
14   - return init(param);
15   -
16   -}
17   -
18   -int IRegionSurveillanceBase::rs_init_region(int numROI, region_info* region_infos, bool iflog)
19   -{
20   - fstream file;//用于输出日志
21   - if (numROI > MAXROINUM)
22   - {
23   - return 0;
24   - }
25   -
26   - for (int i = 0; i < numROI; i++)
27   - {
28   - if (iflog)
29   - {
30   - file.open("log.txt", ios::app);
31   - file << i << ": ";
32   - printAlarmType(&file, region_infos[i].alarm_info);
33   - file << "P1(" << region_infos[i].p_roi[0].x_ << "," << region_infos[i].p_roi[0].y_ << "), P2("
34   - << region_infos[i].p_roi[1].x_ << "," << region_infos[i].p_roi[1].y_ << ")";
35   - }
36   - if (region_infos[i].alarm_info == 3)
37   - {
38   - region_infos[i].finaldir = rs_get_arrowdir(region_infos[i].p_roi[0], region_infos[i].p_roi[1], region_infos[i].dir_point);//确定方向计算,箭头端点坐标
39   -
40   - if (iflog)
41   - file << ", DirPoint(" << region_infos[i].dir_point.x_ << "," << region_infos[i].dir_point.y_ << ")";
42   -
43   - region_infos[i].arrow_start_point = pStart; //箭头的起始端点 箭头指向正方形
44   - region_infos[i].arrow_end_point = pEnd; //箭头的终止端点 箭头指向正方形
45   - }
46   - if (iflog)
47   - {
48   - file << endl;
49   - file.close();
50   - }
51   - }
52   -
53   - m_numROI = numROI;
54   - if (pRegion == NULL)
55   - {
56   - pRegion = new bool*[MAXROINUM];
57   - memset(pRegion, 0, sizeof(bool*) * MAXROINUM);
58   - }
59   -
60   - if (pAlarmInfo == NULL)
61   - {
62   - pAlarmInfo = new int[MAXROINUM];
63   - memset(pAlarmInfo, 0, sizeof(int) * MAXROINUM);
64   - }
65   -
66   - for (int i = 0; i < MAXROINUM; i++)
67   - {
68   - if (pRegion[i] == NULL)
69   - {
70   - pRegion[i] = new bool[GlobelHeight * GlobelWidth];
71   - }
72   - memset(pRegion[i], 0, sizeof(bool) * GlobelWidth * GlobelHeight);
73   - if (i <= m_numROI)
74   - {
75   - pAlarmInfo[i] = region_infos[i].alarm_info;
76   - }
77   - else
78   - {
79   - pAlarmInfo[i] = 0;
80   - }
81   - }
82   -
83   -
84   - // 对每一个待观察的ROI进行监测
85   - for (int i = 0; i < numROI; i++)
86   - {
87   - // 对每一个感兴趣区域进行标志 感兴趣区域pRegion值为1 其余为0
88   - vibeMask(region_infos[i].point_num, region_infos[i].p_roi, pRegion[i]);
89   - }
90   -
91   - return 1;
92   -
93   -}
94   -
95   -void IRegionSurveillanceBase::RSrelease()
96   -{
97   - for (int i = 0; i < MAXROINUM; i++)
98   - {
99   - if (pRegion[i] != NULL)
100   - {
101   - delete[] pRegion[i];
102   - }
103   - }
104   -
105   - if (pRegion != NULL)
106   - {
107   - delete[] pRegion;
108   - pRegion = NULL;
109   - }
110   -
111   - if (pAlarmInfo != NULL)
112   - {
113   - delete[] pAlarmInfo;
114   - pAlarmInfo = NULL;
115   - }
116   - release();
117   - vec_traceinfo.clear();
118   -}
119   -
120   -int IRegionSurveillanceBase::rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir)
121   -{
122   -
123   - float distance = (float)abs(p_roi0.y_ - p_roi1.y_);
124   - //获取方向
125   - float k1, k2; //k1为原线段的斜率
126   -
127   - if (p_roi0.y_ > p_roi1.y_) //在拌线靠近图像下方的端点处画箭头
128   - {
129   - pStart.x_ = p_roi0.x_;
130   - pStart.y_ = p_roi0.y_;
131   - }
132   - else
133   - {
134   - pStart.x_ = p_roi1.x_;
135   - pStart.y_ = p_roi1.y_;
136   - }
137   -
138   - if (p_roi0.x_ != p_roi1.x_) //若不为一根垂直线
139   - {
140   - k1 = (float)(p_roi0.y_ - p_roi1.y_) / (float)(p_roi0.x_ - p_roi1.x_);
141   - if (k1 != 0) //若不为一根平行线
142   - {
143   - k2 = -1 / k1;
144   -
145   -
146   - float b = p_roi1.y_ - k1 * p_roi1.x_;//y = kx + b 坐标系一图像左上顶点为原点,向右为x正方形 向下为y正方向
147   - 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))
148   - {
149   - if (distance < 30) //当两点y值差异较小时,垂线比较陡 若减去20 可能导致箭头太长
150   - {
151   - pEnd.x_ = pStart.x_ - 2;
152   - }
153   - else
154   - pEnd.x_ = pStart.x_ - 20;
155   - }
156   - else
157   - {
158   - if (distance < 30)
159   - {
160   - pEnd.x_ = pStart.x_ + 2;
161   - }
162   - else
163   - pEnd.x_ = pStart.x_ + 20;
164   - }
165   - pEnd.y_ = (int)((pEnd.x_ - pStart.x_) * k2 + pStart.y_);
166   - }
167   - else //若为水平线
168   - {
169   - pEnd.x_ = pStart.x_;
170   - if (dir.y_ > pStart.y_)
171   - pEnd.y_ = pStart.y_ + 20;
172   - else
173   - pEnd.y_ = pStart.y_ - 20;
174   -
175   - }
176   -
177   - }
178   - else //若为垂直线
179   - {
180   - pEnd.y_ = pStart.y_;
181   - if (dir.x_ > pStart.x_)
182   - pEnd.x_ = pStart.x_ + 20;
183   - else
184   - pEnd.x_ = pStart.x_ - 20;
185   - }
186   - //防止越界
187   - pEnd.x_ = pEnd.x_ >= 0 ? pEnd.x_ : 0;
188   - pEnd.x_ = pEnd.x_ <= GlobelWidth ? pEnd.x_ : GlobelWidth;
189   - pEnd.y_ = pEnd.y_ >= 0 ? pEnd.y_ : 0;
190   - pEnd.y_ = pEnd.y_ <= GlobelHeight ? pEnd.y_ : GlobelHeight;
191   -
192   - if (p_roi0.x_ == p_roi1.x_) //若为垂直线
193   - {
194   - if (pEnd.x_ > pStart.x_)
195   - return 1;
196   - else
197   - return 0;
198   - }
199   - else if (k1 <= 0) //若不为垂直线且斜率小于等于0(含水平线情况)
200   - {
201   - if ((pStart.x_ != pEnd.x_ && pEnd.x_ > pStart.x_) || (pStart.x_ == pEnd.x_ && pEnd.y_ > pStart.y_))
202   - return 0;
203   - else
204   - return 1;
205   - }
206   - else
207   - {
208   - if ((pStart.x_ != pEnd.x_ && pEnd.x_ > pStart.x_) || (pStart.x_ == pEnd.x_ && pEnd.y_ > pStart.y_))
209   - return 1;
210   - else
211   - return 0;
212   - }
213   -}
214   -
215   -void IRegionSurveillanceBase::vibeMask(int num, sy_point *pPointList, bool *pRegion)
216   -{
217   -
218   - if (num == 2)
219   - {
220   - double s;
221   - int i, x, y;
222   - int xs, ys;
223   - int dx, dy;
224   -
225   - dx = pPointList[1].x_ - pPointList[0].x_;
226   - if (dx < 0)
227   - {
228   - dx = -dx;
229   - }
230   - dy = pPointList[1].y_ - pPointList[0].y_;
231   - if (dy < 0)
232   - {
233   - dy = -dy;
234   - }
235   - if (dy < dx)
236   - {
237   - //draw according to x-y
238   - s = (double)(pPointList[1].y_ - pPointList[0].y_) / (pPointList[1].x_ - pPointList[0].x_);
239   -
240   - if (pPointList[0].x_ < pPointList[1].x_)
241   - {
242   - xs = pPointList[0].x_;
243   - ys = pPointList[0].y_;
244   - }
245   - else
246   - {
247   - xs = pPointList[1].x_;
248   - ys = pPointList[1].y_;
249   - }
250   -
251   - for (i = 0; i <= dx; i++)
252   - {
253   - x = i + xs;
254   - y = (int)((double)i * s) + ys;
255   - if (x > -1 && x < GlobelWidth && y > -1 && y < GlobelHeight)
256   - {
257   - pRegion[GlobelWidth * y + x] = 1;
258   - }
259   - }
260   - }
261   - else
262   - {
263   - //draw according to y-x
264   - s = (double)(pPointList[1].x_ - pPointList[0].x_) / (pPointList[1].y_ - pPointList[0].y_);
265   -
266   - if (pPointList[0].y_ < pPointList[1].y_)
267   - {
268   - xs = pPointList[0].x_;
269   - ys = pPointList[0].y_;
270   - }
271   - else
272   - {
273   - xs = pPointList[1].x_;
274   - ys = pPointList[1].y_;
275   - }
276   - for (i = 0; i <= dy; i++)
277   - {
278   - y = i + ys;
279   - x = (int)((double)i * s) + xs;
280   - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth)
281   - {
282   - pRegion[GlobelWidth * y + x] = 1;
283   - }
284   - }
285   - }
286   - }
287   - else if (num >= 3)
288   - {
289   -
290   - sy_point LineMin;
291   - sy_point LineMax;
292   -
293   - for (int k = 0; k < num; k++)
294   - {
295   - int startp = k;
296   - int endp = k + 1;
297   -
298   - if (startp == num - 1)
299   - {
300   - endp = 0;
301   - }
302   -
303   - if (abs(pPointList[startp].x_ - pPointList[endp].x_) >= abs(pPointList[startp].y_ - pPointList[endp].y_))
304   - {
305   - if (pPointList[startp].x_ < pPointList[endp].x_)
306   - {
307   - LineMin = pPointList[startp];
308   - LineMax = pPointList[endp];
309   - for (int x = LineMin.x_; x <= LineMax.x_; x++)
310   - {
311   - int y = (int)(((LineMin.y_ - LineMax.y_) / (double)(LineMin.x_ - LineMax.x_)) * (double)(x - LineMin.x_) + 0.5 + (double)LineMin.y_);
312   - //pRegion[GlobelWidth * y + x] = 1;
313   -
314   - //原程序存在越界 苏晓芸修改如下
315   - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth)
316   - {
317   - pRegion[GlobelWidth * y + x] = 1;
318   - }
319   - }
320   - }
321   - else if (pPointList[startp].x_ > pPointList[endp].x_)
322   - {
323   - LineMin = pPointList[endp];
324   - LineMax = pPointList[startp];
325   - for (int x = LineMin.x_; x <= LineMax.x_; x++)
326   - {
327   - int y = (int)(((LineMin.y_ - LineMax.y_) / (double)(LineMin.x_ - LineMax.x_)) * (double)(x - LineMin.x_) + 0.5 + (double)LineMin.y_);
328   - //pRegion[GlobelWidth * y + x] = 1;
329   -
330   - //原程序存在越界 苏晓芸修改如下
331   - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth)
332   - {
333   - pRegion[GlobelWidth * y + x] = 1;
334   - }
335   - }
336   - }
337   - else
338   - {
339   - int YMin = (pPointList[startp].y_ < pPointList[endp].y_) ? pPointList[startp].y_ : pPointList[endp].y_;
340   - int YMax = (pPointList[startp].y_ < pPointList[endp].y_) ? pPointList[endp].y_ : pPointList[startp].y_;
341   - for (int i = YMin; i <= YMax; i++)
342   - {
343   - //pRegion[GlobelWidth * i + pPointList[startp].x_] = 1;
344   -
345   - //原程序存在越界 苏晓芸修改如下
346   - if (i > -1 && i < GlobelHeight && pPointList[startp].x_ > -1 && pPointList[startp].x_ < GlobelWidth)
347   - {
348   - pRegion[GlobelWidth * i + pPointList[startp].x_] = 1;
349   - }
350   - }
351   - }
352   - }
353   - else
354   - {
355   - if (pPointList[startp].y_ < pPointList[endp].y_)
356   - {
357   - LineMin = pPointList[startp];
358   - LineMax = pPointList[endp];
359   - for (int y = LineMin.y_; y <= LineMax.y_; y++)
360   - {
361   - int x = (int)(((LineMin.x_ - LineMax.x_) / (double)(LineMin.y_ - LineMax.y_)) * (double)(y - LineMin.y_) + 0.5 + (double)LineMin.x_);
362   - //pRegion[GlobelWidth * y + x] = 1;
363   -
364   - //原程序存在越界 苏晓芸修改如下
365   - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth)
366   - {
367   - pRegion[GlobelWidth * y + x] = 1;
368   - }
369   - }
370   - }
371   - else if (pPointList[startp].y_ > pPointList[endp].y_)
372   - {
373   - LineMin = pPointList[endp];
374   - LineMax = pPointList[startp];
375   - for (int y = LineMin.y_; y <= LineMax.y_; y++)
376   - {
377   - int x = (int)(((LineMin.x_ - LineMax.x_) / (double)(LineMin.y_ - LineMax.y_)) * (double)(y - LineMin.y_) + 0.5 + (double)LineMin.x_);
378   - //pRegion[GlobelWidth * y + x] = 1;
379   -
380   - //原程序存在越界 苏晓芸修改如下
381   - if (y > -1 && y < GlobelHeight && x > -1 && x < GlobelWidth)
382   - {
383   - pRegion[GlobelWidth * y + x] = 1;
384   - }
385   - }
386   - }
387   - else
388   - {
389   - int XMin = (pPointList[startp].x_ < pPointList[endp].x_) ? pPointList[startp].x_ : pPointList[endp].x_;
390   - int XMax = (pPointList[startp].x_ < pPointList[endp].x_) ? pPointList[endp].x_ : pPointList[startp].x_;
391   - for (int i = XMin; i <= XMax; i++)
392   - {
393   - //pRegion[GlobelWidth * pPointList[startp].y_ + i] = 1;
394   -
395   - //原程序存在越界 苏晓芸修改如下
396   - if (pPointList[startp].y_ > -1 && pPointList[startp].y_ < GlobelHeight && i > -1 && i < GlobelWidth)
397   - {
398   - pRegion[GlobelWidth * pPointList[startp].y_ + i] = 1;
399   - }
400   - }
401   - }
402   - }
403   - }
404   -
405   - // 修改标记方式 将区域边缘标志置为0
406   - for (int i = 0; i < GlobelHeight; i++)
407   - {
408   - for (int j = 0; j < GlobelWidth; j++)
409   - {
410   - if (pRegion[GlobelWidth * i + j] == 0)
411   - {
412   - pRegion[GlobelWidth * i + j] = 1;
413   - }
414   - else
415   - {
416   - pRegion[GlobelWidth * i + j] = 0;
417   - }
418   - }
419   - }
420   -
421   - sy_point StartPoint;
422   - int SumX = 0;
423   - int SumY = 0;
424   - for (int k = 0; k < num; k++)
425   - {
426   - SumX = SumX + pPointList[k].x_;
427   - SumY = SumY + pPointList[k].y_;
428   - }
429   - StartPoint.x_ = SumX / num;
430   - StartPoint.y_ = SumY / num;
431   -
432   - bool *pMaskMap = new bool[GlobelWidth * GlobelHeight];
433   - bool *pMaskMapS = new bool[GlobelWidth * GlobelHeight];
434   - memset(pMaskMap, 0, sizeof(bool) * GlobelWidth * GlobelHeight);
435   - memset(pMaskMapS, 0, sizeof(bool) * GlobelWidth * GlobelHeight);
436   - pMaskMap[GlobelWidth * StartPoint.y_ + StartPoint.x_] = 1;
437   -
438   - int msum = 1;
439   - while (msum != 0)
440   - {
441   - msum = 0;
442   - for (int i = 0; i < GlobelHeight; i++)
443   - {
444   - for (int j = 0; j < GlobelWidth; j++)
445   - {
446   - msum = msum + pMaskMap[GlobelWidth * i + j] - pMaskMapS[GlobelWidth * i + j];
447   - pMaskMapS[GlobelWidth * i + j] = pMaskMap[GlobelWidth * i + j];
448   - }
449   - }
450   - for (int i = 0; i < GlobelHeight; i++)
451   - {
452   - for (int j = 0; j < GlobelWidth; j++)
453   - {
454   - if ((i <= 0) || (i >= GlobelHeight - 1) || (j <= 0) || (j >= GlobelWidth - 1))
455   - {
456   - continue;
457   - }
458   -
459   - if (pMaskMapS[GlobelWidth * i + j] == 1)
460   - {
461   - pMaskMap[GlobelWidth * i + j + 1] = 1;
462   - pMaskMap[GlobelWidth * i + j - 1] = 1;
463   - pMaskMap[GlobelWidth * (i + 1) + j] = 1;
464   - pMaskMap[GlobelWidth * (i - 1) + j] = 1;
465   - }
466   - }
467   - }
468   - for (int i = 0; i < GlobelHeight; i++)
469   - {
470   - for (int j = 0; j < GlobelWidth; j++)
471   - {
472   - pMaskMap[GlobelWidth * i + j] = pMaskMap[GlobelWidth * i + j] && pRegion[GlobelWidth * i + j];
473   - }
474   - }
475   - }
476   -
477   - memcpy(pRegion, pMaskMap, sizeof(bool) * GlobelWidth * GlobelHeight);
478   -
479   - delete[] pMaskMap;
480   - delete[] pMaskMapS;
481   - }
482   -}
483   -
484   -/******************************************************************************
485   -* Function: RSRegion
486   -* Description: 感兴趣区域设置
487   -* Calls: vibeMask
488   -* Called By: main
489   -* Input: numROI ROI个数
490   -pRegionInfo ROI区域
491   -iflog true:输出日志 false:不输出日志
492   -* Output: pRegion 10个ROI指针(bool)每个大小为(图像宽*图像高)感兴趣区域值为1 其余为0
493   -//regionAlarm 10个ROI 报警标志(bool)
494   -pAlarmInfo 10个ROI 报警标志(int)
495   -* Return: 3 1
496   -*******************************************************************************/
497   -void IRegionSurveillanceBase::printAlarmType(std::fstream *file, int style)
498   -{
499   - switch (style)
500   - {
501   - case 1:
502   - *file << "进入禁区, ";
503   - break;
504   - case 2:
505   - *file << "离开禁区, ";
506   - break;
507   - case 3:
508   - *file << "单向越界, ";
509   - break;
510   - case 4:
511   - *file << "双向越界, ";
512   - break;
513   - case 5:
514   - *file << "徘徊, ";
515   - break;
516   - case 6:
517   - *file << "丢包, ";
518   - break;
519   - default:
520   - break;
521   - }
522   -}
523   -
524   -void IRegionSurveillanceBase::AddTaskTracker(const int taskID, const double rWidth, const double rHeight)
525   -{
526   - taskTrackers.TaskID = taskID;
527   - taskTrackers.ratioWidth = rWidth;
528   - taskTrackers.ratioHeight = rHeight;
529   -}
530   -
531   -void IRegionSurveillanceBase::AccessToRestrictedAreas(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //进入禁区
532   -{
533   -
534   - // 只要目标外接矩形有一个点进入区域则报警
535   - for (int ii = 0; ii < m_numROI; ii++) //区域
536   - {
537   - for (int i = 0; i < vptResult.objCount; ++i) //目标
538   - {
539   - if (pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x] && \
540   - pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x + 1] && \
541   - pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x - 1] && \
542   - pRegion[ii][GlobelWidth * (vptResult.obj[i].center_y + 1) + vptResult.obj[i].center_x] && \
543   - pRegion[ii][GlobelWidth * (vptResult.obj[i].center_y - 1) + vptResult.obj[i].center_x])
544   - {
545   - result->obj_infos[i].pb_alarm_state[ii] = true;
546   - result->obj_infos[i].pb_alarm_type[ii] = 1;
547   - }
548   -
549   - }
550   - }
551   - return;
552   -}
553   -
554   -void IRegionSurveillanceBase::LeaveTheRestrictedAreas(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //离开禁区
555   -{
556   - for (int ii = 0; ii < m_numROI; ii++) //区域
557   - {
558   - for (int i = 0; i < vptResult.objCount; ++i) //目标
559   - {
560   - int tar_size = result->obj_infos[i].trace.trace_num;
561   - if (tar_size > 4)
562   - {
563   - sy_point PredictionPoint;
564   - PredictionPoint.x_ = vptResult.obj[i].center_x - result->obj_infos[i].trace.obj_trace[tar_size - 4].x_ + vptResult.obj[i].center_x;
565   - PredictionPoint.y_ = vptResult.obj[i].center_y - result->obj_infos[i].trace.obj_trace[tar_size - 4].y_ + vptResult.obj[i].center_y;
566   - if (pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].left] || \
567   - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].left] || \
568   - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].right] || \
569   - pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].right])
570   - {
571   - if (pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x] == false &&
572   - pRegion[ii][GlobelWidth * PredictionPoint.y_ + PredictionPoint.x_] == false)
573   - {
574   - bool flag = 0;
575   - int j;
576   -
577   - j = tar_size - 1;
578   - while (j >= 0 && j >= tar_size - (vptResult.obj[i].right - vptResult.obj[i].left) / 2)
579   - {
580   - if (pRegion[ii][GlobelWidth * (int)(result->obj_infos[i].trace.obj_trace[j].y_) + (result->obj_infos[i].trace.obj_trace[j].x_)])
581   - {
582   - flag = 1;
583   - break;
584   - }
585   -
586   - j--;
587   - }
588   - if (flag == 1)
589   - {
590   - result->obj_infos[i].pb_alarm_state[ii] = true;
591   - result->obj_infos[i].pb_alarm_type[ii] = 2;
592   - return;
593   - }
594   - }
595   -
596   -
597   - }
598   - }
599   -
600   -
601   -
602   - }
603   - }
604   - return;
605   -}
606   -
607   -void IRegionSurveillanceBase::OneWayCrossBorder(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //单向越界
608   -{
609   - for (int ii = 0; ii < m_numROI; ii++) //区域
610   - {
611   - for (int i = 0; i < vptResult.objCount; ++i) //目标
612   - {
613   - int tar_size = result->obj_infos[i].trace.trace_num;
614   - for (int iy = vptResult.obj[i].top; iy <= vptResult.obj[i].bottom; iy++)
615   - {
616   - for (int ix = vptResult.obj[i].left; ix <= vptResult.obj[i].right; ix++)
617   - {
618   - if (pRegion[ii][GlobelWidth * iy + ix] && tar_size >= 4)
619   - {
620   - int point_x, point_y;
621   - point_x = result->obj_infos[i].trace.obj_trace[tar_size - 4].x_;
622   - point_y = result->obj_infos[i].trace.obj_trace[tar_size - 4].y_;
623   - if (ii >= 0 && ii < m_numROI && region_infos[ii].point_num >= 2)
624   - {
625   - if (abs(region_infos[ii].p_roi[0].x_ - region_infos[ii].p_roi[1].x_) >= 1)
626   - {
627   - double k, b;
628   - 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_);
629   - 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_) /
630   - (region_infos[ii].p_roi[0].x_ - region_infos[ii].p_roi[1].x_);
631   -
632   - double dist_c, dist_p;
633   -
634   - 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);
635   - dist_p = fabs(k * point_x - point_y + b) / sqrt(k * k + 1.0);
636   -
637   - if (abs(dist_c - dist_p) < 10)
638   - {
639   - int pre_index = tar_size - 5;
640   - while (pre_index >= 0)
641   - {
642   - point_x = result->obj_infos[i].trace.obj_trace[pre_index].x_;
643   - point_y = result->obj_infos[i].trace.obj_trace[pre_index].y_;
644   - dist_p = fabs(k * point_x - point_y + b) / sqrt(k * k + 1.0);
645   - pre_index = pre_index - 1;
646   - if (abs(dist_c - dist_p) >= 10)
647   - {
648   - break;
649   - }
650   - }
651   - }
652   -
653   -
654   - if (abs(dist_c - dist_p) < 10)
655   - {
656   - result->obj_infos[i].pb_alarm_state[ii] = false;
657   - result->obj_infos[i].pb_alarm_type[ii] = 0;
658   - return;
659   - }
660   -
661   - bool flag_c, flag_p;
662   - 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_)
663   - {
664   - flag_c = 1;
665   - }
666   - else
667   - {
668   - flag_c = 0;
669   - }
670   -
671   - if (k *point_x + b >= point_y)
672   - {
673   - flag_p = 1;
674   - }
675   - else
676   - {
677   - flag_p = 0;
678   - }
679   -
680   -
681   - //if (region_infos[ii].dir == 1)
682   - if (region_infos[ii].finaldir == 1) //by zl 20150914
683   - {
684   - if (flag_c * flag_p == 1)
685   - {
686   - if (dist_c <= dist_p)
687   - {
688   - result->obj_infos[i].pb_alarm_state[ii] = true;
689   - result->obj_infos[i].pb_alarm_type[ii] = 3;
690   - return;
691   - }
692   - }
693   - else if (flag_c == 0 && flag_p == 1)
694   - {
695   - result->obj_infos[i].pb_alarm_state[ii] = true;
696   - result->obj_infos[i].pb_alarm_type[ii] = 3;
697   - return;
698   - }
699   - else if (flag_c == 0 && flag_p == 0)
700   - {
701   - if (dist_p <= dist_c)
702   - {
703   - result->obj_infos[i].pb_alarm_state[ii] = true;
704   - result->obj_infos[i].pb_alarm_type[ii] = 3;
705   - return;
706   - }
707   - }
708   -
709   - }
710   - else
711   - {
712   - if (flag_c == 0 && flag_p == 0)
713   - {
714   - if (dist_c <= dist_p)
715   - {
716   - result->obj_infos[i].pb_alarm_state[ii] = true;
717   - result->obj_infos[i].pb_alarm_type[ii] = 3;
718   - return;
719   - }
720   - }
721   - else if (flag_c == 1 && flag_p == 0)
722   - {
723   - result->obj_infos[i].pb_alarm_state[ii] = true;
724   - result->obj_infos[i].pb_alarm_type[ii] = 3;
725   - return;
726   - }
727   - else if (flag_c == 1 && flag_p == 1)
728   - {
729   - if (dist_p <= dist_c)
730   - {
731   - result->obj_infos[i].pb_alarm_state[ii] = true;
732   - result->obj_infos[i].pb_alarm_type[ii] = 3;
733   - return;
734   - }
735   - }
736   - }
737   - }
738   - else
739   - {
740   - double k, b;
741   - k = 0;
742   - b = (double)(region_infos[ii].p_roi[0].x_);
743   -
744   - double dist_c, dist_p;
745   -
746   - dist_c = fabs(result->obj_infos[i].trace.obj_trace[tar_size - 1].x_ - b);
747   - dist_p = fabs(point_x - b);
748   -
749   - if (abs(dist_c - dist_p) < 10)
750   - {
751   - int pre_index = tar_size - 5;
752   - while (pre_index >= 0)
753   - {
754   - point_x = result->obj_infos[i].trace.obj_trace[pre_index].x_;
755   - dist_p = fabs(point_x - b);
756   - pre_index = pre_index - 1;
757   - if (abs(dist_c - dist_p) >= 10)
758   - {
759   - break;
760   - }
761   - }
762   - }
763   -
764   - bool flag_c, flag_p;
765   - if (result->obj_infos[i].trace.obj_trace[tar_size - 1].x_ >= b)
766   - {
767   - flag_c = 1;
768   - }
769   - else
770   - {
771   - flag_c = 0;
772   - }
773   -
774   - if (point_x >= b)
775   - {
776   - flag_p = 1;
777   - }
778   - else
779   - {
780   - flag_p = 0;
781   - }
782   -
783   - if (abs(dist_c - dist_p) < 10)
784   - {
785   - result->obj_infos[i].pb_alarm_state[ii] = false;
786   - result->obj_infos[i].pb_alarm_type[ii] = 0;
787   - return;
788   - }
789   - //if (region_infos[ii].dir == 1)
790   - if (region_infos[ii].finaldir == 1) //by zl 20150914
791   - {
792   - if (flag_c * flag_p == 1)
793   - {
794   - if (dist_c <= dist_p)
795   - {
796   - result->obj_infos[i].pb_alarm_state[ii] = true;
797   - result->obj_infos[i].pb_alarm_type[ii] = 3;
798   - return;
799   - }
800   - }
801   - else if (flag_c == 0 && flag_p == 1)
802   - {
803   - result->obj_infos[i].pb_alarm_state[ii] = true;
804   - result->obj_infos[i].pb_alarm_type[ii] = 3;
805   - return;
806   - }
807   - else if (flag_c == 0 && flag_p == 0)
808   - {
809   - if (dist_p <= dist_c)
810   - {
811   - result->obj_infos[i].pb_alarm_state[ii] = true;
812   - result->obj_infos[i].pb_alarm_type[ii] = 3;
813   - return;
814   - }
815   - }
816   -
817   - }
818   - else
819   - {
820   - if (flag_c == 0 && flag_p == 0)
821   - {
822   - if (dist_c <= dist_p)
823   - {
824   - result->obj_infos[i].pb_alarm_state[ii] = true;
825   - result->obj_infos[i].pb_alarm_type[ii] = 3;
826   - return;
827   - }
828   - }
829   - else if (flag_c == 1 && flag_p == 0)
830   - {
831   - result->obj_infos[i].pb_alarm_state[ii] = true;
832   - result->obj_infos[i].pb_alarm_type[ii] = 3;
833   - return;
834   - }
835   - else if (flag_c == 1 && flag_p == 1)
836   - {
837   - if (dist_p <= dist_c)
838   - {
839   - result->obj_infos[i].pb_alarm_state[ii] = true;
840   - result->obj_infos[i].pb_alarm_type[ii] = 3;
841   - return;
842   - }
843   - }
844   - }
845   -
846   -
847   - }
848   - }
849   - }
850   - }
851   - }
852   - }
853   - }
854   - return;
855   -}
856   -
857   -void IRegionSurveillanceBase::TwoWayCrossBorder(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //双向越界
858   -{
859   - // 只要目标外接矩形有一个点进入区域则报警
860   - for (int ii = 0; ii < m_numROI; ii++) //区域
861   - {
862   - for (int i = 0; i < vptResult.objCount; ++i) //目标
863   - {
864   - for (int iy = vptResult.obj[i].top; iy <= vptResult.obj[i].bottom; iy++)
865   - {
866   - for (int ix = vptResult.obj[i].left; ix <= vptResult.obj[i].right; ix++)
867   - {
868   - if (pRegion[ii][GlobelWidth * iy + ix])
869   - {
870   - result->obj_infos[i].pb_alarm_state[ii] = true;
871   - result->obj_infos[i].pb_alarm_type[ii] = 4;
872   - }
873   - }
874   - }
875   - }
876   - }
877   - return;
878   -}
879   -
880   -void IRegionSurveillanceBase::WanderMonitoring(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //徘徊
881   -{
882   - for (int ii = 0; ii < m_numROI; ii++) //区域
883   - {
884   - for (int i = 0; i < vptResult.objCount; ++i) //目标
885   - {
886   - bool flag = 0;
887   - if ((pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].left] || \
888   - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].left] || \
889   - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].right] || \
890   - pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].right]) && (pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x]))
891   - {
892   - if (mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr == 0)
893   - {
894   - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr = 1;
895   - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0;
896   - }
897   - else
898   - {
899   - if (mp_stayinfo[ii][vptResult.obj[i].id].lastFrame <= 5)
900   - {
901   - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr++;
902   - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0;
903   - }
904   - else
905   - {
906   - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr = 0;
907   - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0;
908   -
909   - }
910   - }
911   - if (mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr >= region_infos[ii].frame_num)
912   - {
913   - result->obj_infos[i].pb_alarm_state[ii] = true;
914   - result->obj_infos[i].pb_alarm_type[ii] = 5;
915   - flag = 1;
916   - }
917   -
918   - }
919   - if (flag == 0)
920   - {
921   - result->obj_infos[i].pb_alarm_state[ii] = false;
922   - result->obj_infos[i].pb_alarm_type[ii] = 0;
923   -
924   - }
925   - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame++;
926   - }
927   - }
928   - return;
929   -}
930   -
931   -void IRegionSurveillanceBase::StayMonitoring(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result) //丢包
932   -{
933   - for (int ii = 0; ii < m_numROI; ii++) //区域
934   - {
935   - for (int i = 0; i < vptResult.objCount; ++i) //目标
936   - {
937   - int tar_size = result->obj_infos[i].trace.trace_num;
938   - int cur_dis;
939   - bool flag = 0;
940   - if (pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].left] || \
941   - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].left] || \
942   - pRegion[ii][GlobelWidth * vptResult.obj[i].top + vptResult.obj[i].right] || \
943   - pRegion[ii][GlobelWidth * vptResult.obj[i].bottom + vptResult.obj[i].right])
944   - {
945   - if (pRegion[ii][GlobelWidth * vptResult.obj[i].center_y + vptResult.obj[i].center_x])
946   - {
947   - if (mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr == 0)
948   - {
949   - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr = 1;
950   - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0;
951   - }
952   - else
953   - {
954   - if (tar_size >= 2)
955   - {
956   - 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_) +
957   - (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_);
958   - }
959   - else
960   - {
961   - cur_dis = 0;
962   - }
963   - if (mp_stayinfo[ii][vptResult.obj[i].id].lastFrame <= 5 && cur_dis <= tar_size * tar_size)
964   - {
965   - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr++;
966   - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0;
967   - }
968   - else
969   - {
970   - mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr = 0;
971   - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame = 0;
972   - }
973   - }
974   - if (mp_stayinfo[ii][vptResult.obj[i].id].nFrameCurr >= region_infos[ii].frame_num)
975   - {
976   - result->obj_infos[i].pb_alarm_state[ii] = true;
977   - result->obj_infos[i].pb_alarm_type[ii] = 6;
978   - }
979   - }
980   - }
981   - if (flag == 0)
982   - {
983   - result->obj_infos[i].pb_alarm_state[ii] = false;
984   - result->obj_infos[i].pb_alarm_type[ii] = 0;
985   - }
986   - mp_stayinfo[ii][vptResult.obj[i].id].lastFrame++;
987   - }
988   - }
989   - return;
990   -}
991   -
992   -int IRegionSurveillanceBase::rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result)
993   -{
994   -
995   - VPT_Result vptResult;
996   -
997   - detect(img_data, vptResult);
998   - for (int i = 0; i < vptResult.objCount; i++) //更新轨迹
999   - {
1000   - bool matching = false;
1001   - for (auto &item : vec_traceinfo)
1002   - {
1003   - if (item.id == vptResult.obj[i].id)
1004   - {
1005   - if (item.num < MAXTRACENUM)
1006   - {
1007   - ++item.num;
1008   - sy_point point;
1009   - point.x_ = vptResult.obj[i].center_x;
1010   - point.y_ = vptResult.obj[i].center_y;
1011   - item.trace_obj.push_back(point);
1012   - }
1013   - else
1014   - {
1015   - sy_point point;
1016   - point.x_ = vptResult.obj[i].center_x;
1017   - point.y_ = vptResult.obj[i].center_y;
1018   - item.trace_obj.push_back(point);
1019   - item.trace_obj.pop_front();
1020   - }
1021   - matching = true;
1022   - }
1023   - }
1024   - if (matching == false)
1025   - {
1026   - TraceInfo traceinf;
1027   - traceinf.id = vptResult.obj[i].id;
1028   - traceinf.num = 1;
1029   - sy_point point;
1030   - point.x_ = vptResult.obj[i].center_x;
1031   - point.y_ = vptResult.obj[i].center_y;
1032   - traceinf.trace_obj.push_back(point);
1033   - vec_traceinfo.push_back(traceinf);
1034   - }
1035   - }
1036   -
1037   -
1038   - result->obj_count = vptResult.objCount;
1039   - for (int i = 0; i < result->obj_count; i++)
1040   - {
1041   - memset(result->obj_infos[i].pb_alarm_state, 0, MAXROINUM * sizeof(bool));
1042   - memset(result->obj_infos[i].pb_alarm_type, 0, MAXROINUM * sizeof(int));
1043   - result->obj_infos[i].tar_box.left_ = vptResult.obj[i].left;
1044   - result->obj_infos[i].tar_box.top_ = vptResult.obj[i].top;
1045   - result->obj_infos[i].tar_box.width_ = vptResult.obj[i].right - vptResult.obj[i].left;
1046   - result->obj_infos[i].tar_box.height_ = vptResult.obj[i].bottom - vptResult.obj[i].top;
1047   -
1048   - result->obj_infos[i].curPos.x_ = vptResult.obj[i].center_x;
1049   - result->obj_infos[i].curPos.y_ = vptResult.obj[i].center_y;
1050   - result->obj_infos[i].unique_id = vptResult.obj[i].id;
1051   - for (auto &item : vec_traceinfo)
1052   - {
1053   - if (item.id == vptResult.obj[i].id)
1054   - {
1055   - result->obj_infos[i].trace.trace_num = item.num;
1056   - for (int j = 0; j < item.num; ++j)
1057   - {
1058   - result->obj_infos[i].trace.obj_trace[j] = item.trace_obj[j];
1059   - }
1060   - }
1061   - }
1062   -
1063   - }
1064   -
1065   - for (int i = 0; i < m_numROI; i++)
1066   - {
1067   - // 1进入禁区 2离开禁区 3单向越界 4双向越界 5徘徊 6丢包
1068   - switch (pAlarmInfo[i])
1069   - {
1070   - case 1:
1071   - AccessToRestrictedAreas(vptResult, region_infos, result); //进入禁区
1072   - break;
1073   - case 2:
1074   - LeaveTheRestrictedAreas(vptResult, region_infos, result); //离开禁区
1075   - break;
1076   - case 3:
1077   - OneWayCrossBorder(vptResult, region_infos, result); //单向越界
1078   - break;
1079   - case 4:
1080   - TwoWayCrossBorder(vptResult, region_infos, result); //双向越界
1081   - break;
1082   - case 5:
1083   - WanderMonitoring(vptResult, region_infos, result); //徘徊
1084   - break;
1085   - case 6:
1086   - StayMonitoring(vptResult, region_infos, result); //丢包
1087   - break;
1088   - default:
1089   - break;
1090   - }
1091   -
1092   - }
1093   - return 0;
1094   -}
1095 0 \ No newline at end of file
src/left_over/MSRegionSurveilanceBase.h deleted
1   -#pragma once
2   -#include "header.h"
3   -
4   -#include "RegionSurveillanceProcess.h"
5   -#include <fstream>
6   -#include "Sort.h"
7   -#include <map>
8   -#define MAX_OBJ_COUNT 100
9   -struct TaskTracker
10   -{
11   - int TaskID;
12   - double ratioWidth;
13   - double ratioHeight;
14   - Sort tracker;
15   -};
16   -
17   -typedef struct VPT_Result
18   -{
19   - int objCount;
20   - VPT_ObjInfo obj[MAX_OBJ_COUNT];
21   -}VPT_Result;
22   -
23   -class IRegionSurveillanceBase : public RegionSurveillanceProcess {
24   -public:
25   - IRegionSurveillanceBase();
26   -
27   - // 模型初始化
28   - virtual int rs_init(const rs_param & param) override;
29   - // ROI区域初始化
30   - virtual int rs_init_region(int numROI, region_info* region_infos, bool iflog) override;
31   - //// 每一帧图像检测
32   - int rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result)override;
33   - ////计算方向和箭头绘制的两个端点
34   - virtual int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) override;
35   -protected:
36   - void vibeMask(int num, sy_point *pPointList, bool *pRegion);
37   - void printAlarmType(std::fstream *file, int style);
38   - void AddTaskTracker(const int taskID, const double rWidth, const double rHeight);
39   -/***************************************处理函数**********************************************************/
40   - void AccessToRestrictedAreas(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //进入禁区
41   - void LeaveTheRestrictedAreas(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //离开禁区
42   - void OneWayCrossBorder(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //单向越界
43   - void TwoWayCrossBorder(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //双向越界
44   - void WanderMonitoring(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //徘徊
45   - void StayMonitoring(const VPT_Result & vptResult, const region_info* region_infos, rs_result *result); //丢包
46   -/**********************************************************************************************************/
47   - virtual int init(const rs_param & param) = 0; //回调子类初始化模块
48   - virtual int detect(const sy_img &img_data, VPT_Result & vptResult) = 0; //回调子类获取人车物检测,头肩检测信息 //回调子类人车物检测或头肩检测
49   - virtual void release() = 0; //回调子类用于释放
50   -private:
51   -
52   - void RSrelease();
53   -protected:
54   - struct TraceInfo
55   - {
56   - unsigned int id; //目标唯一id
57   - unsigned int num; //目标轨迹长度
58   - std::deque<sy_point> trace_obj; //目标轨迹点集合
59   - };
60   - std::vector<TraceInfo> vec_traceinfo;
61   - struct StayInfo
62   - {
63   - long nFrameCurr; // 记录当前逗留帧数
64   - int lastFrame; // 上次监测到逗留距离当前的帧数
65   - };
66   - std::map<unsigned int, std::map<unsigned int, StayInfo>> mp_stayinfo; //区域索引, 目标唯一id, 目标逗留帧数
67   - int GlobelWidth = 0;
68   - int GlobelHeight = 0;
69   - TaskTracker taskTrackers;
70   - sy_point pStart, pEnd; //by zl 用于存储可通行方向箭头的两个端点
71   - int m_numROI = 0;
72   - bool** pRegion;
73   - int* pAlarmInfo;
74   -private:
75   -
76   -
77   -};
src/left_over/MSRegionSurveilanceCpu.cpp
1 1 #include "MSRegionSurveilanceCpu.h"
2 2 #include "head.h"
  3 +#include <opencv2/opencv.hpp>
  4 +#include <opencv2/opencv.hpp>
  5 +#include <opencv2/core/core.hpp>
  6 +#include <opencv2/highgui/highgui_c.h>
  7 +
  8 +bool Screenshot(IplImage* src, IplImage* dst, sy_rect t)
  9 +{
  10 +
  11 + CvRect rect;
  12 + rect.x = t.left_;
  13 + rect.y = t.top_;
  14 + rect.width = t.width_;
  15 + rect.height = t.height_;
  16 + cvSetImageROI(src, rect);
  17 + cvCopy(src, dst, 0);
  18 + cvResetImageROI(src);
  19 + //cvNamedWindow("Image", 1);//创建窗口
  20 + //cvShowImage("Image", dst);//显示图像
  21 + //cvWaitKey(0); //等待按键
  22 + return 0;
  23 +}
3 24 int IRegionSurveillanceCpu::rs_init(const rs_params &param)
4 25 {
5   - return IReginCpu->RSinit(param.image.w_, param.image.h_, param.image.w_,
6   - (unsigned char*)(param.image.data_), 1/*param.image.c_*/, 1/*param.channel_deal*/, param.filt_flag, param.min_area, param.max_area);
  26 + int r = 0;
  27 + IplImage * gray = cvCreateImage(cvSize(param.image.w_, param.image.h_), 8, 1);
  28 + cvSetData(gray, param.image.data_, param.image.w_);
  29 + for (int i = 0; i < rect_num; ++i)
  30 + {
  31 + IplImage * img = cvCreateImage(cvSize(rect[i].width_, rect[i].height_), 8, 1);
  32 + Screenshot(gray, img, rect[i]);
  33 + //cv::Mat roi_img = cv::src_img(Range(0, 100), Range(50, 200));
  34 + r = IReginCpu[i]->RSinit(img->width, img->height, img->width,
  35 + (unsigned char*)(img->imageData), 1/*param.image.c_*/, 1/*param.channel_deal*/, param.filt_flag, param.min_area, param.max_area);
  36 + cvReleaseImage(&img);
  37 + }
  38 + //cvReleaseImage(&gray);
  39 + return r;
7 40 }
8 41 int IRegionSurveillanceCpu::rs_init_region(int num_roi, region_info* region_infos/*, bool iflog*/)
9 42 {
... ... @@ -24,7 +57,12 @@ int IRegionSurveillanceCpu::rs_init_region(int num_roi, region_info* region_info
24 57 //reginifos.ArrowStartPoint.y = region_infos->arrow_start_point.y_;
25 58 //reginifos.ArrowEndPoint.x = region_infos->arrow_end_point.x_; //箭头的终止端点 箭头指向正方形
26 59 //reginifos.ArrowEndPoint.y = region_infos->arrow_end_point.y_; //箭头的终止端点 箭头指向正方形
27   - return IReginCpu->RSRegion(num_roi, region_infos->alarm_info/*, iflog*/);
  60 + int r = 0;
  61 + for (int i = 0; i < rect_num; ++i)
  62 + {
  63 + r = IReginCpu[i]->RSRegion(num_roi, region_infos->alarm_info/*, iflog*/);
  64 + }
  65 + return r;
28 66 }
29 67 int IRegionSurveillanceCpu::rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result)
30 68 {
... ... @@ -45,75 +83,93 @@ int IRegionSurveillanceCpu::rs_detect(const sy_img &amp;img_data, region_info* regio
45 83 //reginifos.ArrowStartPoint.y = region_infos->arrow_start_point.y_;
46 84 //reginifos.ArrowEndPoint.x = region_infos->arrow_end_point.x_; //箭头的终止端点 箭头指向正方形
47 85 //reginifos.ArrowEndPoint.y = region_infos->arrow_end_point.y_; //箭头的终止端点 箭头指向正方形
48   - IReginCpu->RSDetect((unsigned char*)(img_data.data_), &reginifos);
49   - auto ObjCount = IReginCpu->getObjectNum();
50   - result->obj_count = ObjCount;
51   - auto * ObjInfo = new MS_ObjectInfo[ObjCount];
52   - IReginCpu->getObjectInfo(ObjCount, ObjInfo);
53   - for (int i = 0; i < ObjCount; ++i)
54   - {
55   - result->obj_infos[i].curPos.x_ = ObjInfo[i].curPos.x; // 当前坐标
56   - result->obj_infos[i].curPos.y_ = ObjInfo[i].curPos.y; // 当前坐标
57 86  
58   - result->obj_infos[i].trace.trace_num = ObjInfo[i].trace.nTraceNum; // 轨迹及报警状态
59   - for (int j = 0; j < MAXTRACENUM; ++j)
60   - {
61   - result->obj_infos[i].trace.obj_trace[j].x_ = ObjInfo[i].trace.pObjTrace[j].x;
62   - result->obj_infos[i].trace.obj_trace[j].y_ = ObjInfo[i].trace.pObjTrace[j].y;
63   - }
64 87  
65   - result->obj_infos[i].unique_id = ObjInfo[i].UniqueID; // 当前目标的特点ID
66   - result->obj_infos[i].tar_box.left_ = ObjInfo[i].TarBox.left; // 目标外接矩形
67   - result->obj_infos[i].tar_box.top_ = ObjInfo[i].TarBox.top;
68   - result->obj_infos[i].tar_box.height_ = ObjInfo[i].TarBox.Height();
69   - result->obj_infos[i].tar_box.width_ = ObjInfo[i].TarBox.Width();
70   - for (int j = 0; j < MAXROINUM; ++j)
71   - {
72   - result->obj_infos[i].pb_alarm_state[j] = ObjInfo[i].pbAlarmState[j];
73   - result->obj_infos[i].pb_alarm_type[j] = ObjInfo[i].pbAlarmType[j];
74   - }
75   - }
76   - delete ObjInfo;
77   - auto delCount = IReginCpu->getDeleteNum();
78   - result->del_count = delCount;
79   - auto * DelInfo = new MS_ObjectInfo[delCount];
80   - IReginCpu->getDeleteInfo(delCount, DelInfo);
81   - for (int i = 0; i < delCount; ++i)
  88 + int totalObjCount = 0;
  89 + int totalDelCount = 0;
  90 + IplImage * gray = cvCreateImage(cvSize(img_data.w_, img_data.h_), 8, 1);
  91 + cvSetData(gray, img_data.data_, img_data.w_);
  92 + for (int k = 0; k < rect_num; ++k)
  93 + //int k = 0;
82 94 {
83   - result->del_infos[i].curPos.x_ = DelInfo[i].curPos.x; // 当前坐标
84   - result->del_infos[i].curPos.y_ = DelInfo[i].curPos.y; // 当前坐标
  95 + IplImage * img = cvCreateImage(cvSize(rect[k].width_, rect[k].height_), 8, 1);
  96 + Screenshot(gray, img, rect[k]);
  97 + //cv::Mat roi_img = cv::src_img(Range(0, 100), Range(50, 200));
  98 + IReginCpu[k]->RSDetect((unsigned char*)(img->imageData), &reginifos);
  99 + auto ObjCount = IReginCpu[k]->getObjectNum();
85 100  
86   - result->del_infos[i].trace.trace_num = DelInfo[i].trace.nTraceNum; // 轨迹及报警状态
87   - for (int j = 0; j < MAXTRACENUM; ++j)
  101 + auto * ObjInfo = new MS_ObjectInfo[ObjCount];
  102 + IReginCpu[k]->getObjectInfo(ObjCount, ObjInfo);
  103 + for (int i = 0; i < ObjCount; ++i)
88 104 {
89   - result->del_infos[i].trace.obj_trace[j].x_ = DelInfo[i].trace.pObjTrace[j].x;
90   - result->del_infos[i].trace.obj_trace[j].y_ = DelInfo[i].trace.pObjTrace[j].y;
  105 + result->obj_infos[totalObjCount].curPos.x_ = ObjInfo[i].curPos.x+rect[k].left_; // 当前坐标
  106 + result->obj_infos[totalObjCount].curPos.y_ = ObjInfo[i].curPos.y+rect[k].top_; // 当前坐标
  107 +
  108 + result->obj_infos[totalObjCount].trace.trace_num = ObjInfo[i].trace.nTraceNum; // 轨迹及报警状态
  109 + for (int j = 0; j < MAXTRACENUM; ++j)
  110 + {
  111 + result->obj_infos[totalObjCount].trace.obj_trace[j].x_ = ObjInfo[i].trace.pObjTrace[j].x+rect[k].left_;
  112 + result->obj_infos[totalObjCount].trace.obj_trace[j].y_ = ObjInfo[i].trace.pObjTrace[j].y+rect[k].top_;
  113 + }
  114 +
  115 + result->obj_infos[totalObjCount].unique_id = ObjInfo[i].UniqueID; // 当前目标的特点ID
  116 + result->obj_infos[totalObjCount].tar_box.left_ = ObjInfo[i].TarBox.left+rect[k].left_; // 目标外接矩形
  117 + result->obj_infos[totalObjCount].tar_box.top_ = ObjInfo[i].TarBox.top+rect[k].top_;
  118 + result->obj_infos[totalObjCount].tar_box.height_ = ObjInfo[i].TarBox.Height();
  119 + result->obj_infos[totalObjCount].tar_box.width_ = ObjInfo[i].TarBox.Width();
  120 + for (int j = 0; j < MAXROINUM; ++j)
  121 + {
  122 + result->obj_infos[totalObjCount].pb_alarm_state[j] = ObjInfo[i].pbAlarmState[j];
  123 + result->obj_infos[totalObjCount].pb_alarm_type[j] = ObjInfo[i].pbAlarmType[j];
  124 + }
  125 + ++totalObjCount;
91 126 }
  127 +
  128 + delete ObjInfo;
  129 + auto delCount = IReginCpu[k]->getDeleteNum();
92 130  
93   - result->del_infos[i].unique_id = DelInfo[i].UniqueID; // 当前目标的特点ID
94   - result->del_infos[i].tar_box.left_ = DelInfo[i].TarBox.left; // 目标外接矩形
95   - result->del_infos[i].tar_box.top_ = DelInfo[i].TarBox.top;
96   - result->del_infos[i].tar_box.height_ = DelInfo[i].TarBox.Height();
97   - result->del_infos[i].tar_box.width_ = DelInfo[i].TarBox.Width();
98   - for (int j = 0; j < MAXROINUM; ++j)
  131 + auto * DelInfo = new MS_ObjectInfo[delCount];
  132 + IReginCpu[k]->getDeleteInfo(delCount, DelInfo);
  133 + for (int i = 0; i < delCount; ++i)
99 134 {
100   - result->del_infos[i].pb_alarm_state[j] = DelInfo[i].pbAlarmState[j];
101   - result->del_infos[i].pb_alarm_type[j] = DelInfo[i].pbAlarmType[j];
  135 + result->del_infos[totalDelCount].curPos.x_ = DelInfo[i].curPos.x + rect[k].left_; // 当前坐标
  136 + result->del_infos[totalDelCount].curPos.y_ = DelInfo[i].curPos.y + rect[k].top_; // 当前坐标
  137 +
  138 + result->del_infos[totalDelCount].trace.trace_num = DelInfo[i].trace.nTraceNum; // 轨迹及报警状态
  139 + for (int j = 0; j < MAXTRACENUM; ++j)
  140 + {
  141 + result->del_infos[totalDelCount].trace.obj_trace[j].x_ = DelInfo[i].trace.pObjTrace[j].x + rect[k].left_;
  142 + result->del_infos[totalDelCount].trace.obj_trace[j].y_ = DelInfo[i].trace.pObjTrace[j].y + rect[k].top_;
  143 + }
  144 +
  145 + result->del_infos[totalDelCount].unique_id = DelInfo[i].UniqueID; // 当前目标的特点ID
  146 + result->del_infos[totalDelCount].tar_box.left_ = DelInfo[i].TarBox.left + rect[k].left_; // 目标外接矩形
  147 + result->del_infos[totalDelCount].tar_box.top_ = DelInfo[i].TarBox.top + rect[k].top_;
  148 + result->del_infos[totalDelCount].tar_box.height_ = DelInfo[i].TarBox.Height();
  149 + result->del_infos[totalDelCount].tar_box.width_ = DelInfo[i].TarBox.Width();
  150 + for (int j = 0; j < MAXROINUM; ++j)
  151 + {
  152 + result->del_infos[totalDelCount].pb_alarm_state[j] = DelInfo[i].pbAlarmState[j];
  153 + result->del_infos[totalDelCount].pb_alarm_type[j] = DelInfo[i].pbAlarmType[j];
  154 + }
  155 + ++totalDelCount;
102 156 }
  157 + delete DelInfo;
103 158 }
104   - delete DelInfo;
  159 + result->obj_count = totalObjCount;
  160 + result->del_count = totalDelCount;
105 161 return 1;
106 162 }
107   -int IRegionSurveillanceCpu::rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir)
108   -{
109   - CMPoint pROI0;
110   - pROI0.x = p_roi0.x_;
111   - pROI0.y = p_roi0.y_;
112   - CMPoint pROI1;
113   - pROI1.x = p_roi1.x_;
114   - pROI1.y = p_roi1.y_;
115   - CMPoint pdir;
116   - pdir.x = dir.x_;
117   - pdir.y = dir.y_;
118   - return IReginCpu->get_ArrowDir(pROI0, pROI1, pdir);
119   -}
120 163 \ No newline at end of file
  164 +//int IRegionSurveillanceCpu::rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir)
  165 +//{
  166 +// CMPoint pROI0;
  167 +// pROI0.x = p_roi0.x_;
  168 +// pROI0.y = p_roi0.y_;
  169 +// CMPoint pROI1;
  170 +// pROI1.x = p_roi1.x_;
  171 +// pROI1.y = p_roi1.y_;
  172 +// CMPoint pdir;
  173 +// pdir.x = dir.x_;
  174 +// pdir.y = dir.y_;
  175 +// return IReginCpu->get_ArrowDir(pROI0, pROI1, pdir);
  176 +//}
121 177 \ No newline at end of file
... ...
src/left_over/MSRegionSurveilanceCpu.h
... ... @@ -7,18 +7,26 @@ class IRegionSurveillanceCpu: public RegionSurveillanceProcess {
7 7 public:
8 8 IRegionSurveillanceCpu()
9 9 {
10   - IReginCpu = MS1.GetMS_RS();
  10 + for(int i = 0; i < MAXVERTEXNUM; ++i )
  11 + IReginCpu[i] = MS1.GetMS_RS();
11 12 };
12 13 ~IRegionSurveillanceCpu()
13 14 {
14   - IReginCpu->RSrelease();
15   - MS1.Destroy();
  15 + for (int i = 0; i < MAXVERTEXNUM; ++i)
  16 + {
  17 + IReginCpu[i]->RSrelease();
  18 + delete IReginCpu[i];
  19 + }
  20 +
  21 + //MS1.Destroy();
16 22 };
17 23 int rs_init(const rs_params &param);
18 24 int rs_init_region(int num_roi, region_info* region_infos/*, bool iflog*/);
19 25 int rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result);
20   - int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir);
  26 + //int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir);
21 27 private:
22 28 MS_RegionSurveillance MS1;
23   - IRegionSurveillance * IReginCpu;
  29 + IRegionSurveillance * IReginCpu[MAXVERTEXNUM];
  30 +
  31 +
24 32 };
25 33 \ No newline at end of file
... ...
src/left_over/MSRegionSurveilanceHst.cpp deleted
1   -#include "MSRegionSurveilanceHst.h"
2   -#include "head_shoulder_det.h"
3   -#include "sy_errorinfo.h"
4   -#include <cuda.h>
5   -#include <cuda_runtime.h>
6   -
7   -
8   -int IRegionSurveillanceHst::init(const rs_param & param)
9   -{
10   - hs_det_param hsparam;
11   - hsparam.gpuid = 0;
12   - hsparam.mode = DEVICE_GPU;
13   - hsparam.thresld = 0.5;
14   - hsparam.engine = ENGINE_MCAFFE2;
15   - hsparam.max_batch = 10;
16   - hsparam.trt_serialize_file = "HSD";
17   - if (hs_det_init(&hst_handle, &hsparam))
18   - {
19   - printf("hs_det_init failed!\n");
20   - return VPT_DET_INIT_ERROR;
21   - }
22   - printf("finish init hst\n");
23   - AddTaskTracker(0, 1, 1);
24   - return 0;
25   -}
26   -
27   -int IRegionSurveillanceHst::detect(const sy_img &img_data, VPT_Result & vptResult)
28   -{
29   - vector<int> deleteObjectID;
30   - hs_det_result * hsresult = new hs_det_result{};
31   - hsresult->objcount = 0;
32   - sy_img batch_img_gpu;
33   - unsigned char * data = NULL;
34   - cudaMalloc(&data, img_data.w_ *img_data.h_*img_data.c_ * sizeof(unsigned char));
35   - cudaMemcpy(data, img_data.data_, img_data.w_ *img_data.h_ * img_data.c_ * sizeof(unsigned char), cudaMemcpyHostToDevice);
36   - batch_img_gpu.set_data(img_data.w_, img_data.h_, img_data.c_, data);
37   - auto ret = hs_det_process_batch(hst_handle, &batch_img_gpu, 1, hsresult);
38   - cudaFree(data);
39   - std::vector<std::vector<float>> detectResult;
40   - for (int c = 0; c < hsresult->objcount&& c < MAX_OBJ_COUNT; c++)
41   - {
42   - vector <float> obj;
43   -
44   - obj.push_back(hsresult->objinfo[c].left);
45   - obj.push_back(hsresult->objinfo[c].top);
46   - obj.push_back(hsresult->objinfo[c].right);
47   - obj.push_back(hsresult->objinfo[c].bottom);
48   - obj.push_back(hsresult->objinfo[c].confidence);
49   - obj.push_back(0);
50   - detectResult.push_back(obj);
51   - }
52   -
53   - 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);
54   - vptResult.objCount = objCount;
55   - delete hsresult;
56   - return ret;
57   -}
58   -
59   -void IRegionSurveillanceHst::release()
60   -{
61   - //1.VPT RELEASE
62   - if (hst_handle)
63   - {
64   - hs_det_release(&hst_handle);
65   - hst_handle = NULL;
66   - }
67   -}
68 0 \ No newline at end of file
src/left_over/MSRegionSurveilanceHst.h deleted
1   -#pragma once
2   -#include "MSRegionSurveilanceBase.h"
3   -
4   -
5   -class IRegionSurveillanceHst : public IRegionSurveillanceBase {
6   -public:
7   -
8   -
9   -private:
10   -
11   - virtual int init(const rs_param & param) override;
12   - virtual int detect(const sy_img &img_data, VPT_Result & vptResult) override;
13   - virtual void release() override;
14   -
15   -private:
16   - void * hst_handle;
17   -
18   -
19   -};
src/left_over/MSRegionSurveilanceVpt.cpp deleted
1   -#include "MSRegionSurveilanceVpt.h"
2   -#include "vpt.h"
3   -#include "sy_errorinfo.h"
4   -#include <cuda.h>
5   -#include <cuda_runtime.h>
6   -
7   -
8   -
9   -
10   -
11   -
12   -
13   -
14   -int IRegionSurveillanceVpt::init(const rs_param & param)
15   -{
16   - vpt_param vptparam;
17   - vptparam.mode = DEVICE_GPU;
18   - vptparam.gpuid = 0;
19   - vptparam.threshold = 0.6;
20   - vptparam.engine = ENGINE_TENSORRT;
21   - vptparam.preprocess_param =
22   - "CopyData_CPU2GPU_U8;"
23   - "TypeConvert_U8_F32;"
24   - "ResizePad_F32_F32,test_size,720,test_max_size,1280,fpn_coarsest_stride,32,"
25   - "submean_b,103.94,submean_g,116.78,submean_r,123.68,"
26   - "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;"
27   - "NHWC2NCHW_F32"
28   - ;
29   - vptparam.serialize_file = "FPN_VPT";
30   - vptparam.max_batch = 20;
31   - if (vpt_init(&vpt_handle, vptparam) != 0)
32   - {
33   - printf("vpt_init failed!\n");
34   - return VPT_DET_INIT_ERROR;
35   - }
36   - printf("finish init vpt\n");
37   - AddTaskTracker(0, 1, 1);
38   - return 0;
39   -}
40   -
41   -
42   -
43   -
44   -
45   -
46   -int IRegionSurveillanceVpt::detect(const sy_img &img_data, VPT_Result & vptResult)
47   -{
48   - vector<int> deleteObjectID;
49   - vpt_result * vptresult = new vpt_result{};
50   - vptresult->obj_count_ = 0;
51   - vptresult->obj_results_ = new vpt_obj_result[MAX_DET_COUNT];
52   - sy_img batch_img_gpu;
53   - unsigned char * data = NULL;
54   - cudaMalloc(&data, img_data.w_ *img_data.h_*img_data.c_ * sizeof(unsigned char));
55   - cudaMemcpy(data, img_data.data_, img_data.w_ *img_data.h_ * img_data.c_ * sizeof(unsigned char), cudaMemcpyHostToDevice);
56   - batch_img_gpu.set_data(img_data.w_, img_data.h_, img_data.c_, data);
57   - auto ret = vpt_batch(vpt_handle, &batch_img_gpu, 1, &vptresult);
58   - cudaFree(data);
59   - std::vector<std::vector<float>> detectResult;
60   - for (int c = 0; c < vptresult->obj_count_&& c < MAX_OBJ_COUNT; c++)
61   - {
62   - vector <float> obj;
63   -
64   - obj.push_back(vptresult->obj_results_[c].obj_rect.left_);
65   - obj.push_back(vptresult->obj_results_[c].obj_rect.top_);
66   - obj.push_back(vptresult->obj_results_[c].obj_rect.left_ + vptresult->obj_results_[c].obj_rect.width_);
67   - obj.push_back(vptresult->obj_results_[c].obj_rect.top_ + vptresult->obj_results_[c].obj_rect.height_);
68   - obj.push_back(vptresult->obj_results_[c].obj_score);
69   - obj.push_back(vptresult->obj_results_[c].obj_index);
70   - detectResult.push_back(obj);
71   - }
72   -
73   - 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);
74   - vptResult.objCount = objCount;
75   - delete[] vptresult->obj_results_;
76   - delete vptresult;
77   - return ret;
78   -}
79   -
80   -
81   -
82   -
83   -void IRegionSurveillanceVpt::release()
84   -{
85   -
86   - //1.VPT RELEASE
87   - if (vpt_handle)
88   - {
89   - vpt_release(&vpt_handle);
90   - vpt_handle = NULL;
91   - }
92   -
93   -}
94 0 \ No newline at end of file
src/left_over/MSRegionSurveilanceVpt.h deleted
1   -#pragma once
2   -#include "MSRegionSurveilanceBase.h"
3   -
4   -
5   -class IRegionSurveillanceVpt : public IRegionSurveillanceBase {
6   -public:
7   -
8   -
9   -private:
10   - virtual int detect(const sy_img &img_data, VPT_Result & vptResult) override;
11   - virtual int init(const rs_param & param) override;
12   - virtual void release() override;
13   -
14   -private:
15   - void * vpt_handle;
16   -
17   -
18   -};
src/left_over/RegionSurveillanceProcess.h
... ... @@ -35,17 +35,19 @@ public:
35 35 virtual int rs_init(const rs_params &param) = 0;
36 36 virtual int rs_init_region(int num_roi, region_info* region_infos/*, bool iflog*/) = 0;
37 37 virtual int rs_detect(const sy_img &img_data, region_info* region_infos, rs_result *result) = 0;
38   - virtual int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) = 0;
  38 + //virtual int rs_get_arrowdir(const sy_point &p_roi0, const sy_point &p_roi1, const sy_point &dir) = 0;
39 39 void* handle;
40 40 int licence_status = -1;
41 41 int thrd_status = -1;
42   - int long_side;
43   - int short_side;
  42 + double scale;
  43 + //int long_side;
  44 + //int short_side;
44 45 std::atomic<bool> thrd_run;
45 46 boost::thread thrd;
46 47 long frame_num = 0;
47 48 bool init_flag = false;
48   - double scale;
  49 + sy_rect rect[MAXVERTEXNUM]; //有效区域
  50 + unsigned char rect_num; //有效区域数量
49 51 private:
50 52 //int mode; //运行模式0 cpu
51 53 //MS_RegionSurveillance MS1;
... ...
src/left_over/helper.cpp
... ... @@ -63,8 +63,8 @@ void RegionSurveillance::RandNeighborInit(int32_t width, int32_t height)
63 63 {
64 64 g_YTable[i + 1] = i;
65 65 }
66   - g_XTable[0] = 0; //1
67   - g_XTable[height + 1] = height - 1;
  66 + g_YTable[0] = 0; //1
  67 + g_YTable[height + 1] = height - 1;
68 68 }
69 69 }
70 70  
... ... @@ -72,13 +72,13 @@ void RegionSurveillance::GetRandNeighborXY(int32_t x, int32_t y, int32_t *_x, in
72 72 {
73 73 uint32_t r = GetRand() & 0x07;
74 74 *_x = g_XTable[x + g_XNeighborTable[r]];
75   - *_y = g_XTable[y + g_YNeighborTable[r]];
  75 + *_y = g_YTable[y + g_YNeighborTable[r]];
76 76 }
77 77  
78 78 void RegionSurveillance::GetNeighborXY(int32_t x, int32_t y, int32_t *_x, int32_t *_y, int32_t flag)
79 79 {
80 80 *_x = g_XTable[x + g_XNeighborTable[flag]];
81   - *_y = g_XTable[y + g_YNeighborTable[flag]];
  81 + *_y = g_YTable[y + g_YNeighborTable[flag]];
82 82 }
83 83  
84 84 void RegionSurveillance::FreeRandNeighbor()
... ...
src/left_over/left_over_det.h
... ... @@ -24,8 +24,8 @@
24 24 #define m_BOUNDING_BOX_RATEMIN 0.001
25 25 #define m_BOUNDING_BOX_RATEMAX 100
26 26 #define MAXROINUM 10 // 最大ROI数
27   -//#define MACDETECTOBJNUM 100
28   -#define MACDETECTOBJNUM 3
  27 +#define MACDETECTOBJNUM 10
  28 +
29 29 #ifdef __cplusplus
30 30 extern "C"
31 31 {
... ... @@ -33,14 +33,25 @@ extern &quot;C&quot;
33 33  
34 34 #ifndef __RS_PARAM__
35 35 #define __RS_PARAM__
36   -
37   -
  36 +#ifndef __SY_RECT__
  37 +#define __SY_RECT__
  38 + typedef struct sy_rect
  39 + {
  40 + int left_;
  41 + int top_;
  42 + int width_;
  43 + int height_;
  44 + 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) {};
  45 + sy_rect() {};
  46 + } sy_rect;
  47 +#endif
  48 +#define MAXVERTEXNUM 10
38 49 typedef struct rs_param
39 50 {
40 51 long frame_num; // 逗留时间 单位帧数
41   - int long_side;
42   - int short_side;
43   -
  52 + double scale; //缩小比例
  53 + sy_rect rect[MAXVERTEXNUM]; //有效区域
  54 + unsigned char rect_num; //有效区域数量
44 55 }rs_param;
45 56 #endif
46 57  
... ...
src/left_over/ms_region_surveilance.cpp
... ... @@ -2,9 +2,10 @@
2 2 #include "RegionSurveillanceProcess.h"
3 3 #include "MSRegionSurveilanceCpu.h"
4 4 #include <thread>
  5 +#include <ctime>
5 6 #include <chrono>
6 7 #include "head.h"
7   -#include "authority.h"
  8 +//#include "authority.h"
8 9 #include "sy_errorinfo.h"
9 10 #include <opencv2/opencv.hpp>
10 11 #ifdef _MSC_VER
... ... @@ -16,100 +17,172 @@
16 17  
17 18  
18 19  
19   -void check_thread(RegionSurveillanceProcess* handle)
  20 +//void check_thread(RegionSurveillanceProcess* handle)
  21 +//{
  22 +// int res = -1;
  23 +//#ifdef __linux__
  24 +// char* wtime = new char[15];
  25 +// memset(wtime, 0, 15);
  26 +//#endif
  27 +// while (1)
  28 +// {
  29 +// //printf("xxx check status on process...\n");
  30 +//#ifdef _WIN32
  31 +// res = sy_licence(productSN);
  32 +//#elif __linux__
  33 +// res = sy_licence(productSN, &wtime);
  34 +// //printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status);
  35 +//#endif
  36 +// if (res < 0)
  37 +// {
  38 +// handle->licence_status = handle->licence_status - 1;
  39 +// }
  40 +// else
  41 +// {
  42 +// if (handle->licence_status < 0)
  43 +// {
  44 +// handle->licence_status = 0;
  45 +// }
  46 +// }
  47 +// boost::this_thread::sleep(boost::posix_time::seconds(300)); //5min
  48 +// }
  49 +//#ifdef __linux__
  50 +// if (wtime)
  51 +// {
  52 +// delete[] wtime;
  53 +// wtime = NULL;
  54 +// }
  55 +//#endif
  56 +//}
  57 +#define RESIZE_SCALE 0.5
  58 +inline std::chrono::system_clock::time_point makeTimePoint(int year, int mon, int day)
20 59 {
21   - int res = -1;
22   -#ifdef __linux__
23   - char* wtime = new char[15];
24   - memset(wtime, 0, 15);
25   -#endif
26   - while (1)
  60 + std::tm t;
  61 + t.tm_year = year - 1900;
  62 + t.tm_mon = mon - 1;
  63 + t.tm_mday = day;
  64 + t.tm_hour = 0;
  65 + t.tm_min = 0;
  66 + t.tm_sec = 0;
  67 + t.tm_isdst = -1;
  68 + std::time_t tt = std::mktime(&t);
  69 + if (tt == -1)
27 70 {
28   - //printf("xxx check status on process...\n");
29   -#ifdef _WIN32
30   - res = sy_licence(productSN);
31   -#elif __linux__
32   - res = sy_licence(productSN, &wtime);
33   - //printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status);
34   -#endif
35   - if (res < 0)
36   - {
37   - handle->licence_status = handle->licence_status - 1;
38   - }
39   - else
40   - {
41   - if (handle->licence_status < 0)
42   - {
43   - handle->licence_status = 0;
44   - }
45   - }
46   - boost::this_thread::sleep(boost::posix_time::seconds(300)); //5min
  71 + exit(-1);
  72 + }
  73 + return std::chrono::system_clock::from_time_t(tt);
  74 +}
  75 +
  76 +inline bool timecheck()
  77 +{
  78 + std::chrono::system_clock::time_point limitTime = makeTimePoint(2020, 12, 31);
  79 + std::chrono::system_clock::time_point nowTime = std::chrono::system_clock::now();
  80 + if (nowTime > limitTime)
  81 + {
  82 + return false;
47 83 }
48   -#ifdef __linux__
49   - if (wtime)
  84 + else
50 85 {
51   - delete[] wtime;
52   - wtime = NULL;
  86 + return true;
53 87 }
54   -#endif
55 88 }
56   -
57   -
58 89 int rs_init(void **handle, rs_param param)
59 90 {
60 91 int ret = SUCCESS;
61   -#ifdef AUTHORIZATION
62   -#ifdef _WIN32
63   - if (SUCCESS == (ret = sy_licence(productSN)))
64   -#elif __linux__
65   - char* wtime = new char[15];
66   - memset(wtime, 0, 15);
67   - if (SUCCESS == (ret = sy_licence(productSN, &wtime)))
68   -#endif
69   -#else
70   - ret = sy_time_check(2022, 1);
71   - if (ret == SUCCESS)
72   -#endif
  92 +
  93 + if (timecheck())
73 94 {
74 95  
75 96 RegionSurveillanceProcess* regin = nullptr;
76 97 //if (param.mode == 0)
77   - regin = new IRegionSurveillanceCpu;
78   - regin->frame_num = param.frame_num;
  98 + regin = new IRegionSurveillanceCpu;
  99 + regin->frame_num = param.frame_num;
79 100 if (!regin)
80 101 {
81 102 printf("model initial failed \n");
82 103 return -1;
83 104 }
84   -
85 105  
86   - regin->long_side = param.long_side;
87   - regin->short_side = param.short_side;
  106 +
  107 + /* regin->long_side = param.long_side;
  108 + regin->short_side = param.short_side;*/
88 109 regin->licence_status = 0;
89   -#ifdef AUTHORIZATION
90   - regin->thrd_run = true;
91   - regin->thrd = boost::thread(check_thread, regin);
92   -#endif
  110 +
93 111 regin->thrd_status = 0;
94   - *handle = regin;
95   -#ifdef AUTHORIZATION
96   -#ifdef __linux__
97   - if (wtime)
  112 + regin->scale = param.scale;
  113 + regin->rect_num = param.rect_num; //有效区域数量
  114 + for (int i = 0; i < regin->rect_num; ++i)
98 115 {
99   - delete[] wtime;
100   - wtime = NULL;
  116 + regin->rect[i].left_ = param.rect[i].left_ / param.scale;
  117 + regin->rect[i].top_ = param.rect[i].top_ / param.scale;
  118 + regin->rect[i].width_ = param.rect[i].width_ / param.scale;
  119 + regin->rect[i].height_ = param.rect[i].height_ / param.scale;
101 120 }
102   -#endif
103   -#endif
  121 + *handle = regin;
104 122 return ret;
105 123 }
106 124 else
107 125 {
108 126 return AUTHOR_ERROR;
109 127 }
110   -
  128 +
111 129 }
112 130  
  131 +//int rs_init(void **handle, rs_param param)
  132 +//{
  133 +// int ret = SUCCESS;
  134 +//#ifdef AUTHORIZATION
  135 +//#ifdef _WIN32
  136 +// if (SUCCESS == (ret = sy_licence(productSN)))
  137 +//#elif __linux__
  138 +// char* wtime = new char[15];
  139 +// memset(wtime, 0, 15);
  140 +// if (SUCCESS == (ret = sy_licence(productSN, &wtime)))
  141 +//#endif
  142 +//#else
  143 +// ret = sy_time_check(2021, 1);
  144 +// if (ret == SUCCESS)
  145 +//#endif
  146 +// {
  147 +//
  148 +// RegionSurveillanceProcess* regin = nullptr;
  149 +// //if (param.mode == 0)
  150 +// regin = new IRegionSurveillanceCpu;
  151 +// regin->frame_num = param.frame_num;
  152 +// if (!regin)
  153 +// {
  154 +// printf("model initial failed \n");
  155 +// return -1;
  156 +// }
  157 +//
  158 +//
  159 +// regin->long_side = param.long_side;
  160 +// regin->short_side = param.short_side;
  161 +// regin->licence_status = 0;
  162 +//#ifdef AUTHORIZATION
  163 +// regin->thrd_run = true;
  164 +// regin->thrd = boost::thread(check_thread, regin);
  165 +//#endif
  166 +// regin->thrd_status = 0;
  167 +// *handle = regin;
  168 +//#ifdef AUTHORIZATION
  169 +//#ifdef __linux__
  170 +// if (wtime)
  171 +// {
  172 +// delete[] wtime;
  173 +// wtime = NULL;
  174 +// }
  175 +//#endif
  176 +//#endif
  177 +// return ret;
  178 +// }
  179 +// else
  180 +// {
  181 +// return AUTHOR_ERROR;
  182 +// }
  183 +//
  184 +//}
  185 +
113 186 int rs_process(void *handle, sy_img img_data, rs_result *result)
114 187 {
115 188 RegionSurveillanceProcess* regin = (RegionSurveillanceProcess*)handle;
... ... @@ -135,12 +208,12 @@ int rs_process(void *handle, sy_img img_data, rs_result *result)
135 208 //pRegionInfo.p_roi[3].y_ = img_data.h_;
136 209 cv::Mat srcImage(img_data.h_, img_data.w_, CV_8UC3, img_data.data_);
137 210 IplImage img = IplImage(srcImage);
138   - int long_side = (img.width > img.height ? img.width : img.height);
139   - int short_side = (img.width <= img.height ? img.width : img.height);
140   - double scale_l = (double)long_side / (double)regin->long_side;
141   - double scale_s = (double)short_side / (double)regin->short_side;
142   - regin->scale = (scale_l > scale_s ? scale_l : scale_s);
143   - regin->scale = 1.00;
  211 + //int long_side = (img.width > img.height ? img.width : img.height);
  212 + //int short_side = (img.width <= img.height ? img.width : img.height);
  213 + //double scale_l = (double)long_side / (double)regin->long_side;
  214 + //double scale_s = (double)short_side / (double)regin->short_side;
  215 + //regin->scale = (scale_l > scale_s ? scale_l : scale_s);
  216 + //regin->scale = param.scale;
144 217 int width = img.width / regin->scale;
145 218 int height = img.height / regin->scale;
146 219 IplImage * srcscale = cvCreateImage(cvSize(width, height), 8, 3); //用于缩放 当前先不缩放
... ...
src/left_over/svibe.cpp
... ... @@ -849,92 +849,253 @@ void RegionSurveillance::VibeModelErosion(unsigned char* inputdata, int width, i
849 849 }
850 850 }
851 851 }
  852 +typedef union uEndianTest {
  853 + struct {
  854 + bool flittle_endian;
  855 + bool fill[3];
  856 + };
  857 + long value;
  858 +} EndianTest;
  859 +static const EndianTest __Endian_Test__ = { (long)1 };
  860 +const bool platform_little_endian = __Endian_Test__.flittle_endian;
  861 +
  862 +
  863 +typedef struct _int_128
  864 +{
  865 + int64_t _n1;
  866 + int64_t _n2;
852 867  
  868 +}_int_128;
853 869  
854   -void RegionSurveillance::VibeModelDilation2(unsigned char* inputdata,unsigned char *output, int width,int height)
  870 +const _int_128 & int_128_max(const _int_128 & n1, const _int_128 & n2)
  871 +{
  872 + if (platform_little_endian) //小端
  873 + {
  874 + if (n1._n2 > n2._n2)
  875 + {
  876 + return n1;
  877 + }
  878 + else if (n1._n2 < n2._n2)
  879 + {
  880 + return n2;
  881 + }
  882 + else
  883 + {
  884 + if (n1._n1 > n2._n1)
  885 + {
  886 + return n1;
  887 + }
  888 + else if (n1._n1 < n2._n1)
  889 + {
  890 + return n2;
  891 + }
  892 + else
  893 + {
  894 + return n1;
  895 + }
  896 + }
  897 + }
  898 + else
  899 + {
  900 + if (n1._n1 > n2._n1) //大端
  901 + {
  902 + return n1;
  903 + }
  904 + else if (n1._n1 < n2._n1)
  905 + {
  906 + return n2;
  907 + }
  908 + else
  909 + {
  910 + if (n1._n2 > n2._n2)
  911 + {
  912 + return n1;
  913 + }
  914 + else if (n1._n2 < n2._n2)
  915 + {
  916 + return n2;
  917 + }
  918 + else
  919 + {
  920 + return n1;
  921 + }
  922 + }
  923 + }
  924 +}
  925 +
  926 +void int_128_store(_int_128 * n1, _int_128 & n2)
  927 +{
  928 + n1->_n1 = n2._n1;
  929 + n1->_n2 = n2._n2;
  930 +}
  931 +void RegionSurveillance::VibeModelDilation2(unsigned char* inputdata, unsigned char *output, int width, int height)
855 932 {
856 933 memset(output, 0, sizeof(output[0])*width*height);
857   - if (width<32 || height<32 || inputdata==NULL || output==NULL)
  934 + if (width<32 || height<32 || inputdata == NULL || output == NULL)
858 935 return;
859 936 unsigned char *src = inputdata;
860 937 unsigned char *dst = output;
861 938  
862 939 //memcpy(output, inputdata, width*height);
863   - for (int i=0; i<height; i++) {
864   - output[i*width+0] = 0;
865   - output[i*width+width-1] = 0;
  940 + for (int i = 0; i<height; i++) {
  941 + output[i*width + 0] = 0;
  942 + output[i*width + width - 1] = 0;
866 943 }
867   - for (int j=0; j<width; j++) {
  944 + for (int j = 0; j<width; j++) {
868 945 output[j] = 0;
869   - output[(height-1)*width+j]=0;
  946 + output[(height - 1)*width + j] = 0;
870 947 }
871   - for (int i=1; i<height-1; i++)
  948 + for (int i = 1; i<height - 1; i++)
872 949 {
873 950 src = inputdata + i*width;
874 951 dst = output + i*width;
875 952 for (int j = 1; j < width - 16; j += 16)
876 953 {
877   - // 2 unaligned loads.
878   - __m128i m = _mm_loadu_si128((const __m128i*)(src + j ));
879   - m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j - 1 - width)));
880   - m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + 1)));
881   - m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j - width)));
882   - m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + 1 - width)));
  954 + // 2 unaligned loads.
  955 + _int_128 m = *((const _int_128*)(src + j));
  956 + m = int_128_max(m, *((const _int_128*)(src + j - 1 - width)));
  957 + m = int_128_max(m, *((const _int_128*)(src + j + 1)));
  958 + m = int_128_max(m, *((const _int_128*)(src + j - width)));
  959 + m = int_128_max(m, *((const _int_128*)(src + j + 1 - width)));
883 960  
884 961 // 3 aligned loads: more efficient.
885   - m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j -1)));
  962 + m = int_128_max(m, *((const _int_128*)(src + j - 1)));
886 963  
887   - m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + width)));
888   - m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j -1 + width)));
889   - m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j +1 + width)));
  964 + m = int_128_max(m, *((const _int_128*)(src + j + width)));
  965 + m = int_128_max(m, *((const _int_128*)(src + j - 1 + width)));
  966 + m = int_128_max(m, *((const _int_128*)(src + j + 1 + width)));
890 967 // Store the result in the destination image.
891   - _mm_storeu_si128((__m128i*)(dst + j), m);
  968 + int_128_store((_int_128*)(dst + j), m);
892 969 }
893 970 }
894 971  
895 972 }
896   -void RegionSurveillance::VibeModelErosion2(unsigned char* inputdata,unsigned char *output, int width,int height)
  973 +void RegionSurveillance::VibeModelErosion2(unsigned char* inputdata, unsigned char *output, int width, int height)
897 974 {
898 975 memset(output, 0, sizeof(output[0])*width*height);
899   - if (width<32 || height<32 || inputdata==NULL || output==NULL)
  976 + if (width<32 || height<32 || inputdata == NULL || output == NULL)
900 977 return;
901 978 unsigned char *src = inputdata;
902 979 unsigned char *dst = output;
903 980  
904 981 //memcpy(output, inputdata, width*height);
905   - for (int i=0; i<height; i++) {
906   - output[i*width+0] = 0;
907   - output[i*width+width-1] = 0;
  982 + for (int i = 0; i<height; i++) {
  983 + output[i*width + 0] = 0;
  984 + output[i*width + width - 1] = 0;
908 985 }
909   - for (int j=0; j<width; j++) {
  986 + for (int j = 0; j<width; j++) {
910 987 output[j] = 0;
911   - output[(height-1)*width+j]=0;
  988 + output[(height - 1)*width + j] = 0;
912 989 }
913   - for (int i=1; i<height-1; i++)
  990 + for (int i = 1; i<height; i++)
914 991 {
915 992 src = inputdata + i*width;
916 993 dst = output + i*width;
917 994 for (int j = 1; j < width - 16; j += 16)
918 995 {
919 996 // 2 unaligned loads.
920   - __m128i m = _mm_loadu_si128((const __m128i*)(src + j ));
921   - m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j - 1 - width)));
922   - m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + 1)));
923   - m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j - width)));
924   - m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + 1 - width)));
  997 + _int_128 m = *((const _int_128*)(src + j));
  998 + m = int_128_max(m, *((const _int_128*)(src + j - 1 - width)));
  999 + m = int_128_max(m, *((const _int_128*)(src + j + 1)));
  1000 + m = int_128_max(m, *((const _int_128*)(src + j - width)));
  1001 + m = int_128_max(m, *((const _int_128*)(src + j + 1 - width)));
925 1002  
926 1003 // 3 aligned loads: more efficient.
927   - m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j -1)));
  1004 + m = int_128_max(m, *((const _int_128*)(src + j - 1)));
928 1005  
929   - m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + width)));
930   - m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j -1 + width)));
931   - m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j +1 + width)));
  1006 + m = int_128_max(m, *((const _int_128*)(src + j + width)));
  1007 + m = int_128_max(m, *((const _int_128*)(src + j - 1 + width)));
  1008 + m = int_128_max(m, *((const _int_128*)(src + j + 1 + width)));
932 1009 // Store the result in the destination image.
933   - _mm_storeu_si128((__m128i*)(dst + j), m);
  1010 + int_128_store((_int_128*)(dst + j), m);
934 1011 }
935 1012 }
936 1013  
937 1014 }
  1015 +//void RegionSurveillance::VibeModelDilation2(unsigned char* inputdata,unsigned char *output, int width,int height)
  1016 +//{
  1017 +// memset(output, 0, sizeof(output[0])*width*height);
  1018 +// if (width<32 || height<32 || inputdata==NULL || output==NULL)
  1019 +// return;
  1020 +// unsigned char *src = inputdata;
  1021 +// unsigned char *dst = output;
  1022 +//
  1023 +// //memcpy(output, inputdata, width*height);
  1024 +// for (int i=0; i<height; i++) {
  1025 +// output[i*width+0] = 0;
  1026 +// output[i*width+width-1] = 0;
  1027 +// }
  1028 +// for (int j=0; j<width; j++) {
  1029 +// output[j] = 0;
  1030 +// output[(height-1)*width+j]=0;
  1031 +// }
  1032 +// for (int i=1; i<height-1; i++)
  1033 +// {
  1034 +// src = inputdata + i*width;
  1035 +// dst = output + i*width;
  1036 +// for (int j = 1; j < width - 16; j += 16)
  1037 +// {
  1038 +// // 2 unaligned loads.
  1039 +// __m128i m = _mm_loadu_si128((const __m128i*)(src + j ));
  1040 +// m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j - 1 - width)));
  1041 +// m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + 1)));
  1042 +// m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j - width)));
  1043 +// m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + 1 - width)));
  1044 +//
  1045 +// // 3 aligned loads: more efficient.
  1046 +// m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j -1)));
  1047 +//
  1048 +// m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + width)));
  1049 +// m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j -1 + width)));
  1050 +// m = _mm_max_epu8(m, _mm_loadu_si128((const __m128i*)(src + j +1 + width)));
  1051 +// // Store the result in the destination image.
  1052 +// _mm_storeu_si128((__m128i*)(dst + j), m);
  1053 +// }
  1054 +// }
  1055 +//
  1056 +//}
  1057 +//void RegionSurveillance::VibeModelErosion2(unsigned char* inputdata,unsigned char *output, int width,int height)
  1058 +//{
  1059 +// memset(output, 0, sizeof(output[0])*width*height);
  1060 +// if (width<32 || height<32 || inputdata==NULL || output==NULL)
  1061 +// return;
  1062 +// unsigned char *src = inputdata;
  1063 +// unsigned char *dst = output;
  1064 +//
  1065 +// //memcpy(output, inputdata, width*height);
  1066 +// for (int i=0; i<height; i++) {
  1067 +// output[i*width+0] = 0;
  1068 +// output[i*width+width-1] = 0;
  1069 +// }
  1070 +// for (int j=0; j<width; j++) {
  1071 +// output[j] = 0;
  1072 +// output[(height-1)*width+j]=0;
  1073 +// }
  1074 +// for (int i=1; i<height-1; i++)
  1075 +// {
  1076 +// src = inputdata + i*width;
  1077 +// dst = output + i*width;
  1078 +// for (int j = 1; j < width - 16; j += 16)
  1079 +// {
  1080 +// // 2 unaligned loads.
  1081 +// __m128i m = _mm_loadu_si128((const __m128i*)(src + j ));
  1082 +// m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j - 1 - width)));
  1083 +// m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + 1)));
  1084 +// m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j - width)));
  1085 +// m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + 1 - width)));
  1086 +//
  1087 +// // 3 aligned loads: more efficient.
  1088 +// m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j -1)));
  1089 +//
  1090 +// m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j + width)));
  1091 +// m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j -1 + width)));
  1092 +// m = _mm_min_epu8(m, _mm_loadu_si128((const __m128i*)(src + j +1 + width)));
  1093 +// // Store the result in the destination image.
  1094 +// _mm_storeu_si128((__m128i*)(dst + j), m);
  1095 +// }
  1096 +// }
  1097 +//
  1098 +//}
938 1099  
939 1100  
940 1101 //按照中心点的位置进行排序 by zl
... ... @@ -944,7 +1105,7 @@ void RegionSurveillance::SortForeground(vector&lt;CForeground&gt; &amp;ForegroundArray)
944 1105 }
945 1106  
946 1107  
947   -
  1108 +int RegionSurveillance::dwGlobalID;
948 1109 /******************************************************************************
949 1110 * Function: VibeModelGetTrace
950 1111 * Description:
... ...
src/left_over/svibe.h
... ... @@ -184,7 +184,7 @@ private:
184 184 void FreeRandNeighbor();
185 185  
186 186 public:
187   - int dwGlobalID; // object ID for Global use
  187 + static int dwGlobalID; // object ID for Global use
188 188  
189 189 //by zl 20160307
190 190 private:
... ...
src/test/demo.cpp
... ... @@ -78,23 +78,39 @@ void imag_ana_3channels()
78 78  
79 79 void *tools = nullptr;
80 80 rs_param param;
81   - param.frame_num = 30;
82   - param.long_side = 1920;
83   - param.short_side = 1080;
  81 + param.frame_num = 100;
  82 + //param.long_side = 1920;
  83 + //param.short_side = 1080;
  84 + param.scale = 2;
  85 + param.rect_num = 2;
  86 +
  87 + {
  88 + param.rect[0].left_ = 30;
  89 + param.rect[0].top_ = 0;
  90 + param.rect[0].width_ = 320;
  91 + param.rect[0].height_ = 480;
  92 +
  93 + param.rect[1].left_ = 320;
  94 + param.rect[1].top_ = 0;
  95 + param.rect[1].width_ = 319;
  96 + param.rect[1].height_ = 479;
  97 + }
84 98 if (rs_init(&tools, param) != 0)
85 99 cout << "hp_init ailed!" << endl;
86 100  
87 101 char imgpath[260];
  102 + //CvCapture* video1 = cvCaptureFromFile("D:\\weixin\\ATM遗留物\\20200928\\192.0.0.209_8000_1_4_-1\\20200928_20200928103418_20200928104058_103413.mp4");
  103 + //CvCapture* video1 = cvCaptureFromFile("E:\\vpt_pic\\MSRegion.git\\win\\MSRegionDemo\\test1.mp4");
88 104 CvCapture* video1 = cvCaptureFromFile("D:\\ruijinVideo\\192.168.1.10_01_2020072911472348.mp4");
89 105 // 用opencv函数读取视频的一帧
90 106 IplImage * src = cvQueryFrame(video1);
91 107  
92   - int long_side = (src->width > src->height ? src->width : src->height);
93   - int short_side = (src->width <= src->height ? src->width : src->height);
94   - double scale_l = (double)long_side / (double)param.long_side;
95   - double scale_s = (double)short_side / (double)param.short_side;
96   - double scale = (scale_l > scale_s ? scale_l : scale_s);
97   - scale = 1.0;
  108 + //int long_side = (src->width > src->height ? src->width : src->height);
  109 + //int short_side = (src->width <= src->height ? src->width : src->height);
  110 + //double scale_l = (double)long_side / (double)param.long_side;
  111 + //double scale_s = (double)short_side / (double)param.short_side;
  112 + //double scale = (scale_l > scale_s ? scale_l : scale_s);
  113 + double scale = 1.0;
98 114 int width = src->width / scale;
99 115 int height = src->height / scale;
100 116 //width = 1912;
... ... @@ -142,7 +158,7 @@ void imag_ana_3channels()
142 158 //ExternalRectangle((unsigned char*)(srcscale1->imageData), srcscale1->width, srcscale1->height, result.obj_infos, result.obj_count, srcscale1->widthStep, 1);
143 159  
144 160 /*****************************************************/
145   - ExternalRectangle((unsigned char*)(srcscale->imageData), srcscale->width, srcscale->height, result.obj_infos, result.obj_count, srcscale->widthStep, 1);
  161 + ExternalRectangle((unsigned char*)(srcscale->imageData), srcscale->width, srcscale->height, result.obj_infos, result.obj_count, srcscale->widthStep,1);
146 162 CvFont font;
147 163 cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 2, 8);
148 164 //cvPutText(srcscale, "1Hello World !", cvPoint(80, 40), &font, cvScalar(255, 0, 0, 1));
... ...
src/test/regionassist.h
... ... @@ -16,5 +16,5 @@ void Trajectory(unsigned char* pRGBIn, ms_object_info *ObjInfo, int ObjCount, in
16 16  
17 17 //判断单向检测方向和绘制箭头
18 18 void DrawArrow(IplImage * src, cv::Point pStart, cv::Point pEnd, int len, int alpha);
19   -int get_ArrowDir(IplImage *frame, CMPoint pROI0, CMPoint pROI1, CMPoint dir, cv::Point &pt1, cv::Point &pt2);
  19 +//int get_ArrowDir(IplImage *frame, CMPoint pROI0, CMPoint pROI1, CMPoint dir, cv::Point &pt1, cv::Point &pt2);
20 20 #endif
21 21 \ No newline at end of file
... ...