- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/opt/OpenCV-2.2.0/modules/legacy/include/opencv2/legacy/blobtrack.hpp

Go to the documentation of this file.

    00001 /*M///////////////////////////////////////////////////////////////////////////////////////
    00002 //
    00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
    00004 //
    00005 //  By downloading, copying, installing or using the software you agree to this license.
    00006 //  If you do not agree to this license, do not download, install,
    00007 //  copy or use the software.
    00008 //
    00009 //
    00010 //                        Intel License Agreement
    00011 //                For Open Source Computer Vision Library
    00012 //
    00013 // Copyright (C) 2000, Intel Corporation, all rights reserved.
    00014 // Third party copyrights are property of their respective owners.
    00015 //
    00016 // Redistribution and use in source and binary forms, with or without modification,
    00017 // are permitted provided that the following conditions are met:
    00018 //
    00019 //   * Redistribution's of source code must retain the above copyright notice,
    00020 //     this list of conditions and the following disclaimer.
    00021 //
    00022 //   * Redistribution's in binary form must reproduce the above copyright notice,
    00023 //     this list of conditions and the following disclaimer in the documentation
    00024 //     and/or other materials provided with the distribution.
    00025 //
    00026 //   * The name of Intel Corporation may not be used to endorse or promote products
    00027 //     derived from this software without specific prior written permission.
    00028 //
    00029 // This software is provided by the copyright holders and contributors "as is" and
    00030 // any express or implied warranties, including, but not limited to, the implied
    00031 // warranties of merchantability and fitness for a particular purpose are disclaimed.
    00032 // In no event shall the Intel Corporation or contributors be liable for any direct,
    00033 // indirect, incidental, special, exemplary, or consequential damages
    00034 // (including, but not limited to, procurement of substitute goods or services;
    00035 // loss of use, data, or profits; or business interruption) however caused
    00036 // and on any theory of liability, whether in contract, strict liability,
    00037 // or tort (including negligence or otherwise) arising in any way out of
    00038 // the use of this software, even if advised of the possibility of such damage.
    00039 //
    00040 //M*/
    00041
    00042
    00043 #ifndef __OPENCV_VIDEOSURVEILLANCE_H__
    00044 #define __OPENCV_VIDEOSURVEILLANCE_H__
    00045
    00046 /* Turn off the functionality until cvaux/src/Makefile.am gets updated: */
    00047 //#if _MSC_VER >= 1200
    00048
    00049 #include "opencv2/core/core_c.h"
    00050 #include <stdio.h>
    00051
    00052 #if _MSC_VER >= 1200 || defined __BORLANDC__
    00053 #define cv_stricmp stricmp
    00054 #define cv_strnicmp strnicmp
    00055 #if defined WINCE
    00056 #define strdup _strdup
    00057 #define stricmp _stricmp
    00058 #endif
    00059 #elif defined __GNUC__
    00060 #define cv_stricmp strcasecmp
    00061 #define cv_strnicmp strncasecmp
    00062 #else
    00063 #error Do not know how to make case-insensitive string comparison on this platform
    00064 #endif
    00065
    00066 //struct DefParam;
    00067 struct CvDefParam
    00068 {
    00069     struct CvDefParam*    next;
    00070     char*               pName;
    00071     char*               pComment;
    00072     double*             pDouble;
    00073     double              Double;
    00074     float*              pFloat;
    00075     float               Float;
    00076     int*                pInt;
    00077     int                 Int;
    00078     char**              pStr;
    00079     char*               Str;
    00080 };
    00081
    00082 class CV_EXPORTS CvVSModule
    00083 {
    00084 private: /* Internal data: */
    00085     CvDefParam*   m_pParamList;
    00086     char*       m_pModuleTypeName;
    00087     char*       m_pModuleName;
    00088     char*       m_pNickName;
    00089 protected:
    00090     int         m_Wnd;
    00091 public: /* Constructor and destructor: */
    00092     CvVSModule();
    00093     virtual ~CvVSModule();
    00094 private: /* Internal functions: */
    00095     void    FreeParam(CvDefParam** pp);
    00096     CvDefParam* NewParam(const char* name);
    00097     CvDefParam* GetParamPtr(int index);
    00098     CvDefParam* GetParamPtr(const char* name);
    00099 protected: /* INTERNAL INTERFACE */
    00100     int  IsParam(const char* name);
    00101     void AddParam(const char* name, double* pAddr);
    00102     void AddParam(const char* name, float* pAddr);
    00103     void AddParam(const char* name, int* pAddr);
    00104     void AddParam(const char* name, const char** pAddr);
    00105     void AddParam(const char* name);
    00106     void CommentParam(const char* name, const char* pComment);
    00107     void SetTypeName(const char* name);
    00108     void SetModuleName(const char* name);
    00109     void DelParam(const char* name);
    00110
    00111 public: /* EXTERNAL INTERFACE */
    00112     const char* GetParamName(int index);
    00113     const char* GetParamComment(const char* name);
    00114     double GetParam(const char* name);
    00115     const char* GetParamStr(const char* name);
    00116     void   SetParam(const char* name, double val);
    00117     void   SetParamStr(const char* name, const char* str);
    00118     void TransferParamsFromChild(CvVSModule* pM, const char* prefix = NULL);
    00119     void TransferParamsToChild(CvVSModule* pM, char* prefix = NULL);
    00120     virtual void ParamUpdate();
    00121     const char*   GetTypeName();
    00122     int     IsModuleTypeName(const char* name);
    00123     char*   GetModuleName();
    00124     int     IsModuleName(const char* name);
    00125     void SetNickName(const char* pStr);
    00126     const char* GetNickName();
    00127     virtual void SaveState(CvFileStorage*);
    00128     virtual void LoadState(CvFileStorage*, CvFileNode*);
    00129
    00130     virtual void Release() = 0;
    00131 };/* CvVMModule */
    00132
    00133 CV_EXPORTS void cvWriteStruct(CvFileStorage* fs, const char* name, void* addr, const char* desc, int num=1);
    00134 CV_EXPORTS void cvReadStructByName(CvFileStorage* fs, CvFileNode* node, const char* name, void* addr, const char* desc);
    00135
    00136 /* FOREGROUND DETECTOR INTERFACE */
    00137 class CV_EXPORTS CvFGDetector : public CvVSModule
    00138 {
    00139 public:
    00140     CvFGDetector();
    00141     virtual IplImage* GetMask() = 0;
    00142     /* Process current image: */
    00143     virtual void    Process(IplImage* pImg) = 0;
    00144     /* Release foreground detector: */
    00145     virtual void    Release() = 0;
    00146 };
    00147
    00148 CV_EXPORTS void cvReleaseFGDetector(CvFGDetector** ppT );
    00149 CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param);
    00150
    00151
    00152 /* BLOB STRUCTURE*/
    00153 struct CvBlob
    00154 {
    00155     float   x,y; /* blob position   */
    00156     float   w,h; /* blob sizes      */
    00157     int     ID;  /* blob ID         */
    00158 };
    00159
    00160 inline CvBlob cvBlob(float x,float y, float w, float h)
    00161 {
    00162     CvBlob B = {x,y,w,h,0};
    00163     return B;
    00164 }
    00165 #define CV_BLOB_MINW 5
    00166 #define CV_BLOB_MINH 5
    00167 #define CV_BLOB_ID(pB) (((CvBlob*)(pB))->ID)
    00168 #define CV_BLOB_CENTER(pB) cvPoint2D32f(((CvBlob*)(pB))->x,((CvBlob*)(pB))->y)
    00169 #define CV_BLOB_X(pB) (((CvBlob*)(pB))->x)
    00170 #define CV_BLOB_Y(pB) (((CvBlob*)(pB))->y)
    00171 #define CV_BLOB_WX(pB) (((CvBlob*)(pB))->w)
    00172 #define CV_BLOB_WY(pB) (((CvBlob*)(pB))->h)
    00173 #define CV_BLOB_RX(pB) (0.5f*CV_BLOB_WX(pB))
    00174 #define CV_BLOB_RY(pB) (0.5f*CV_BLOB_WY(pB))
    00175 #define CV_BLOB_RECT(pB) cvRect(cvRound(((CvBlob*)(pB))->x-CV_BLOB_RX(pB)),cvRound(((CvBlob*)(pB))->y-CV_BLOB_RY(pB)),cvRound(CV_BLOB_WX(pB)),cvRound(CV_BLOB_WY(pB)))
    00176 /* END BLOB STRUCTURE*/
    00177
    00178
    00179 /* simple BLOBLIST */
    00180 class CV_EXPORTS CvBlobSeq
    00181 {
    00182 public:
    00183     CvBlobSeq(int BlobSize = sizeof(CvBlob))
    00184     {
    00185         m_pMem = cvCreateMemStorage();
    00186         m_pSeq = cvCreateSeq(0,sizeof(CvSeq),BlobSize,m_pMem);
    00187         strcpy(m_pElemFormat,"ffffi");
    00188     }
    00189     virtual ~CvBlobSeq()
    00190     {
    00191         cvReleaseMemStorage(&m_pMem);
    00192     };
    00193     virtual CvBlob* GetBlob(int BlobIndex)
    00194     {
    00195         return (CvBlob*)cvGetSeqElem(m_pSeq,BlobIndex);
    00196     };
    00197     virtual CvBlob* GetBlobByID(int BlobID)
    00198     {
    00199         int i;
    00200         for(i=0; i<m_pSeq->total; ++i)
    00201             if(BlobID == CV_BLOB_ID(GetBlob(i)))
    00202                 return GetBlob(i);
    00203         return NULL;
    00204     };
    00205     virtual void DelBlob(int BlobIndex)
    00206     {
    00207         cvSeqRemove(m_pSeq,BlobIndex);
    00208     };
    00209     virtual void DelBlobByID(int BlobID)
    00210     {
    00211         int i;
    00212         for(i=0; i<m_pSeq->total; ++i)
    00213         {
    00214             if(BlobID == CV_BLOB_ID(GetBlob(i)))
    00215             {
    00216                 DelBlob(i);
    00217                 return;
    00218             }
    00219         }
    00220     };
    00221     virtual void Clear()
    00222     {
    00223         cvClearSeq(m_pSeq);
    00224     };
    00225     virtual void AddBlob(CvBlob* pB)
    00226     {
    00227         cvSeqPush(m_pSeq,pB);
    00228     };
    00229     virtual int GetBlobNum()
    00230     {
    00231         return m_pSeq->total;
    00232     };
    00233     virtual void Write(CvFileStorage* fs, const char* name)
    00234     {
    00235         const char*  attr[] = {"dt",m_pElemFormat,NULL};
    00236         if(fs)
    00237         {
    00238             cvWrite(fs,name,m_pSeq,cvAttrList(attr,NULL));
    00239         }
    00240     }
    00241     virtual void Load(CvFileStorage* fs, CvFileNode* node)
    00242     {
    00243         if(fs==NULL) return;
    00244         CvSeq* pSeq = (CvSeq*)cvRead(fs, node);
    00245         if(pSeq)
    00246         {
    00247             int i;
    00248             cvClearSeq(m_pSeq);
    00249             for(i=0;i<pSeq->total;++i)
    00250             {
    00251                 void* pB = cvGetSeqElem( pSeq, i );
    00252                 cvSeqPush( m_pSeq, pB );
    00253             }
    00254         }
    00255     }
    00256     void AddFormat(const char* str){strcat(m_pElemFormat,str);}
    00257 protected:
    00258     CvMemStorage*   m_pMem;
    00259     CvSeq*          m_pSeq;
    00260     char            m_pElemFormat[1024];
    00261 };
    00262 /* simple BLOBLIST */
    00263
    00264
    00265 /* simple TRACKLIST */
    00266 struct CvBlobTrack
    00267 {
    00268     int         TrackID;
    00269     int         StartFrame;
    00270     CvBlobSeq*  pBlobSeq;
    00271 };
    00272
    00273 class CV_EXPORTS CvBlobTrackSeq
    00274 {
    00275 public:
    00276     CvBlobTrackSeq(int TrackSize = sizeof(CvBlobTrack));
    00277     virtual ~CvBlobTrackSeq();
    00278     virtual CvBlobTrack* GetBlobTrack(int TrackIndex);
    00279     virtual CvBlobTrack* GetBlobTrackByID(int TrackID);
    00280     virtual void DelBlobTrack(int TrackIndex);
    00281     virtual void DelBlobTrackByID(int TrackID);
    00282     virtual void Clear();
    00283     virtual void AddBlobTrack(int TrackID, int StartFrame = 0);
    00284     virtual int GetBlobTrackNum();
    00285 protected:
    00286     CvMemStorage*   m_pMem;
    00287     CvSeq*          m_pSeq;
    00288 };
    00289
    00290 /* simple TRACKLIST */
    00291
    00292
    00293 /* BLOB DETECTOR INTERFACE */
    00294 class CV_EXPORTS CvBlobDetector: public CvVSModule
    00295 {
    00296 public:
    00297         CvBlobDetector(){SetTypeName("BlobDetector");};
    00298     /* Try to detect new blob entrance based on foreground mask. */
    00299     /* pFGMask - image of foreground mask */
    00300     /* pNewBlob - pointer to CvBlob structure which will be filled if new blob entrance detected */
    00301     /* pOldBlobList - pointer to blob list which already exist on image */
    00302     virtual int DetectNewBlob(IplImage* pImg, IplImage* pImgFG, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList) = 0;
    00303     /* release blob detector */
    00304     virtual void Release()=0;
    00305 };
    00306
    00307 /* Release any blob detector: */
    00308 CV_EXPORTS void cvReleaseBlobDetector(CvBlobDetector** ppBD);
    00309
    00310 /* Declarations of constructors of implemented modules: */
    00311 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorSimple();
    00312 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorCC();
    00313
    00314 struct CV_EXPORTS CvDetectedBlob : public CvBlob
    00315 {
    00316     float response;
    00317 };
    00318
    00319 CV_INLINE CvDetectedBlob cvDetectedBlob( float x, float y, float w, float h, int ID = 0, float response = 0.0F )
    00320 {
    00321     CvDetectedBlob b;
    00322     b.x = x; b.y = y; b.w = w; b.h = h; b.ID = ID; b.response = response;
    00323     return b;
    00324 }
    00325
    00326
    00327 class CV_EXPORTS CvObjectDetector
    00328 {
    00329 public:
    00330     CvObjectDetector( const char* /*detector_file_name*/ = 0 );
    00331     ~CvObjectDetector();
    00332
    00333     /*
    00334      * Release the current detector and load new detector from file
    00335      * (if detector_file_name is not 0)
    00336      * Return true on success:
    00337      */
    00338     bool Load( const char* /*detector_file_name*/ = 0 );
    00339
    00340     /* Return min detector window size: */
    00341     CvSize GetMinWindowSize() const;
    00342
    00343     /* Return max border: */
    00344     int GetMaxBorderSize() const;
    00345
    00346     /*
    00347      * Detect the object on the image and push the detected
    00348      * blobs into <detected_blob_seq> which must be the sequence of <CvDetectedBlob>s
    00349      */
    00350     void Detect( const CvArr* /*img*/, /* out */ CvBlobSeq* /*detected_blob_seq*/ = 0 );
    00351
    00352 protected:
    00353     class CvObjectDetectorImpl* impl;
    00354 };
    00355
    00356
    00357 CV_INLINE CvRect cvRectIntersection( const CvRect r1, const CvRect r2 )
    00358 {
    00359     CvRect r = cvRect( MAX(r1.x, r2.x), MAX(r1.y, r2.y), 0, 0 );
    00360
    00361     r.width  = MIN(r1.x + r1.width, r2.x + r2.width) - r.x;
    00362     r.height = MIN(r1.y + r1.height, r2.y + r2.height) - r.y;
    00363
    00364     return r;
    00365 }
    00366
    00367
    00368 /*
    00369  * CvImageDrawer
    00370  *
    00371  * Draw on an image the specified ROIs from the source image and
    00372  * given blobs as ellipses or rectangles:
    00373  */
    00374
    00375 struct CvDrawShape
    00376 {
    00377     enum {RECT, ELLIPSE} shape;
    00378     CvScalar color;
    00379 };
    00380
    00381 /*extern const CvDrawShape icv_shape[] =
    00382 {
    00383     { CvDrawShape::ELLIPSE, CV_RGB(255,0,0) },
    00384     { CvDrawShape::ELLIPSE, CV_RGB(0,255,0) },
    00385     { CvDrawShape::ELLIPSE, CV_RGB(0,0,255) },
    00386     { CvDrawShape::ELLIPSE, CV_RGB(255,255,0) },
    00387     { CvDrawShape::ELLIPSE, CV_RGB(0,255,255) },
    00388     { CvDrawShape::ELLIPSE, CV_RGB(255,0,255) }
    00389 };*/
    00390
    00391 class CV_EXPORTS CvImageDrawer
    00392 {
    00393 public:
    00394     CvImageDrawer() : m_image(0) {}
    00395     ~CvImageDrawer() { cvReleaseImage( &m_image ); }
    00396     void SetShapes( const CvDrawShape* shapes, int num );
    00397     /* <blob_seq> must be the sequence of <CvDetectedBlob>s */
    00398     IplImage* Draw( const CvArr* src, CvBlobSeq* blob_seq = 0, const CvSeq* roi_seq = 0 );
    00399     IplImage* GetImage() { return m_image; }
    00400 protected:
    00401     //static const int MAX_SHAPES = sizeof(icv_shape) / sizeof(icv_shape[0]);;
    00402
    00403     IplImage* m_image;
    00404     CvDrawShape m_shape[16];
    00405 };
    00406
    00407
    00408
    00409 /* Trajectory generation module: */
    00410 class CV_EXPORTS CvBlobTrackGen: public CvVSModule
    00411 {
    00412 public:
    00413         CvBlobTrackGen(){SetTypeName("BlobTrackGen");};
    00414     virtual void    SetFileName(char* pFileName) = 0;
    00415     virtual void    AddBlob(CvBlob* pBlob) = 0;
    00416     virtual void    Process(IplImage* pImg = NULL, IplImage* pFG = NULL) = 0;
    00417     virtual void    Release() = 0;
    00418 };
    00419
    00420 inline void cvReleaseBlobTrackGen(CvBlobTrackGen** pBTGen)
    00421 {
    00422     if(*pBTGen)(*pBTGen)->Release();
    00423     *pBTGen = 0;
    00424 }
    00425
    00426 /* Declarations of constructors of implemented modules: */
    00427 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGen1();
    00428 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGenYML();
    00429
    00430
    00431
    00432 /* BLOB TRACKER INTERFACE */
    00433 class CV_EXPORTS CvBlobTracker: public CvVSModule
    00434 {
    00435 public:
    00436     CvBlobTracker();
    00437
    00438     /* Add new blob to track it and assign to this blob personal ID */
    00439     /* pBlob - pointer to structure with blob parameters (ID is ignored)*/
    00440     /* pImg - current image */
    00441     /* pImgFG - current foreground mask */
    00442     /* Return pointer to new added blob: */
    00443     virtual CvBlob* AddBlob(CvBlob* pBlob, IplImage* pImg, IplImage* pImgFG = NULL ) = 0;
    00444
    00445     /* Return number of currently tracked blobs: */
    00446     virtual int     GetBlobNum() = 0;
    00447
    00448     /* Return pointer to specified by index blob: */
    00449     virtual CvBlob* GetBlob(int BlobIndex) = 0;
    00450
    00451     /* Delete blob by its index: */
    00452     virtual void    DelBlob(int BlobIndex) = 0;
    00453
    00454     /* Process current image and track all existed blobs: */
    00455     virtual void    Process(IplImage* pImg, IplImage* pImgFG = NULL) = 0;
    00456
    00457     /* Release blob tracker: */
    00458     virtual void    Release() = 0;
    00459
    00460
    00461     /* Process one blob (for multi hypothesis tracing): */
    00462     virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL);
    00463
    00464     /* Get confidence/wieght/probability (0-1) for blob: */
    00465     virtual double  GetConfidence(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL);
    00466
    00467     virtual double GetConfidenceList(CvBlobSeq* pBlobList, IplImage* pImg, IplImage* pImgFG = NULL);
    00468
    00469     virtual void UpdateBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL);
    00470
    00471     /* Update all blob models: */
    00472     virtual void Update(IplImage* pImg, IplImage* pImgFG = NULL);
    00473
    00474     /* Return pointer to blob by its unique ID: */
    00475     virtual int     GetBlobIndexByID(int BlobID);
    00476
    00477     /* Return pointer to blob by its unique ID: */
    00478     virtual CvBlob* GetBlobByID(int BlobID);
    00479
    00480     /* Delete blob by its ID: */
    00481     virtual void    DelBlobByID(int BlobID);
    00482
    00483     /* Set new parameters for specified (by index) blob: */
    00484     virtual void    SetBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/);
    00485
    00486     /* Set new parameters for specified (by ID) blob: */
    00487     virtual void    SetBlobByID(int BlobID, CvBlob* pBlob);
    00488
    00489     /*  ===============  MULTI HYPOTHESIS INTERFACE ==================  */
    00490
    00491     /* Return number of position hyposetis of currently tracked blob: */
    00492     virtual int     GetBlobHypNum(int /*BlobIdx*/);
    00493
    00494     /* Return pointer to specified blob hypothesis by index blob: */
    00495     virtual CvBlob* GetBlobHyp(int BlobIndex, int /*hypothesis*/);
    00496
    00497     /* Set new parameters for specified (by index) blob hyp
    00498      * (can be called several times for each hyp ):
    00499      */
    00500     virtual void    SetBlobHyp(int /*BlobIndex*/, CvBlob* /*pBlob*/);
    00501 };
    00502
    00503 CV_EXPORTS void cvReleaseBlobTracker(CvBlobTracker**ppT );
    00504 /* BLOB TRACKER INTERFACE */
    00505
    00506 /*BLOB TRACKER ONE INTERFACE */
    00507 class CV_EXPORTS CvBlobTrackerOne : public CvVSModule
    00508 {
    00509 public:
    00510     virtual void Init(CvBlob* pBlobInit, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
    00511     virtual CvBlob* Process(CvBlob* pBlobPrev, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
    00512     virtual void Release() =  0;
    00513
    00514     /* Non-required methods: */
    00515     virtual void SkipProcess(CvBlob* /*pBlobPrev*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
    00516     virtual void Update(CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
    00517     virtual void SetCollision(int /*CollisionFlag*/){}; /* call in case of blob collision situation*/
    00518     virtual double GetConfidence(CvBlob* /*pBlob*/, IplImage* /*pImg*/,
    00519                                  IplImage* /*pImgFG*/ = NULL, IplImage* /*pImgUnusedReg*/ = NULL)
    00520     {
    00521         return 1;
    00522     };
    00523 };
    00524 inline void cvReleaseBlobTrackerOne(CvBlobTrackerOne **ppT )
    00525 {
    00526     ppT[0]->Release();
    00527     ppT[0] = 0;
    00528 }
    00529 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerList(CvBlobTrackerOne* (*create)());
    00530 /*BLOB TRACKER ONE INTERFACE */
    00531
    00532 /* Declarations of constructors of implemented modules: */
    00533
    00534 /* Some declarations for specific MeanShift tracker: */
    00535 #define PROFILE_EPANECHNIKOV    0
    00536 #define PROFILE_DOG             1
    00537 struct CvBlobTrackerParamMS
    00538 {
    00539     int     noOfSigBits;
    00540     int     appearance_profile;
    00541     int     meanshift_profile;
    00542     float   sigma;
    00543 };
    00544
    00545 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1(CvBlobTrackerParamMS* param);
    00546 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS2(CvBlobTrackerParamMS* param);
    00547 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1ByList();
    00548
    00549 /* Some declarations for specific Likelihood tracker: */
    00550 struct CvBlobTrackerParamLH
    00551 {
    00552     int     HistType; /* see Prob.h */
    00553     int     ScaleAfter;
    00554 };
    00555
    00556 /* Without scale optimization: */
    00557 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHR(CvBlobTrackerParamLH* /*param*/ = NULL);
    00558
    00559 /* With scale optimization: */
    00560 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHRS(CvBlobTrackerParamLH* /*param*/ = NULL);
    00561
    00562 /* Simple blob tracker based on connected component tracking: */
    00563 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCC();
    00564
    00565 /* Connected component tracking and mean-shift particle filter collion-resolver: */
    00566 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCCMSPF();
    00567
    00568 /* Blob tracker that integrates meanshift and connected components: */
    00569 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFG();
    00570 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFGS();
    00571
    00572 /* Meanshift without connected-components */
    00573 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS();
    00574
    00575 /* Particle filtering via Bhattacharya coefficient, which        */
    00576 /* is roughly the dot-product of two probability densities.      */
    00577 /* See: Real-Time Tracking of Non-Rigid Objects using Mean Shift */
    00578 /*      Comanicius, Ramesh, Meer, 2000, 8p                       */
    00579 /*      http://citeseer.ist.psu.edu/321441.html                  */
    00580 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSPF();
    00581
    00582 /* =========== tracker integrators trackers =============*/
    00583
    00584 /* Integrator based on Particle Filtering method: */
    00585 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPF();
    00586
    00587 /* Rule based integrator: */
    00588 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIRB();
    00589
    00590 /* Integrator based on data fusion using particle filtering: */
    00591 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPFDF();
    00592
    00593
    00594
    00595
    00596 /* Trajectory postprocessing module: */
    00597 class CV_EXPORTS CvBlobTrackPostProc: public CvVSModule
    00598 {
    00599 public:
    00600         CvBlobTrackPostProc(){SetTypeName("BlobTrackPostProc");};
    00601     virtual void    AddBlob(CvBlob* pBlob) = 0;
    00602     virtual void    Process() = 0;
    00603     virtual int     GetBlobNum() = 0;
    00604     virtual CvBlob* GetBlob(int index) = 0;
    00605     virtual void    Release() = 0;
    00606
    00607     /* Additional functionality: */
    00608     virtual CvBlob* GetBlobByID(int BlobID)
    00609     {
    00610         int i;
    00611         for(i=GetBlobNum();i>0;i--)
    00612         {
    00613             CvBlob* pB=GetBlob(i-1);
    00614             if(pB->ID==BlobID) return pB;
    00615         }
    00616         return NULL;
    00617     };
    00618 };
    00619
    00620 inline void cvReleaseBlobTrackPostProc(CvBlobTrackPostProc** pBTPP)
    00621 {
    00622     if(pBTPP == NULL) return;
    00623     if(*pBTPP)(*pBTPP)->Release();
    00624     *pBTPP = 0;
    00625 }
    00626
    00627 /* Trajectory generation module: */
    00628 class CV_EXPORTS CvBlobTrackPostProcOne: public CvVSModule
    00629 {
    00630 public:
    00631         CvBlobTrackPostProcOne(){SetTypeName("BlobTrackPostOne");};
    00632     virtual CvBlob* Process(CvBlob* pBlob) = 0;
    00633     virtual void    Release() = 0;
    00634 };
    00635
    00636 /* Create blob tracking post processing module based on simle module: */
    00637 CV_EXPORTS CvBlobTrackPostProc* cvCreateBlobTrackPostProcList(CvBlobTrackPostProcOne* (*create)());
    00638
    00639
    00640 /* Declarations of constructors of implemented modules: */
    00641 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcKalman();
    00642 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverRect();
    00643 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverExp();
    00644
    00645
    00646 /* PREDICTORS */
    00647 /* blob PREDICTOR */
    00648 class CvBlobTrackPredictor: public CvVSModule
    00649 {
    00650 public:
    00651         CvBlobTrackPredictor(){SetTypeName("BlobTrackPredictor");};
    00652     virtual CvBlob* Predict() = 0;
    00653     virtual void    Update(CvBlob* pBlob) = 0;
    00654     virtual void    Release() = 0;
    00655 };
    00656 CV_EXPORTS CvBlobTrackPredictor* cvCreateModuleBlobTrackPredictKalman();
    00657
    00658
    00659
    00660 /* Trajectory analyser module: */
    00661 class CV_EXPORTS CvBlobTrackAnalysis: public CvVSModule
    00662 {
    00663 public:
    00664         CvBlobTrackAnalysis(){SetTypeName("BlobTrackAnalysis");};
    00665     virtual void    AddBlob(CvBlob* pBlob) = 0;
    00666     virtual void    Process(IplImage* pImg, IplImage* pFG) = 0;
    00667     virtual float   GetState(int BlobID) = 0;
    00668     /* return 0 if trajectory is normal
    00669        return >0 if trajectory abnormal */
    00670     virtual const char*   GetStateDesc(int /*BlobID*/){return NULL;};
    00671     virtual void    SetFileName(char* /*DataBaseName*/){};
    00672     virtual void    Release() = 0;
    00673 };
    00674
    00675
    00676 inline void cvReleaseBlobTrackAnalysis(CvBlobTrackAnalysis** pBTPP)
    00677 {
    00678     if(pBTPP == NULL) return;
    00679     if(*pBTPP)(*pBTPP)->Release();
    00680     *pBTPP = 0;
    00681 }
    00682
    00683 /* Feature-vector generation module: */
    00684 class CV_EXPORTS CvBlobTrackFVGen : public CvVSModule
    00685 {
    00686 public:
    00687         CvBlobTrackFVGen(){SetTypeName("BlobTrackFVGen");};
    00688     virtual void    AddBlob(CvBlob* pBlob) = 0;
    00689     virtual void    Process(IplImage* pImg, IplImage* pFG) = 0;
    00690     virtual void    Release() = 0;
    00691     virtual int     GetFVSize() = 0;
    00692     virtual int     GetFVNum() = 0;
    00693     virtual float*  GetFV(int index, int* pFVID) = 0; /* Returns pointer to FV, if return 0 then FV not created */
    00694     virtual float*  GetFVVar(){return NULL;}; /* Returns pointer to array of variation of values of FV, if returns 0 then FVVar does not exist. */
    00695     virtual float*  GetFVMin() = 0; /* Returns pointer to array of minimal values of FV, if returns 0 then FVrange does not exist */
    00696     virtual float*  GetFVMax() = 0; /* Returns pointer to array of maximal values of FV, if returns 0 then FVrange does not exist */
    00697 };
    00698
    00699
    00700 /* Trajectory Analyser module: */
    00701 class CV_EXPORTS CvBlobTrackAnalysisOne
    00702 {
    00703 public:
    00704     virtual ~CvBlobTrackAnalysisOne() {};
    00705     virtual int     Process(CvBlob* pBlob, IplImage* pImg, IplImage* pFG) = 0;
    00706     /* return 0 if trajectory is normal
    00707        return >0 if trajectory abnormal */
    00708     virtual void    Release() = 0;
    00709 };
    00710
    00711 /* Create blob tracking post processing module based on simle module: */
    00712 CV_EXPORTS CvBlobTrackAnalysis* cvCreateBlobTrackAnalysisList(CvBlobTrackAnalysisOne* (*create)());
    00713
    00714 /* Declarations of constructors of implemented modules: */
    00715
    00716 /* Based on histogram analysis of 2D FV (x,y): */
    00717 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistP();
    00718
    00719 /* Based on histogram analysis of 4D FV (x,y,vx,vy): */
    00720 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPV();
    00721
    00722 /* Based on histogram analysis of 5D FV (x,y,vx,vy,state): */
    00723 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPVS();
    00724
    00725 /* Based on histogram analysis of 4D FV (startpos,stoppos): */
    00726 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistSS();
    00727
    00728
    00729
    00730 /* Based on SVM classifier analysis of 2D FV (x,y): */
    00731 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP();
    00732
    00733 /* Based on SVM classifier analysis of 4D FV (x,y,vx,vy): */
    00734 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPV();
    00735
    00736 /* Based on SVM classifier analysis of 5D FV (x,y,vx,vy,state): */
    00737 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS();
    00738
    00739 /* Based on SVM classifier analysis of 4D FV (startpos,stoppos): */
    00740 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS();
    00741
    00742 /* Track analysis based on distance between tracks: */
    00743 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisTrackDist();
    00744
    00745 /* Analyzer based on reation Road and height map: */
    00746 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysis3DRoadMap();
    00747
    00748 /* Analyzer that makes OR decision using set of analyzers: */
    00749 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR();
    00750
    00751 /* Estimator of human height: */
    00752 class CV_EXPORTS CvBlobTrackAnalysisHeight: public CvBlobTrackAnalysis
    00753 {
    00754 public:
    00755     virtual double  GetHeight(CvBlob* pB) = 0;
    00756 };
    00757 //CV_EXPORTS CvBlobTrackAnalysisHeight* cvCreateModuleBlobTrackAnalysisHeightScale();
    00758
    00759
    00760
    00761 /* AUTO BLOB TRACKER INTERFACE -- pipeline of 3 modules: */
    00762 class CV_EXPORTS CvBlobTrackerAuto: public CvVSModule
    00763 {
    00764 public:
    00765         CvBlobTrackerAuto(){SetTypeName("BlobTrackerAuto");};
    00766     virtual void        Process(IplImage* pImg, IplImage* pMask = NULL) = 0;
    00767     virtual CvBlob*     GetBlob(int index) = 0;
    00768     virtual CvBlob*     GetBlobByID(int ID) = 0;
    00769     virtual int         GetBlobNum() = 0;
    00770     virtual IplImage*   GetFGMask(){return NULL;};
    00771     virtual float       GetState(int BlobID) = 0;
    00772     virtual const char*       GetStateDesc(int BlobID) = 0;
    00773     /* return 0 if trajectory is normal;
    00774      * return >0 if trajectory abnormal. */
    00775     virtual void    Release() = 0;
    00776 };
    00777 inline void cvReleaseBlobTrackerAuto(CvBlobTrackerAuto** ppT)
    00778 {
    00779     ppT[0]->Release();
    00780     ppT[0] = 0;
    00781 }
    00782 /* END AUTO BLOB TRACKER INTERFACE */
    00783
    00784
    00785 /* Constructor functions and data for specific BlobTRackerAuto modules: */
    00786
    00787 /* Parameters of blobtracker auto ver1: */
    00788 struct CvBlobTrackerAutoParam1
    00789 {
    00790     int                     FGTrainFrames; /* Number of frames needed for FG (foreground) detector to train.        */
    00791
    00792     CvFGDetector*           pFG;           /* FGDetector module. If this field is NULL the Process FG mask is used. */
    00793
    00794     CvBlobDetector*         pBD;           /* Selected blob detector module.                                        */
    00795                                            /* If this field is NULL default blobdetector module will be created.    */
    00796
    00797     CvBlobTracker*          pBT;           /* Selected blob tracking module.                                        */
    00798                                            /* If this field is NULL default blobtracker module will be created.     */
    00799
    00800     CvBlobTrackGen*         pBTGen;        /* Selected blob trajectory generator.                                   */
    00801                                            /* If this field is NULL no generator is used.                           */
    00802
    00803     CvBlobTrackPostProc*    pBTPP;         /* Selected blob trajectory postprocessing module.                       */
    00804                                            /* If this field is NULL no postprocessing is done.                      */
    00805
    00806     int                     UsePPData;
    00807
    00808     CvBlobTrackAnalysis*    pBTA;          /* Selected blob trajectory analysis module.                             */
    00809                                            /* If this field is NULL no track analysis is done.                      */
    00810 };
    00811
    00812 /* Create blob tracker auto ver1: */
    00813 CV_EXPORTS CvBlobTrackerAuto* cvCreateBlobTrackerAuto1(CvBlobTrackerAutoParam1* param = NULL);
    00814
    00815 /* Simple loader for many auto trackers by its type : */
    00816 inline CvBlobTrackerAuto* cvCreateBlobTrackerAuto(int type, void* param)
    00817 {
    00818     if(type == 0) return cvCreateBlobTrackerAuto1((CvBlobTrackerAutoParam1*)param);
    00819     return 0;
    00820 }
    00821
    00822
    00823
    00824 struct CvTracksTimePos
    00825 {
    00826     int len1,len2;
    00827     int beg1,beg2;
    00828     int end1,end2;
    00829     int comLen; //common length for two tracks
    00830     int shift1,shift2;
    00831 };
    00832
    00833 /*CV_EXPORTS int cvCompareTracks( CvBlobTrackSeq *groundTruth,
    00834                    CvBlobTrackSeq *result,
    00835                    FILE *file);*/
    00836
    00837
    00838 /* Constructor functions:  */
    00839
    00840 CV_EXPORTS void cvCreateTracks_One(CvBlobTrackSeq *TS);
    00841 CV_EXPORTS void cvCreateTracks_Same(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2);
    00842 CV_EXPORTS void cvCreateTracks_AreaErr(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2, int addW, int addH);
    00843
    00844
    00845 /* HIST API */
    00846 class CV_EXPORTS CvProb
    00847 {
    00848 public:
    00849     virtual ~CvProb() {};
    00850
    00851     /* Calculate probability value: */
    00852     virtual double Value(int* /*comp*/, int /*x*/ = 0, int /*y*/ = 0){return -1;};
    00853
    00854     /* Update histograpp Pnew = (1-W)*Pold + W*Padd*/
    00855     /* W weight of new added prob */
    00856     /* comps - matrix of new fetature vectors used to update prob */
    00857     virtual void AddFeature(float W, int* comps, int x =0, int y = 0) = 0;
    00858     virtual void Scale(float factor = 0, int x = -1, int y = -1) = 0;
    00859     virtual void Release() = 0;
    00860 };
    00861 inline void cvReleaseProb(CvProb** ppProb){ppProb[0]->Release();ppProb[0]=NULL;}
    00862 /* HIST API */
    00863
    00864 /* Some Prob: */
    00865 CV_EXPORTS CvProb* cvCreateProbS(int dim, CvSize size, int sample_num);
    00866 CV_EXPORTS CvProb* cvCreateProbMG(int dim, CvSize size, int sample_num);
    00867 CV_EXPORTS CvProb* cvCreateProbMG2(int dim, CvSize size, int sample_num);
    00868 CV_EXPORTS CvProb* cvCreateProbHist(int dim, CvSize size);
    00869
    00870 #define CV_BT_HIST_TYPE_S     0
    00871 #define CV_BT_HIST_TYPE_MG    1
    00872 #define CV_BT_HIST_TYPE_MG2   2
    00873 #define CV_BT_HIST_TYPE_H     3
    00874 inline CvProb* cvCreateProb(int type, int dim, CvSize size = cvSize(1,1), void* /*param*/ = NULL)
    00875 {
    00876     if(type == CV_BT_HIST_TYPE_S) return cvCreateProbS(dim, size, -1);
    00877     if(type == CV_BT_HIST_TYPE_MG) return cvCreateProbMG(dim, size, -1);
    00878     if(type == CV_BT_HIST_TYPE_MG2) return cvCreateProbMG2(dim, size, -1);
    00879     if(type == CV_BT_HIST_TYPE_H) return cvCreateProbHist(dim, size);
    00880     return NULL;
    00881 }
    00882
    00883
    00884
    00885 /* Noise type definitions: */
    00886 #define CV_NOISE_NONE               0
    00887 #define CV_NOISE_GAUSSIAN           1
    00888 #define CV_NOISE_UNIFORM            2
    00889 #define CV_NOISE_SPECKLE            3
    00890 #define CV_NOISE_SALT_AND_PEPPER    4
    00891
    00892 /* Add some noise to image: */
    00893 /* pImg - (input) image without noise */
    00894 /* pImg - (output) image with noise */
    00895 /* noise_type - type of added noise */
    00896 /*  CV_NOISE_GAUSSIAN - pImg += n , n - is gaussian noise with Ampl standart deviation */
    00897 /*  CV_NOISE_UNIFORM - pImg += n , n - is uniform noise with Ampl standart deviation */
    00898 /*  CV_NOISE_SPECKLE - pImg += n*pImg , n - is gaussian noise with Ampl standart deviation */
    00899 /*  CV_NOISE_SALT_AND_PAPPER - pImg = pImg with blacked and whited pixels,
    00900             Ampl is density of brocken pixels (0-there are not broken pixels, 1 - all pixels are broken)*/
    00901 /* Ampl - "amplitude" of noise */
    00902 //CV_EXPORTS void cvAddNoise(IplImage* pImg, int noise_type, double Ampl, CvRNG* rnd_state = NULL);
    00903
    00904 /*================== GENERATOR OF TEST VIDEO SEQUENCE ===================== */
    00905 typedef void CvTestSeq;
    00906
    00907 /* pConfigfile - Name of file (yml or xml) with description of test sequence */
    00908 /* videos - array of names of test videos described in "pConfigfile" file */
    00909 /* numvideos - size of "videos" array */
    00910 CV_EXPORTS CvTestSeq* cvCreateTestSeq(char* pConfigfile, char** videos, int numvideo, float Scale = 1, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
    00911 CV_EXPORTS void cvReleaseTestSeq(CvTestSeq** ppTestSeq);
    00912
    00913 /* Generate next frame from test video seq and return pointer to it: */
    00914 CV_EXPORTS IplImage* cvTestSeqQueryFrame(CvTestSeq* pTestSeq);
    00915
    00916 /* Return pointer to current foreground mask: */
    00917 CV_EXPORTS IplImage* cvTestSeqGetFGMask(CvTestSeq* pTestSeq);
    00918
    00919 /* Return pointer to current image: */
    00920 CV_EXPORTS IplImage* cvTestSeqGetImage(CvTestSeq* pTestSeq);
    00921
    00922 /* Return frame size of result test video: */
    00923 CV_EXPORTS CvSize cvTestSeqGetImageSize(CvTestSeq* pTestSeq);
    00924
    00925 /* Return number of frames result test video: */
    00926 CV_EXPORTS int cvTestSeqFrameNum(CvTestSeq* pTestSeq);
    00927
    00928 /* Return number of existing objects.
    00929  * This is general number of any objects.
    00930  * For example number of trajectories may be equal or less than returned value:
    00931  */
    00932 CV_EXPORTS int cvTestSeqGetObjectNum(CvTestSeq* pTestSeq);
    00933
    00934 /* Return 0 if there is not position for current defined on current frame */
    00935 /* Return 1 if there is object position and pPos was filled */
    00936 CV_EXPORTS int cvTestSeqGetObjectPos(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pPos);
    00937 CV_EXPORTS int cvTestSeqGetObjectSize(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pSize);
    00938
    00939 /* Add noise to final image: */
    00940 CV_EXPORTS void cvTestSeqAddNoise(CvTestSeq* pTestSeq, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
    00941
    00942 /* Add Intensity variation: */
    00943 CV_EXPORTS void cvTestSeqAddIntensityVariation(CvTestSeq* pTestSeq, float DI_per_frame, float MinI, float MaxI);
    00944 CV_EXPORTS void cvTestSeqSetFrame(CvTestSeq* pTestSeq, int n);
    00945
    00946 #endif
    00947
    00948 /* End of file. */

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines