Blame view

src/MSRegionSurveilance/ConExtraction.h 3.08 KB
8805b950   Liu Meng   物品遗留效果优化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  // ConExtraction.h: interface for the CConExtraction class.
  
  #ifndef _I_FIND_CONTOURS_H_NEW_
  #define _I_FIND_CONTOURS_H_NEW_
  
  #include<vector>
  #include<iterator>
  #include<iostream>
  using namespace std;
  
  
  #include <opencv2/opencv.hpp>
  using namespace cv;
  
  typedef struct iCPoint{
  	int x;
  	int y;
  }iCPoint;
  
  typedef struct iCvRect{
  	int x;
  	int y;
  	int width;
  	int height;
  }iCvRect;
  
  typedef struct iRect{
  	int left;   //x_1
  	int right;  //x_2
  	int top;    //y_1
  	int bottom; //y_2
  }iRect;
  
  typedef struct CContour
  {
  	int  left;
  	int  top;
  	int  right;
  	int  bottom;
  	int  xCenter;
  	int  yCenter;
  	bool label;
  }CContour; // the detected target external contour of the current frame 
  
  typedef struct CForegroundTarget      
  {
  	iCvRect  m_rtConnect;
  	iCPoint  m_ptCenter;
  	int      m_area;
  	bool     m_AbandonFlag;
  	CContour m_Contour;    //the contour the target
  	iCPoint  m_point;      //the position of the foreground target
  }CForegroundTarget;        //the detected target of the current frame 
  
  //3*3 neighborhood of a pixel
  #define DELTAS(deltas, step, nch)                       \
  	 ((deltas)[0] = (nch),  (deltas)[1] = -(step) + (nch),    \
        (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch),   \
  	  (deltas)[4] = -(nch), (deltas)[5] = (step) - (nch),    \
  	  (deltas)[6] = (step), (deltas)[7] = (step) + (nch) )
  
  class CConExtraction  
  {
  public:
  	CConExtraction();
  	//CConExtraction(const int &m_nbd, const int &m_area, const int &m_size);
  	virtual ~CConExtraction();
  
  public:
  	void InitBackgroud(unsigned char *pSrcImage, const int &width, const int &height, const int& channels);
  	void CalMask(vector<vector<Point>> regions, int width, int height);
  	vector<CContour> ExtractContours (unsigned char *pSrcImage, const int &width, const int &height, const int &step);
  	vector<CContour> ExtractContours_PixelSub(unsigned char *pSrcImage, const int &width, const int &height, const int &step);
  	vector<CContour> ExtractContours_Canny(unsigned char *pSrcImage, const int &width, const int &height, const int &step);
  	//vector<CForegroundTarget> DetectTarget(unsigned char *pSrcImage, const int &width, const int &height, const int &step);
  
  private:
  
  	vector<CContour> m_Contourvec; //the contour of the corresponding detected target
  	//vector<CForegroundTarget> m_ForeTargetvec;
  	int   m_nbd; //current mark value
  	int   m_area; //it is used to remove the noise point
  	int   m_size; //the size of the contour pixel
  	iRect m_rect; //the rectangle of the contour
  
  	int total_mask_image_human;
  	cv::Mat background_image, mask_image, mask_image_human;
  	cv::Mat img_diffLast, img_foreg;
  	time_t last_time;
  
  	float human_ratio;
  	int bk_update_interval;
  private:
  	
  	vector<CContour> AeraMaxX(vector<CContour> CForegrounds, int topx);
  
  	CContour FetchContour(unsigned char *pImage, const int &step,  iCPoint &pt);
  
      void BoundingRect(vector<iCPoint> Pointvec); //get the corresponding rectangle of a point set
  
  	//void RemoveNoise(unsigned char *pSrcImage, const int &width, const int &height, const int &step); //remove the single noise point
  
  	//void Dilation(unsigned char *pSrcImage, const int &width, const int &height, const int &step);
  };
  
  #endif