ConExtraction.h 3.08 KB
// 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