1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
43 #ifndef __OPENCV_VIDEOSURVEILLANCE_H__
44 #define __OPENCV_VIDEOSURVEILLANCE_H__
46 /* Turn off the functionality until cvaux/src/Makefile.am gets updated: */
47 //#if _MSC_VER >= 1200
49 #include "opencv2/core/core_c.h"
52 #if (defined _MSC_VER && _MSC_VER >= 1200) || defined __BORLANDC__
53 #define cv_stricmp stricmp
54 #define cv_strnicmp strnicmp
56 #define strdup _strdup
57 #define stricmp _stricmp
59 #elif defined __GNUC__ || defined __sun
60 #define cv_stricmp strcasecmp
61 #define cv_strnicmp strncasecmp
63 #error Do not know how to make case-insensitive string comparison on this platform
69 struct CvDefParam* next;
82 class CV_EXPORTS CvVSModule
84 private: /* Internal data: */
85 CvDefParam* m_pParamList;
86 char* m_pModuleTypeName;
91 public: /* Constructor and destructor: */
93 virtual ~CvVSModule();
94 private: /* Internal functions: */
95 void FreeParam(CvDefParam** pp);
96 CvDefParam* NewParam(const char* name);
97 CvDefParam* GetParamPtr(int index);
98 CvDefParam* GetParamPtr(const char* name);
99 protected: /* INTERNAL INTERFACE */
100 int IsParam(const char* name);
101 void AddParam(const char* name, double* pAddr);
102 void AddParam(const char* name, float* pAddr);
103 void AddParam(const char* name, int* pAddr);
104 void AddParam(const char* name, const char** pAddr);
105 void AddParam(const char* name);
106 void CommentParam(const char* name, const char* pComment);
107 void SetTypeName(const char* name);
108 void SetModuleName(const char* name);
109 void DelParam(const char* name);
111 public: /* EXTERNAL INTERFACE */
112 const char* GetParamName(int index);
113 const char* GetParamComment(const char* name);
114 double GetParam(const char* name);
115 const char* GetParamStr(const char* name);
116 void SetParam(const char* name, double val);
117 void SetParamStr(const char* name, const char* str);
118 void TransferParamsFromChild(CvVSModule* pM, const char* prefix = NULL);
119 void TransferParamsToChild(CvVSModule* pM, char* prefix = NULL);
120 virtual void ParamUpdate();
121 const char* GetTypeName();
122 int IsModuleTypeName(const char* name);
123 char* GetModuleName();
124 int IsModuleName(const char* name);
125 void SetNickName(const char* pStr);
126 const char* GetNickName();
127 virtual void SaveState(CvFileStorage*);
128 virtual void LoadState(CvFileStorage*, CvFileNode*);
130 virtual void Release() = 0;
133 CV_EXPORTS void cvWriteStruct(CvFileStorage* fs, const char* name, void* addr, const char* desc, int num=1);
134 CV_EXPORTS void cvReadStructByName(CvFileStorage* fs, CvFileNode* node, const char* name, void* addr, const char* desc);
136 /* FOREGROUND DETECTOR INTERFACE */
137 class CV_EXPORTS CvFGDetector : public CvVSModule
141 virtual IplImage* GetMask() = 0;
142 /* Process current image: */
143 virtual void Process(IplImage* pImg) = 0;
144 /* Release foreground detector: */
145 virtual void Release() = 0;
148 CV_EXPORTS void cvReleaseFGDetector(CvFGDetector** ppT );
149 CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param);
155 float x,y; /* blob position */
156 float w,h; /* blob sizes */
157 int ID; /* blob ID */
160 inline CvBlob cvBlob(float x,float y, float w, float h)
162 CvBlob B = {x,y,w,h,0};
165 #define CV_BLOB_MINW 5
166 #define CV_BLOB_MINH 5
167 #define CV_BLOB_ID(pB) (((CvBlob*)(pB))->ID)
168 #define CV_BLOB_CENTER(pB) cvPoint2D32f(((CvBlob*)(pB))->x,((CvBlob*)(pB))->y)
169 #define CV_BLOB_X(pB) (((CvBlob*)(pB))->x)
170 #define CV_BLOB_Y(pB) (((CvBlob*)(pB))->y)
171 #define CV_BLOB_WX(pB) (((CvBlob*)(pB))->w)
172 #define CV_BLOB_WY(pB) (((CvBlob*)(pB))->h)
173 #define CV_BLOB_RX(pB) (0.5f*CV_BLOB_WX(pB))
174 #define CV_BLOB_RY(pB) (0.5f*CV_BLOB_WY(pB))
175 #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)))
176 /* END BLOB STRUCTURE*/
179 /* simple BLOBLIST */
180 class CV_EXPORTS CvBlobSeq
183 CvBlobSeq(int BlobSize = sizeof(CvBlob))
185 m_pMem = cvCreateMemStorage();
186 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),BlobSize,m_pMem);
187 strcpy(m_pElemFormat,"ffffi");
191 cvReleaseMemStorage(&m_pMem);
193 virtual CvBlob* GetBlob(int BlobIndex)
195 return (CvBlob*)cvGetSeqElem(m_pSeq,BlobIndex);
197 virtual CvBlob* GetBlobByID(int BlobID)
200 for(i=0; i<m_pSeq->total; ++i)
201 if(BlobID == CV_BLOB_ID(GetBlob(i)))
205 virtual void DelBlob(int BlobIndex)
207 cvSeqRemove(m_pSeq,BlobIndex);
209 virtual void DelBlobByID(int BlobID)
212 for(i=0; i<m_pSeq->total; ++i)
214 if(BlobID == CV_BLOB_ID(GetBlob(i)))
225 virtual void AddBlob(CvBlob* pB)
227 cvSeqPush(m_pSeq,pB);
229 virtual int GetBlobNum()
231 return m_pSeq->total;
233 virtual void Write(CvFileStorage* fs, const char* name)
235 const char* attr[] = {"dt",m_pElemFormat,NULL};
238 cvWrite(fs,name,m_pSeq,cvAttrList(attr,NULL));
241 virtual void Load(CvFileStorage* fs, CvFileNode* node)
244 CvSeq* pSeq = (CvSeq*)cvRead(fs, node);
249 for(i=0;i<pSeq->total;++i)
251 void* pB = cvGetSeqElem( pSeq, i );
252 cvSeqPush( m_pSeq, pB );
256 void AddFormat(const char* str){strcat(m_pElemFormat,str);}
258 CvMemStorage* m_pMem;
260 char m_pElemFormat[1024];
262 /* simple BLOBLIST */
265 /* simple TRACKLIST */
273 class CV_EXPORTS CvBlobTrackSeq
276 CvBlobTrackSeq(int TrackSize = sizeof(CvBlobTrack));
277 virtual ~CvBlobTrackSeq();
278 virtual CvBlobTrack* GetBlobTrack(int TrackIndex);
279 virtual CvBlobTrack* GetBlobTrackByID(int TrackID);
280 virtual void DelBlobTrack(int TrackIndex);
281 virtual void DelBlobTrackByID(int TrackID);
282 virtual void Clear();
283 virtual void AddBlobTrack(int TrackID, int StartFrame = 0);
284 virtual int GetBlobTrackNum();
286 CvMemStorage* m_pMem;
290 /* simple TRACKLIST */
293 /* BLOB DETECTOR INTERFACE */
294 class CV_EXPORTS CvBlobDetector: public CvVSModule
297 CvBlobDetector(){SetTypeName("BlobDetector");};
298 /* Try to detect new blob entrance based on foreground mask. */
299 /* pFGMask - image of foreground mask */
300 /* pNewBlob - pointer to CvBlob structure which will be filled if new blob entrance detected */
301 /* pOldBlobList - pointer to blob list which already exist on image */
302 virtual int DetectNewBlob(IplImage* pImg, IplImage* pImgFG, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList) = 0;
303 /* release blob detector */
304 virtual void Release()=0;
307 /* Release any blob detector: */
308 CV_EXPORTS void cvReleaseBlobDetector(CvBlobDetector** ppBD);
310 /* Declarations of constructors of implemented modules: */
311 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorSimple();
312 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorCC();
314 struct CV_EXPORTS CvDetectedBlob : public CvBlob
319 CV_INLINE CvDetectedBlob cvDetectedBlob( float x, float y, float w, float h, int ID = 0, float response = 0.0F )
322 b.x = x; b.y = y; b.w = w; b.h = h; b.ID = ID; b.response = response;
327 class CV_EXPORTS CvObjectDetector
330 CvObjectDetector( const char* /*detector_file_name*/ = 0 );
334 * Release the current detector and load new detector from file
335 * (if detector_file_name is not 0)
336 * Return true on success:
338 bool Load( const char* /*detector_file_name*/ = 0 );
340 /* Return min detector window size: */
341 CvSize GetMinWindowSize() const;
343 /* Return max border: */
344 int GetMaxBorderSize() const;
347 * Detect the object on the image and push the detected
348 * blobs into <detected_blob_seq> which must be the sequence of <CvDetectedBlob>s
350 void Detect( const CvArr* /*img*/, /* out */ CvBlobSeq* /*detected_blob_seq*/ = 0 );
353 class CvObjectDetectorImpl* impl;
357 CV_INLINE CvRect cvRectIntersection( const CvRect r1, const CvRect r2 )
359 CvRect r = cvRect( MAX(r1.x, r2.x), MAX(r1.y, r2.y), 0, 0 );
361 r.width = MIN(r1.x + r1.width, r2.x + r2.width) - r.x;
362 r.height = MIN(r1.y + r1.height, r2.y + r2.height) - r.y;
371 * Draw on an image the specified ROIs from the source image and
372 * given blobs as ellipses or rectangles:
377 enum {RECT, ELLIPSE} shape;
381 /*extern const CvDrawShape icv_shape[] =
383 { CvDrawShape::ELLIPSE, CV_RGB(255,0,0) },
384 { CvDrawShape::ELLIPSE, CV_RGB(0,255,0) },
385 { CvDrawShape::ELLIPSE, CV_RGB(0,0,255) },
386 { CvDrawShape::ELLIPSE, CV_RGB(255,255,0) },
387 { CvDrawShape::ELLIPSE, CV_RGB(0,255,255) },
388 { CvDrawShape::ELLIPSE, CV_RGB(255,0,255) }
391 class CV_EXPORTS CvImageDrawer
394 CvImageDrawer() : m_image(0) {}
395 ~CvImageDrawer() { cvReleaseImage( &m_image ); }
396 void SetShapes( const CvDrawShape* shapes, int num );
397 /* <blob_seq> must be the sequence of <CvDetectedBlob>s */
398 IplImage* Draw( const CvArr* src, CvBlobSeq* blob_seq = 0, const CvSeq* roi_seq = 0 );
399 IplImage* GetImage() { return m_image; }
401 //static const int MAX_SHAPES = sizeof(icv_shape) / sizeof(icv_shape[0]);;
404 CvDrawShape m_shape[16];
409 /* Trajectory generation module: */
410 class CV_EXPORTS CvBlobTrackGen: public CvVSModule
413 CvBlobTrackGen(){SetTypeName("BlobTrackGen");};
414 virtual void SetFileName(char* pFileName) = 0;
415 virtual void AddBlob(CvBlob* pBlob) = 0;
416 virtual void Process(IplImage* pImg = NULL, IplImage* pFG = NULL) = 0;
417 virtual void Release() = 0;
420 inline void cvReleaseBlobTrackGen(CvBlobTrackGen** pBTGen)
422 if(*pBTGen)(*pBTGen)->Release();
426 /* Declarations of constructors of implemented modules: */
427 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGen1();
428 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGenYML();
432 /* BLOB TRACKER INTERFACE */
433 class CV_EXPORTS CvBlobTracker: public CvVSModule
438 /* Add new blob to track it and assign to this blob personal ID */
439 /* pBlob - pointer to structure with blob parameters (ID is ignored)*/
440 /* pImg - current image */
441 /* pImgFG - current foreground mask */
442 /* Return pointer to new added blob: */
443 virtual CvBlob* AddBlob(CvBlob* pBlob, IplImage* pImg, IplImage* pImgFG = NULL ) = 0;
445 /* Return number of currently tracked blobs: */
446 virtual int GetBlobNum() = 0;
448 /* Return pointer to specified by index blob: */
449 virtual CvBlob* GetBlob(int BlobIndex) = 0;
451 /* Delete blob by its index: */
452 virtual void DelBlob(int BlobIndex) = 0;
454 /* Process current image and track all existed blobs: */
455 virtual void Process(IplImage* pImg, IplImage* pImgFG = NULL) = 0;
457 /* Release blob tracker: */
458 virtual void Release() = 0;
461 /* Process one blob (for multi hypothesis tracing): */
462 virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL);
464 /* Get confidence/wieght/probability (0-1) for blob: */
465 virtual double GetConfidence(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL);
467 virtual double GetConfidenceList(CvBlobSeq* pBlobList, IplImage* pImg, IplImage* pImgFG = NULL);
469 virtual void UpdateBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL);
471 /* Update all blob models: */
472 virtual void Update(IplImage* pImg, IplImage* pImgFG = NULL);
474 /* Return pointer to blob by its unique ID: */
475 virtual int GetBlobIndexByID(int BlobID);
477 /* Return pointer to blob by its unique ID: */
478 virtual CvBlob* GetBlobByID(int BlobID);
480 /* Delete blob by its ID: */
481 virtual void DelBlobByID(int BlobID);
483 /* Set new parameters for specified (by index) blob: */
484 virtual void SetBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/);
486 /* Set new parameters for specified (by ID) blob: */
487 virtual void SetBlobByID(int BlobID, CvBlob* pBlob);
489 /* =============== MULTI HYPOTHESIS INTERFACE ================== */
491 /* Return number of position hyposetis of currently tracked blob: */
492 virtual int GetBlobHypNum(int /*BlobIdx*/);
494 /* Return pointer to specified blob hypothesis by index blob: */
495 virtual CvBlob* GetBlobHyp(int BlobIndex, int /*hypothesis*/);
497 /* Set new parameters for specified (by index) blob hyp
498 * (can be called several times for each hyp ):
500 virtual void SetBlobHyp(int /*BlobIndex*/, CvBlob* /*pBlob*/);
503 CV_EXPORTS void cvReleaseBlobTracker(CvBlobTracker**ppT );
504 /* BLOB TRACKER INTERFACE */
506 /*BLOB TRACKER ONE INTERFACE */
507 class CV_EXPORTS CvBlobTrackerOne : public CvVSModule
510 virtual void Init(CvBlob* pBlobInit, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
511 virtual CvBlob* Process(CvBlob* pBlobPrev, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
512 virtual void Release() = 0;
514 /* Non-required methods: */
515 virtual void SkipProcess(CvBlob* /*pBlobPrev*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
516 virtual void Update(CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
517 virtual void SetCollision(int /*CollisionFlag*/){}; /* call in case of blob collision situation*/
518 virtual double GetConfidence(CvBlob* /*pBlob*/, IplImage* /*pImg*/,
519 IplImage* /*pImgFG*/ = NULL, IplImage* /*pImgUnusedReg*/ = NULL)
524 inline void cvReleaseBlobTrackerOne(CvBlobTrackerOne **ppT )
529 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerList(CvBlobTrackerOne* (*create)());
530 /*BLOB TRACKER ONE INTERFACE */
532 /* Declarations of constructors of implemented modules: */
534 /* Some declarations for specific MeanShift tracker: */
535 #define PROFILE_EPANECHNIKOV 0
536 #define PROFILE_DOG 1
537 struct CvBlobTrackerParamMS
540 int appearance_profile;
541 int meanshift_profile;
545 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1(CvBlobTrackerParamMS* param);
546 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS2(CvBlobTrackerParamMS* param);
547 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1ByList();
549 /* Some declarations for specific Likelihood tracker: */
550 struct CvBlobTrackerParamLH
552 int HistType; /* see Prob.h */
556 /* Without scale optimization: */
557 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHR(CvBlobTrackerParamLH* /*param*/ = NULL);
559 /* With scale optimization: */
560 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHRS(CvBlobTrackerParamLH* /*param*/ = NULL);
562 /* Simple blob tracker based on connected component tracking: */
563 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCC();
565 /* Connected component tracking and mean-shift particle filter collion-resolver: */
566 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCCMSPF();
568 /* Blob tracker that integrates meanshift and connected components: */
569 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFG();
570 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFGS();
572 /* Meanshift without connected-components */
573 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS();
575 /* Particle filtering via Bhattacharya coefficient, which */
576 /* is roughly the dot-product of two probability densities. */
577 /* See: Real-Time Tracking of Non-Rigid Objects using Mean Shift */
578 /* Comanicius, Ramesh, Meer, 2000, 8p */
579 /* http://citeseer.ist.psu.edu/321441.html */
580 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSPF();
582 /* =========== tracker integrators trackers =============*/
584 /* Integrator based on Particle Filtering method: */
585 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPF();
587 /* Rule based integrator: */
588 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIRB();
590 /* Integrator based on data fusion using particle filtering: */
591 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPFDF();
596 /* Trajectory postprocessing module: */
597 class CV_EXPORTS CvBlobTrackPostProc: public CvVSModule
600 CvBlobTrackPostProc(){SetTypeName("BlobTrackPostProc");};
601 virtual void AddBlob(CvBlob* pBlob) = 0;
602 virtual void Process() = 0;
603 virtual int GetBlobNum() = 0;
604 virtual CvBlob* GetBlob(int index) = 0;
605 virtual void Release() = 0;
607 /* Additional functionality: */
608 virtual CvBlob* GetBlobByID(int BlobID)
611 for(i=GetBlobNum();i>0;i--)
613 CvBlob* pB=GetBlob(i-1);
614 if(pB->ID==BlobID) return pB;
620 inline void cvReleaseBlobTrackPostProc(CvBlobTrackPostProc** pBTPP)
622 if(pBTPP == NULL) return;
623 if(*pBTPP)(*pBTPP)->Release();
627 /* Trajectory generation module: */
628 class CV_EXPORTS CvBlobTrackPostProcOne: public CvVSModule
631 CvBlobTrackPostProcOne(){SetTypeName("BlobTrackPostOne");};
632 virtual CvBlob* Process(CvBlob* pBlob) = 0;
633 virtual void Release() = 0;
636 /* Create blob tracking post processing module based on simle module: */
637 CV_EXPORTS CvBlobTrackPostProc* cvCreateBlobTrackPostProcList(CvBlobTrackPostProcOne* (*create)());
640 /* Declarations of constructors of implemented modules: */
641 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcKalman();
642 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverRect();
643 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverExp();
648 class CvBlobTrackPredictor: public CvVSModule
651 CvBlobTrackPredictor(){SetTypeName("BlobTrackPredictor");};
652 virtual CvBlob* Predict() = 0;
653 virtual void Update(CvBlob* pBlob) = 0;
654 virtual void Release() = 0;
656 CV_EXPORTS CvBlobTrackPredictor* cvCreateModuleBlobTrackPredictKalman();
660 /* Trajectory analyser module: */
661 class CV_EXPORTS CvBlobTrackAnalysis: public CvVSModule
664 CvBlobTrackAnalysis(){SetTypeName("BlobTrackAnalysis");};
665 virtual void AddBlob(CvBlob* pBlob) = 0;
666 virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
667 virtual float GetState(int BlobID) = 0;
668 /* return 0 if trajectory is normal
669 return >0 if trajectory abnormal */
670 virtual const char* GetStateDesc(int /*BlobID*/){return NULL;};
671 virtual void SetFileName(char* /*DataBaseName*/){};
672 virtual void Release() = 0;
676 inline void cvReleaseBlobTrackAnalysis(CvBlobTrackAnalysis** pBTPP)
678 if(pBTPP == NULL) return;
679 if(*pBTPP)(*pBTPP)->Release();
683 /* Feature-vector generation module: */
684 class CV_EXPORTS CvBlobTrackFVGen : public CvVSModule
687 CvBlobTrackFVGen(){SetTypeName("BlobTrackFVGen");};
688 virtual void AddBlob(CvBlob* pBlob) = 0;
689 virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
690 virtual void Release() = 0;
691 virtual int GetFVSize() = 0;
692 virtual int GetFVNum() = 0;
693 virtual float* GetFV(int index, int* pFVID) = 0; /* Returns pointer to FV, if return 0 then FV not created */
694 virtual float* GetFVVar(){return NULL;}; /* Returns pointer to array of variation of values of FV, if returns 0 then FVVar does not exist. */
695 virtual float* GetFVMin() = 0; /* Returns pointer to array of minimal values of FV, if returns 0 then FVrange does not exist */
696 virtual float* GetFVMax() = 0; /* Returns pointer to array of maximal values of FV, if returns 0 then FVrange does not exist */
700 /* Trajectory Analyser module: */
701 class CV_EXPORTS CvBlobTrackAnalysisOne
704 virtual ~CvBlobTrackAnalysisOne() {};
705 virtual int Process(CvBlob* pBlob, IplImage* pImg, IplImage* pFG) = 0;
706 /* return 0 if trajectory is normal
707 return >0 if trajectory abnormal */
708 virtual void Release() = 0;
711 /* Create blob tracking post processing module based on simle module: */
712 CV_EXPORTS CvBlobTrackAnalysis* cvCreateBlobTrackAnalysisList(CvBlobTrackAnalysisOne* (*create)());
714 /* Declarations of constructors of implemented modules: */
716 /* Based on histogram analysis of 2D FV (x,y): */
717 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistP();
719 /* Based on histogram analysis of 4D FV (x,y,vx,vy): */
720 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPV();
722 /* Based on histogram analysis of 5D FV (x,y,vx,vy,state): */
723 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPVS();
725 /* Based on histogram analysis of 4D FV (startpos,stoppos): */
726 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistSS();
730 /* Based on SVM classifier analysis of 2D FV (x,y): */
731 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP();
733 /* Based on SVM classifier analysis of 4D FV (x,y,vx,vy): */
734 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPV();
736 /* Based on SVM classifier analysis of 5D FV (x,y,vx,vy,state): */
737 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS();
739 /* Based on SVM classifier analysis of 4D FV (startpos,stoppos): */
740 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS();
742 /* Track analysis based on distance between tracks: */
743 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisTrackDist();
745 /* Analyzer based on reation Road and height map: */
746 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysis3DRoadMap();
748 /* Analyzer that makes OR decision using set of analyzers: */
749 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR();
751 /* Estimator of human height: */
752 class CV_EXPORTS CvBlobTrackAnalysisHeight: public CvBlobTrackAnalysis
755 virtual double GetHeight(CvBlob* pB) = 0;
757 //CV_EXPORTS CvBlobTrackAnalysisHeight* cvCreateModuleBlobTrackAnalysisHeightScale();
761 /* AUTO BLOB TRACKER INTERFACE -- pipeline of 3 modules: */
762 class CV_EXPORTS CvBlobTrackerAuto: public CvVSModule
765 CvBlobTrackerAuto(){SetTypeName("BlobTrackerAuto");};
766 virtual void Process(IplImage* pImg, IplImage* pMask = NULL) = 0;
767 virtual CvBlob* GetBlob(int index) = 0;
768 virtual CvBlob* GetBlobByID(int ID) = 0;
769 virtual int GetBlobNum() = 0;
770 virtual IplImage* GetFGMask(){return NULL;};
771 virtual float GetState(int BlobID) = 0;
772 virtual const char* GetStateDesc(int BlobID) = 0;
773 /* return 0 if trajectory is normal;
774 * return >0 if trajectory abnormal. */
775 virtual void Release() = 0;
777 inline void cvReleaseBlobTrackerAuto(CvBlobTrackerAuto** ppT)
782 /* END AUTO BLOB TRACKER INTERFACE */
785 /* Constructor functions and data for specific BlobTRackerAuto modules: */
787 /* Parameters of blobtracker auto ver1: */
788 struct CvBlobTrackerAutoParam1
790 int FGTrainFrames; /* Number of frames needed for FG (foreground) detector to train. */
792 CvFGDetector* pFG; /* FGDetector module. If this field is NULL the Process FG mask is used. */
794 CvBlobDetector* pBD; /* Selected blob detector module. */
795 /* If this field is NULL default blobdetector module will be created. */
797 CvBlobTracker* pBT; /* Selected blob tracking module. */
798 /* If this field is NULL default blobtracker module will be created. */
800 CvBlobTrackGen* pBTGen; /* Selected blob trajectory generator. */
801 /* If this field is NULL no generator is used. */
803 CvBlobTrackPostProc* pBTPP; /* Selected blob trajectory postprocessing module. */
804 /* If this field is NULL no postprocessing is done. */
808 CvBlobTrackAnalysis* pBTA; /* Selected blob trajectory analysis module. */
809 /* If this field is NULL no track analysis is done. */
812 /* Create blob tracker auto ver1: */
813 CV_EXPORTS CvBlobTrackerAuto* cvCreateBlobTrackerAuto1(CvBlobTrackerAutoParam1* param = NULL);
815 /* Simple loader for many auto trackers by its type : */
816 inline CvBlobTrackerAuto* cvCreateBlobTrackerAuto(int type, void* param)
818 if(type == 0) return cvCreateBlobTrackerAuto1((CvBlobTrackerAutoParam1*)param);
824 struct CvTracksTimePos
829 int comLen; //common length for two tracks
833 /*CV_EXPORTS int cvCompareTracks( CvBlobTrackSeq *groundTruth,
834 CvBlobTrackSeq *result,
838 /* Constructor functions: */
840 CV_EXPORTS void cvCreateTracks_One(CvBlobTrackSeq *TS);
841 CV_EXPORTS void cvCreateTracks_Same(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2);
842 CV_EXPORTS void cvCreateTracks_AreaErr(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2, int addW, int addH);
846 class CV_EXPORTS CvProb
849 virtual ~CvProb() {};
851 /* Calculate probability value: */
852 virtual double Value(int* /*comp*/, int /*x*/ = 0, int /*y*/ = 0){return -1;};
854 /* Update histograpp Pnew = (1-W)*Pold + W*Padd*/
855 /* W weight of new added prob */
856 /* comps - matrix of new fetature vectors used to update prob */
857 virtual void AddFeature(float W, int* comps, int x =0, int y = 0) = 0;
858 virtual void Scale(float factor = 0, int x = -1, int y = -1) = 0;
859 virtual void Release() = 0;
861 inline void cvReleaseProb(CvProb** ppProb){ppProb[0]->Release();ppProb[0]=NULL;}
865 CV_EXPORTS CvProb* cvCreateProbS(int dim, CvSize size, int sample_num);
866 CV_EXPORTS CvProb* cvCreateProbMG(int dim, CvSize size, int sample_num);
867 CV_EXPORTS CvProb* cvCreateProbMG2(int dim, CvSize size, int sample_num);
868 CV_EXPORTS CvProb* cvCreateProbHist(int dim, CvSize size);
870 #define CV_BT_HIST_TYPE_S 0
871 #define CV_BT_HIST_TYPE_MG 1
872 #define CV_BT_HIST_TYPE_MG2 2
873 #define CV_BT_HIST_TYPE_H 3
874 inline CvProb* cvCreateProb(int type, int dim, CvSize size = cvSize(1,1), void* /*param*/ = NULL)
876 if(type == CV_BT_HIST_TYPE_S) return cvCreateProbS(dim, size, -1);
877 if(type == CV_BT_HIST_TYPE_MG) return cvCreateProbMG(dim, size, -1);
878 if(type == CV_BT_HIST_TYPE_MG2) return cvCreateProbMG2(dim, size, -1);
879 if(type == CV_BT_HIST_TYPE_H) return cvCreateProbHist(dim, size);
885 /* Noise type definitions: */
886 #define CV_NOISE_NONE 0
887 #define CV_NOISE_GAUSSIAN 1
888 #define CV_NOISE_UNIFORM 2
889 #define CV_NOISE_SPECKLE 3
890 #define CV_NOISE_SALT_AND_PEPPER 4
892 /* Add some noise to image: */
893 /* pImg - (input) image without noise */
894 /* pImg - (output) image with noise */
895 /* noise_type - type of added noise */
896 /* CV_NOISE_GAUSSIAN - pImg += n , n - is gaussian noise with Ampl standart deviation */
897 /* CV_NOISE_UNIFORM - pImg += n , n - is uniform noise with Ampl standart deviation */
898 /* CV_NOISE_SPECKLE - pImg += n*pImg , n - is gaussian noise with Ampl standart deviation */
899 /* CV_NOISE_SALT_AND_PAPPER - pImg = pImg with blacked and whited pixels,
900 Ampl is density of brocken pixels (0-there are not broken pixels, 1 - all pixels are broken)*/
901 /* Ampl - "amplitude" of noise */
902 //CV_EXPORTS void cvAddNoise(IplImage* pImg, int noise_type, double Ampl, CvRNG* rnd_state = NULL);
904 /*================== GENERATOR OF TEST VIDEO SEQUENCE ===================== */
905 typedef void CvTestSeq;
907 /* pConfigfile - Name of file (yml or xml) with description of test sequence */
908 /* videos - array of names of test videos described in "pConfigfile" file */
909 /* numvideos - size of "videos" array */
910 CV_EXPORTS CvTestSeq* cvCreateTestSeq(char* pConfigfile, char** videos, int numvideo, float Scale = 1, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
911 CV_EXPORTS void cvReleaseTestSeq(CvTestSeq** ppTestSeq);
913 /* Generate next frame from test video seq and return pointer to it: */
914 CV_EXPORTS IplImage* cvTestSeqQueryFrame(CvTestSeq* pTestSeq);
916 /* Return pointer to current foreground mask: */
917 CV_EXPORTS IplImage* cvTestSeqGetFGMask(CvTestSeq* pTestSeq);
919 /* Return pointer to current image: */
920 CV_EXPORTS IplImage* cvTestSeqGetImage(CvTestSeq* pTestSeq);
922 /* Return frame size of result test video: */
923 CV_EXPORTS CvSize cvTestSeqGetImageSize(CvTestSeq* pTestSeq);
925 /* Return number of frames result test video: */
926 CV_EXPORTS int cvTestSeqFrameNum(CvTestSeq* pTestSeq);
928 /* Return number of existing objects.
929 * This is general number of any objects.
930 * For example number of trajectories may be equal or less than returned value:
932 CV_EXPORTS int cvTestSeqGetObjectNum(CvTestSeq* pTestSeq);
934 /* Return 0 if there is not position for current defined on current frame */
935 /* Return 1 if there is object position and pPos was filled */
936 CV_EXPORTS int cvTestSeqGetObjectPos(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pPos);
937 CV_EXPORTS int cvTestSeqGetObjectSize(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pSize);
939 /* Add noise to final image: */
940 CV_EXPORTS void cvTestSeqAddNoise(CvTestSeq* pTestSeq, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
942 /* Add Intensity variation: */
943 CV_EXPORTS void cvTestSeqAddIntensityVariation(CvTestSeq* pTestSeq, float DI_per_frame, float MinI, float MaxI);
944 CV_EXPORTS void cvTestSeqSetFrame(CvTestSeq* pTestSeq, int n);