BlobTracker.h
资源名称:VIS.zip [点击查看]
上传用户:sdgangtie
上传日期:2020-03-07
资源大小:7324k
文件大小:5k
源码类别:
数值算法/人工智能
开发平台:
Visual C++
- #pragma once
- #include "cvaux.h" #include "highgui.h" #include <stdio.h>
- #include <time.h>
- /************************************************************************/
- /* 前景检测模块——背景差部分 */
- /************************************************************************/
- // 动态连接库计算两幅图像间的仿射变换矩阵
- #pragma comment (lib,"../Release/SIFT_VC")
- extern "C" __declspec(dllimport) void GetMaskBySIFT( IplImage* img1, IplImage* img2, int flag, CvMat *T );
- class FGDetector :
- public CvFGDetector
- {
- public:
- FGDetector(void);
- ~FGDetector(void);
- IplImage* GetMask(void);
- void Process(IplImage* pFrame);
- void Release(void);
- private:
- int m_FrameCount;
- int m_Transform; // 计算方式:‘1’为仿射变换;‘0’为透视变换
- double m_Threshold; // 前景阈值化参数,大小一般为10-30之间
- IplImage* m_pFramePre;
- IplImage* m_pFGMask;
- IplImage* m_pTransPre;
- };
- static CvFGDetector* cvCreateFGDetectorBoa() { return new FGDetector(); }
- /************************************************************************/
- /* 对象检测模块——连通分量方法 */
- /************************************************************************/
- class BlobDetector :
- public CvBlobDetector
- {
- public:
- BlobDetector(void);
- ~BlobDetector(void);
- int DetectNewBlob(IplImage* pImg, IplImage* pImgFG, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList);
- void Release(void);
- private:
- void cvFindBlobsByCCClasters(IplImage* pFG, CvBlobSeq* pBlobs, CvMemStorage* storage);
- double m_HMin;
- double m_HMax;
- double m_WMin;
- double m_WMax;
- };
- static CvBlobDetector* cvCreateBlobDetectorBoa() { return new BlobDetector(); }
- /************************************************************************/
- /* 轨迹生成模块——对象特征方法 */
- /************************************************************************/
- typedef struct DefBlobTrack { CvBlob blob; CvBlobSeq* pSeq; int FrameBegin; int FrameLast; int Saved; } DefBlobTrack;
- class BlobTrackGen :
- public CvBlobTrackGen
- {
- public:
- BlobTrackGen(void);
- ~BlobTrackGen(void);
- void SetFileName(char* pFileName);
- void AddBlob(CvBlob* pBlob);
- void Process(IplImage* pImg, IplImage* pFG);
- void Release(void);
- CvBlobSeq *GetTrackList(){return &m_TrackList;};
- private:
- int m_FrameCount;
- int m_Transform; // 计算方式:‘1’为仿射变换;‘0’为透视变换
- char* m_pFileName;
- CvSize m_Size;
- CvBlobSeq m_TrackList;
- CvPoint2D64f affine_xform_pt(CvPoint2D64f pt, CvMat* T);
- CvPoint2D64f persp_xform_pt(CvPoint2D64f pt, CvMat* T);
- void SaveAll(void);
- };
- static CvBlobTrackGen* cvCreateModuleBlobTrackGenBoa() { return new BlobTrackGen(); }
- /************************************************************************/
- /* 主模块——各个子模块综合模块 */
- /************************************************************************/
- typedef struct CvBlobTrackAuto { CvBlob blob; int BadFrames; } CvBlobTrackAuto;
- struct CvBlobTrackerAutoParam { int FGTrainFrames; CvFGDetector* pFG; CvBlobDetector* pBD; CvBlobTracker* pBT; CvBlobTrackGen* pBTGen; CvBlobTrackPostProc* pBTPP; int UsePPData; CvBlobTrackAnalysis* pBTA; };
- class BlobTrackerAuto: public CvBlobTrackerAuto
- {
- public:
- BlobTrackerAuto(CvBlobTrackerAutoParam* param);
- ~BlobTrackerAuto();
- CvBlob* GetBlob(int index){return m_BlobList.GetBlob(index);};
- CvBlob* GetBlobByID(int ID){return m_BlobList.GetBlobByID(ID);};
- int GetBlobNum(){return m_BlobList.GetBlobNum();};
- virtual IplImage* GetFGMask(){return m_pFGMask;};
- float GetState(int BlobID){return m_pBTA?m_pBTA->GetState(BlobID):0;};
- const char* GetStateDesc(int BlobID){return m_pBTA?m_pBTA->GetStateDesc(BlobID):NULL;};
- void Process(IplImage* pImg, IplImage* pMask = NULL);
- void Release(){delete this;};
- virtual void SaveState(CvFileStorage* fs)
- {
- cvWriteInt(fs,"FrameCount",m_FrameCount);
- cvWriteInt(fs,"NextBlobID",m_NextBlobID);
- m_BlobList.Write(fs,"BlobList");
- };
- virtual void LoadState(CvFileStorage* fs, CvFileNode* node)
- {
- CvFileNode* BlobListNode = cvGetFileNodeByName(fs,node,"BlobList");
- m_FrameCount = cvReadIntByName(fs,node, "FrameCount", m_FrameCount);
- m_NextBlobID = cvReadIntByName(fs,node, "NextBlobID", m_NextBlobID);
- if(BlobListNode)
- {
- m_BlobList.Load(fs,BlobListNode);
- }
- };
- CvBlobTrackGen* GetTrackGen() { return m_pBTGen; };
- private:
- IplImage* m_pFGMask;
- int m_FGTrainFrames;
- CvFGDetector* m_pFG;
- CvBlobTracker* m_pBT;
- CvBlobDetector* m_pBD;
- CvBlobTrackGen* m_pBTGen;
- CvBlobTrackPostProc* m_pBTPostProc;
- int m_UsePPData;
- CvBlobTrackAnalysis* m_pBTA;
- CvBlobSeq m_BlobList;
- int m_FrameCount;
- int m_NextBlobID;
- };
- static CvBlobTrackerAuto* cvCreateBlobTrackerAutoBoa(CvBlobTrackerAutoParam* param) { return (CvBlobTrackerAuto*)new BlobTrackerAuto(param); } //////////////////////////////////////////////////////////////////////////