⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grimsonbg.h

📁 人体运动跟踪 混合高斯模型+GRISON方法
💻 H
字号:
/***************************************************************************** * * File :       GrimsonBG.cpp * * Module :     visualise_data * * Author :     Derek Magee, School of Computing, Leeds University. * * Created :    18th September 2001 * ***************************************************************************** * * Source code for CogVis * * The author, Derek Magee, gives permission for this code to be copied, * modified and distributed within the University of Leeds subject to the * following conditions:- * * - The code is not to be used for commercial gain. * - The code and use thereof will be attributed to the author where *   appropriate (inluding demonstrations which rely on it's use). * - All modified, distributions of the source files will retain this header. * ***************************************************************************** * * Description: * * Definition of class GrimsonBG which implements the Stauffer / Grimson * background model (based on mixtures of gaussians at each pixel). * * See: * * C. Stauffer, W.E.L. Grimson "Adaptive background mixture models for real-time * tracking", CVPR 99. * ***************************************************************************** * * Revision History: * * Date         By              Revision * * 01/08/01     DRM             Created. * ****************************************************************************/#include <vfw.h>
#include "ipl.h"#ifndef GRIMSON_BG_H
#define GRIMSON_BG_H//#define UPDATE_RATE_MIN 25 #define UPDATE_RATE_MIN 1 
struct Gaussian{            double weight ;             double mean[3] ;            double covariance ;
                        double ss ;};struct PixelInfo{            Gaussian     **gaussians ;             int no_in_bg ;            unsigned int frames_since_fg ;            unsigned int frames_since_ud ;
			unsigned int belong[4]; 
	};            enum DataType{            DATA_RGB,      // RGB Data             DATA_NORM_RGB  // Intensity normalised RGB };class GrimsonBG{// Public data public:     bool         m_bInitOk;             //            bool         m_bUpdateEveryFrame;   //
			unsigned int m_biTotPixels;         //
	         int m_biWidth;             //
             int m_biHeight;            //
            unsigned int m_biInrX;              // 
            unsigned int m_biInrY;              //
	        int m_biGaussiansPerMix;   //
			int          m_iCurrentTrack;       //
	        double        m_dProportion;         //
			float        m_fUpdateAlpha;        //               double       m_dBgdProp ;           //            double       m_dAlpha;              //            double       m_dAlphai;               //              DataType     m_sdDataType;          //                PixelInfo    *m_pModel ;            //            


            // read avi file
			long    m_lCurrentFrame;               
			WORD    m_wBitCount;               
         	BOOL    m_bGetFrame;                     
	        CString	m_csInfileName;
			PAVIFILE	m_pAviFile;	// for AVIFileOpen
        	AVIFILEINFO m_Info;		// for AVIFileInfo
			PAVISTREAM	m_pStream;	//
			bool	m_bAviOpened;
			bool	m_bStreamInit;
			PAVISTREAM	m_pAudio[5], m_pVideo[5];	// maximum video steam : 5
			int m_iNumAudioStreams, m_iNumVideoStreams;	
			LPBITMAPINFO m_lpVideoFormats[5];
			LPBITMAPINFO m_pBitmapInfo ;
			LPBITMAPINFOHEADER m_lpBitmapInforHead;
			PGETFRAME m_pGf;
          
			//labeling
			short	m_sRegionInfo[256*2];	
	        CRect	m_crResultPosition[256];
	        int		m_iNumofSeg;            int     m_iMinRegionSize;
            int     m_iMinObjectSize;
            // property
			SHORT	m_sCentroid[256*2];
			short	m_sXProject[352], m_sYProject[288], m_sXBackup[352], m_sYBackup[288];
			BYTE	m_bOutputInfo[512];   // number of segments, especially two segments from merged segment.

		    CRect	m_crRectangle[10];
	        CRect	m_crRectangleAll[512];
			int		m_iTotalRectangle;


			BYTE	m_byYuvTemp[352*288*3];
			float	m_fObjectInfo[20000];
	        float	m_fObjectColor[20000];
	        CRect	m_crObjectPosition[1000];
//	        CRect	m_crObjectResultPositionBack[256*10];
	        byte	m_byMorpLabeled[352*288*10];
			int		m_iColorIndexV;
			BYTE	m_bOriginalforDisplayBackground[352*288*4];
// Public methods public:
	IplImage*  CreateIpl(int width, int height, byte *Source,  int mode);
	int		ComputeSmoothCenterPosition(byte *labeled, int left, int right, int segnum);
	void FindBestMatching2(CDC* pDC, int upperx, int uppery);
	float ComputeOverlappedRegion(int current, int past);
	void  DisplayBackgroundWithObject(CDC* pDC, COLORREF tt, int current);
	COLORREF ColorIndexRGB(int value);
	void ComputeColorDistribution(byte *original, int bits,  byte *label);
	void ChangeColorModeltoYUV(byte *original, byte *output);
	void DrawRectangle(CDC* pDC, int number, CRect *point, int upperx, int uppery);
	void FindBestRectangle(BYTE *labeled,short *region_info, CRect *position, short *projection, int whichone, int *outputnumber,  CRect *result);
	void FindBestRectangleAll(CDC*pDC,BYTE *labeled, short *region_info, CRect *position,  byte *OutputInformation, CRect *result);
	void ComputeProjection(BYTE *Morp, short *region_info, CRect *position, int whichone, short *xprojection, short *yprojection); 
	void ComputeCentroid(BYTE *labeled, short *region_info, CRect *position, short *ResultCentroid);
	HANDLE DDBToDIB(CBitmap& bitmap, DWORD dwCompression, CPalette* pPal );
	BOOL WriteDIB(CString szFile, HANDLE hDIB);
	void SaveScreen(CDC* pDC, int width, int height);
	void DetectionMoveRegion(unsigned char*src,unsigned char*median,unsigned char*result);
	void Display8bit(CDC* pDC, BYTE *source, int xpos, int ypos);
	BOOL ConvertGrayImage(BYTE *rgb, BYTE *gray);
    GrimsonBG();
	BOOL GetInfo();
	BOOL OpenAndInitialize();
    int m_iNum;
	unsigned char m_ucRgbTemp[352*288*3];
	unsigned char m_ucBackgroundPic[352*288*3];
	unsigned char m_ucImgResultMorp[352*288];

	BYTE m_bResultone[352*288];
	BOOL GetRGBXImage(unsigned char*rgbx);
	
	void Display32bit(CDC* pDC, unsigned char* source, int xpos, int ypos);
	unsigned char m_ucTbuffer[352*288*4];
	void Display8bitPseudoColor(CDC* pDC, unsigned char*source, int xpos, int ypos);
	void Label(BYTE *Source, BYTE *Result, int w, int h, short *region_info, CRect *position);
	void VerticalMorp(unsigned char *Source,bool flag);

	       ~GrimsonBG();
            BackgroundInit(unsigned int gauss_per_mix,                       double       bg_proportion,                      double       update_alpha,                      unsigned int size_x,                      unsigned int size_y,                      unsigned int x_inc,    // Increment for low-res model                      unsigned int y_inc,                      DataType     type) ;  // Increment for low-res model            void      AddNewImage(unsigned char *data) ;            void      PlotBestMixture(unsigned char *data) ;            void      SetAlpha(double a) ;            void      CalculateUpdate(unsigned char *data) ;                                                      void      CalculateForeground(unsigned char  *data,                                           unsigned char *fg) ;      // Private Methodsprivate: 
	        bool      isShadow(double *data, PixelInfo *pi);
            void      SortGaussians(Gaussian **) ;            void      InitialiseMixtures(Gaussian *,                                          Gaussian **) ;            double    CalculateGaussian(double *d,                                         Gaussian *) ;            void      UpdateMixture(double *, PixelInfo *) ;            bool      InMixture(double *, PixelInfo *,bool ) ;    inline  double    MahalanobisDist(double *, Gaussian *) ;
	        int GetAverage(unsigned char* ,int,int);       
	        bool m_bShadow;
};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -