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 __CVVIDEOSURVEILLANCE_H__
44 #define __CVVIDEOSURVEILLANCE_H__
46 /* turn off the functionality until cvaux/src/Makefile.am gets updated */
47 //#if _MSC_VER >= 1200
51 #if _MSC_VER >= 1200 || defined __BORLANDC__
52 #define cv_stricmp stricmp
53 #define cv_strnicmp strnicmp
54 #elif defined __GNUC__
55 #define cv_stricmp strcasecmp
56 #define cv_strnicmp strncasecmp
58 #error Do not know how to make case-insensitive string comparison on this platform
64 struct CvDefParam* next;
77 class CV_EXPORTS CvVSModule
79 private: /* internal data */
80 CvDefParam* m_pParamList;
81 char* m_pModuleTypeName;
86 public: /* constructor and destructor */
91 m_pModuleTypeName = NULL;
94 AddParam("DebugWnd",&m_Wnd);
98 CvDefParam* p = m_pParamList;
106 if(m_pModuleTypeName)free(m_pModuleTypeName);
107 if(m_pModuleName)free(m_pModuleName);
109 private: /* internal functions */
110 void FreeParam(CvDefParam** pp)
112 CvDefParam* p = pp[0];
113 if(p->Str)free(p->Str);
114 if(p->pName)free(p->pName);
115 if(p->pComment)free(p->pComment);
118 CvDefParam* NewParam(char* name)
120 CvDefParam* pNew = (CvDefParam*)cvAlloc(sizeof(CvDefParam));
121 memset(pNew,0,sizeof(CvDefParam));
122 pNew->pName = strdup(name);
123 if(m_pParamList==NULL)
129 CvDefParam* p = m_pParamList;
130 for(;p->next;p=p->next);
136 CvDefParam* GetParamPtr(int index)
138 CvDefParam* p = m_pParamList;
139 for(;index>0 && p;index--,p=p->next);
142 CvDefParam* GetParamPtr(char* name)
144 CvDefParam* p = m_pParamList;
147 if(cv_stricmp(p->pName,name)==0) break;
151 protected: /* INTERNAL INTERFACE */
152 int IsParam(char* name)
154 return GetParamPtr(name)?1:0;
156 void AddParam(char* name, double* pAddr)
158 NewParam(name)->pDouble = pAddr;
160 void AddParam(char* name, float* pAddr)
162 NewParam(name)->pFloat=pAddr;
164 void AddParam(char* name, int* pAddr)
166 NewParam(name)->pInt=pAddr;
168 void AddParam(char* name, char** pAddr)
170 CvDefParam* pP = NewParam(name);
171 char* p = pAddr?pAddr[0]:NULL;
172 pP->pStr = pAddr?pAddr:&(pP->Str);
176 pP->pStr[0] = pP->Str;
179 void AddParam(char* name)
181 CvDefParam* p = NewParam(name);
182 p->pDouble = &p->Double;
184 void CommentParam(char* name, char* pComment)
186 CvDefParam* p = GetParamPtr(name);
187 if(p)p->pComment = pComment ? strdup(pComment) : 0;
189 void SetTypeName(char* name){m_pModuleTypeName = strdup(name);}
190 void SetModuleName(char* name){m_pModuleName = strdup(name);}
191 void DelParam(char* name)
193 CvDefParam* p = m_pParamList;
194 CvDefParam* pPrev = NULL;
197 if(cv_stricmp(p->pName,name)==0) break;
204 pPrev->next = p->next;
208 m_pParamList = p->next;
214 public: /* EXTERNAL INTERFACE */
215 char* GetParamName(int index)
217 CvDefParam* p = GetParamPtr(index);
218 return p?p->pName:NULL;
220 char* GetParamComment(char* name)
222 CvDefParam* p = GetParamPtr(name);
223 if(p && p->pComment) return p->pComment;
226 double GetParam(char* name)
228 CvDefParam* p = GetParamPtr(name);
231 if(p->pDouble) return p->pDouble[0];
232 if(p->pFloat) return p->pFloat[0];
233 if(p->pInt) return p->pInt[0];
238 char* GetParamStr(char* name)
240 CvDefParam* p = GetParamPtr(name);
241 return p?p->Str:NULL;
243 void SetParam(char* name, double val)
245 CvDefParam* p = m_pParamList;
248 if(cv_stricmp(p->pName,name) != 0) continue;
249 if(p->pDouble)p->pDouble[0] = val;
250 if(p->pFloat)p->pFloat[0] = (float)val;
251 if(p->pInt)p->pInt[0] = cvRound(val);
254 void SetParamStr(char* name, char* str)
256 CvDefParam* p = m_pParamList;
259 if(cv_stricmp(p->pName,name) != 0) continue;
262 if(p->Str)free(p->Str);
264 if(str)p->Str = strdup(str);
268 /* convert to double and set */
269 if(str)SetParam(name,atof(str));
271 void TransferParamsFromChild(CvVSModule* pM, char* prefix = NULL)
278 char* N = pM->GetParamName(i);
290 if(pM->GetParamStr(N))
292 AddParam(FN,(char**)NULL);
299 if(pM->GetParamStr(N))
301 char* val = pM->GetParamStr(N);
306 double val = pM->GetParam(N);
309 CommentParam(FN, pM->GetParamComment(N));
310 }/* transfer next param */
311 }/* Transfer params */
313 void TransferParamsToChild(CvVSModule* pM, char* prefix = NULL)
319 char* N = pM->GetParamName(i);
335 pM->SetParamStr(N,GetParamStr(tmp));
337 pM->SetParam(N,GetParam(tmp));
339 }/* transfer next param */
341 }/* Transfer params */
343 virtual void ParamUpdate(){};
346 return m_pModuleTypeName;
348 int IsModuleTypeName(char* name)
350 return m_pModuleTypeName?(cv_stricmp(m_pModuleTypeName,name)==0):0;
352 char* GetModuleName()
354 return m_pModuleName;
356 int IsModuleName(char* name)
358 return m_pModuleName?(cv_stricmp(m_pModuleName,name)==0):0;
360 void SetNickName(char* pStr)
367 m_pNickName = strdup(pStr);
371 return m_pNickName ? m_pNickName : (char *)"unknown";
373 virtual void SaveState(CvFileStorage*){};
374 virtual void LoadState(CvFileStorage*, CvFileNode*){};
376 virtual void Release() = 0;
378 void inline cvWriteStruct(CvFileStorage* fs, char* name, void* addr, char* desc, int num=1)
380 cvStartWriteStruct(fs,name,CV_NODE_SEQ|CV_NODE_FLOW);
381 cvWriteRawData(fs,addr,num,desc);
382 cvEndWriteStruct(fs);
384 void inline cvReadStructByName(CvFileStorage* fs, CvFileNode* node, char* name, void* addr, char* desc)
386 CvFileNode* pSeqNode = cvGetFileNodeByName(fs, node, name);
389 printf("WARNING!!! Can't read structure %s\n",name);
393 if(CV_NODE_IS_SEQ(pSeqNode->tag))
395 cvReadRawData( fs, pSeqNode, addr, desc );
399 printf("WARNING!!! Structure %s is not sequence and can not be read\n",name);
405 /* FOREGROUND DETECTOR INTERFACE */
406 class CV_EXPORTS CvFGDetector: public CvVSModule
409 virtual IplImage* GetMask() = 0;
410 /* process current image */
411 virtual void Process(IplImage* pImg) = 0;
412 /* release foreground detector */
413 virtual void Release() = 0;
415 inline void cvReleaseFGDetector(CvFGDetector** ppT )
420 /* FOREGROUND DETECTOR INTERFACE */
422 CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param);
428 float x,y; /* blob position */
429 float w,h; /* blob sizes */
430 int ID; /* blbo ID */
433 inline CvBlob cvBlob(float x,float y, float w, float h)
435 CvBlob B = {x,y,w,h,0};
438 #define CV_BLOB_MINW 5
439 #define CV_BLOB_MINH 5
440 #define CV_BLOB_ID(pB) (((CvBlob*)(pB))->ID)
441 #define CV_BLOB_CENTER(pB) cvPoint2D32f(((CvBlob*)(pB))->x,((CvBlob*)(pB))->y)
442 #define CV_BLOB_X(pB) (((CvBlob*)(pB))->x)
443 #define CV_BLOB_Y(pB) (((CvBlob*)(pB))->y)
444 #define CV_BLOB_WX(pB) (((CvBlob*)(pB))->w)
445 #define CV_BLOB_WY(pB) (((CvBlob*)(pB))->h)
446 #define CV_BLOB_RX(pB) (0.5f*CV_BLOB_WX(pB))
447 #define CV_BLOB_RY(pB) (0.5f*CV_BLOB_WY(pB))
448 #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)))
449 /* END BLOB STRUCTURE*/
452 /* simple BLOBLIST */
453 class CV_EXPORTS CvBlobSeq
456 CvBlobSeq(int BlobSize = sizeof(CvBlob))
458 m_pMem = cvCreateMemStorage();
459 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),BlobSize,m_pMem);
460 strcpy(m_pElemFormat,"ffffi");
464 cvReleaseMemStorage(&m_pMem);
466 virtual CvBlob* GetBlob(int BlobIndex)
468 return (CvBlob*)cvGetSeqElem(m_pSeq,BlobIndex);
470 virtual CvBlob* GetBlobByID(int BlobID)
473 for(i=0;i<m_pSeq->total;++i)
474 if(BlobID == CV_BLOB_ID(GetBlob(i)))
478 virtual void DelBlob(int BlobIndex)
480 cvSeqRemove(m_pSeq,BlobIndex);
482 virtual void DelBlobByID(int BlobID)
485 for(i=0;i<m_pSeq->total;++i)
487 if(BlobID == CV_BLOB_ID(GetBlob(i)))
498 virtual void AddBlob(CvBlob* pB)
500 cvSeqPush(m_pSeq,pB);
502 virtual int GetBlobNum()
504 return m_pSeq->total;
506 virtual void Write(CvFileStorage* fs, char* name)
508 char* attr[] = {"dt",m_pElemFormat,NULL};
511 cvWrite(fs,name,m_pSeq,cvAttrList((const char**)attr,NULL));
514 virtual void Load(CvFileStorage* fs, CvFileNode* node)
517 CvSeq* pSeq = (CvSeq*)cvRead(fs, node);
522 for(i=0;i<pSeq->total;++i)
524 void* pB = cvGetSeqElem( pSeq, i );
525 cvSeqPush( m_pSeq, pB );
529 void AddFormat(char* str){strcat(m_pElemFormat,str);}
531 CvMemStorage* m_pMem;
533 char m_pElemFormat[1024];
535 /* simple BLOBLIST */
538 /* simple TRACKLIST */
546 class CV_EXPORTS CvBlobTrackSeq
549 CvBlobTrackSeq(int TrackSize = sizeof(CvBlobTrack))
551 m_pMem = cvCreateMemStorage();
552 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),TrackSize,m_pMem);
554 virtual ~CvBlobTrackSeq()
557 cvReleaseMemStorage(&m_pMem);
559 virtual CvBlobTrack* GetBlobTrack(int TrackIndex)
561 return (CvBlobTrack*)cvGetSeqElem(m_pSeq,TrackIndex);
563 virtual CvBlobTrack* GetBlobTrackByID(int TrackID)
566 for(i=0;i<m_pSeq->total;++i)
568 CvBlobTrack* pP = GetBlobTrack(i);
569 if(pP && pP->TrackID == TrackID)
574 virtual void DelBlobTrack(int TrackIndex)
576 CvBlobTrack* pP = GetBlobTrack(TrackIndex);
577 if(pP && pP->pBlobSeq) delete pP->pBlobSeq;
578 cvSeqRemove(m_pSeq,TrackIndex);
580 virtual void DelBlobTrackByID(int TrackID)
583 for(i=0;i<m_pSeq->total;++i)
585 CvBlobTrack* pP = GetBlobTrack(i);
586 if(TrackID == pP->TrackID)
596 for(i=GetBlobTrackNum();i>0;i--)
602 virtual void AddBlobTrack(int TrackID, int StartFrame = 0)
606 N.StartFrame = StartFrame;
607 N.pBlobSeq = new CvBlobSeq;
608 cvSeqPush(m_pSeq,&N);
610 virtual int GetBlobTrackNum()
612 return m_pSeq->total;
615 CvMemStorage* m_pMem;
619 /* simple TRACKLIST */
622 /* BLOB DETECTOR INTERFACE */
623 class CV_EXPORTS CvBlobDetector: public CvVSModule
626 /* try to detect new blob entrance based on foreground mask */
627 /* pFGMask - image of foreground mask */
628 /* pNewBlob - pointer to CvBlob structure which will bew filled if new blob entrance detected */
629 /* pOldBlobList - pointer to blob list which already exist on image */
630 virtual int DetectNewBlob(IplImage* pImg, IplImage* pImgFG, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList) = 0;
631 /* release blob detector */
632 virtual void Release()=0;
634 /* release any blob detector*/
635 inline void cvReleaseBlobDetector(CvBlobDetector** ppBD)
640 /* END BLOB DETECTOR INTERFACE */
642 /* declaration of constructors of implemented modules */
643 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorSimple();
644 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorCC();
647 struct CV_EXPORTS CvDetectedBlob : public CvBlob
652 CV_INLINE CvDetectedBlob cvDetectedBlob( float x, float y, float w, float h, int ID = 0, float response = 0.0F )
655 b.x = x; b.y = y; b.w = w; b.h = h; b.ID = ID; b.response = response;
660 class CV_EXPORTS CvObjectDetector
663 CvObjectDetector( const char* /*detector_file_name*/ = 0 ) {};
665 ~CvObjectDetector() {};
668 * Releases the current detector and loads new detector from file
669 * (if detector_file_name is not 0)
670 * Returns true on success
672 bool Load( const char* /*detector_file_name*/ = 0 ) { return false; }
674 /* Returns min detector window size */
675 CvSize GetMinWindowSize() const { return cvSize(0,0); }
677 /* Returns max border */
678 int GetMaxBorderSize() const { return 0; }
681 * Detects the objects on the image and pushes the detected
682 * blobs into <detected_blob_seq> which must be the sequence of <CvDetectedBlob>s
684 void Detect( const CvArr* /*img*/, /* out */ CvBlobSeq* /*detected_blob_seq*/ = 0 ) {};
687 class CvObjectDetectorImpl* impl;
691 CV_INLINE CvRect cvRectIntersection( const CvRect r1, const CvRect r2 )
693 CvRect r = cvRect( MAX(r1.x, r2.x), MAX(r1.y, r2.y), 0, 0 );
695 r.width = MIN(r1.x + r1.width, r2.x + r2.width) - r.x;
696 r.height = MIN(r1.y + r1.height, r2.y + r2.height) - r.y;
705 * Draws on an image the specified ROIs from the source image and
706 * given blobs as ellipses or rectangles
711 enum {RECT, ELLIPSE} shape;
715 /*extern const CvDrawShape icv_shape[] =
717 { CvDrawShape::ELLIPSE, CV_RGB(255,0,0) },
718 { CvDrawShape::ELLIPSE, CV_RGB(0,255,0) },
719 { CvDrawShape::ELLIPSE, CV_RGB(0,0,255) },
720 { CvDrawShape::ELLIPSE, CV_RGB(255,255,0) },
721 { CvDrawShape::ELLIPSE, CV_RGB(0,255,255) },
722 { CvDrawShape::ELLIPSE, CV_RGB(255,0,255) }
725 class CV_EXPORTS CvImageDrawer
728 CvImageDrawer() : m_image(0) {}
729 ~CvImageDrawer() { cvReleaseImage( &m_image ); }
730 void SetShapes( const CvDrawShape* shapes, int num );
731 /* <blob_seq> must be the sequence of <CvDetectedBlob>s */
732 IplImage* Draw( const CvArr* src, CvBlobSeq* blob_seq = 0, const CvSeq* roi_seq = 0 );
733 IplImage* GetImage() { return m_image; }
735 //static const int MAX_SHAPES = sizeof(icv_shape) / sizeof(icv_shape[0]);;
738 CvDrawShape m_shape[16];
743 /* Trajectory generation module */
744 class CV_EXPORTS CvBlobTrackGen: public CvVSModule
747 virtual void SetFileName(char* pFileName) = 0;
748 virtual void AddBlob(CvBlob* pBlob) = 0;
749 virtual void Process(IplImage* pImg = NULL, IplImage* pFG = NULL) = 0;
750 virtual void Release() = 0;
753 inline void cvReleaseBlobTrackGen(CvBlobTrackGen** pBTGen)
755 if(*pBTGen)(*pBTGen)->Release();
759 /* declaration of constructors of implemented modules */
760 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGen1();
761 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGenYML();
765 /* BLOB TRACKER INTERFACE */
766 class CV_EXPORTS CvBlobTracker: public CvVSModule
769 CvBlobTracker(){SetTypeName("BlobTracker");};
770 /* Add new blob to track it and assign to this blob personal ID */
771 /* pBlob - pinter to structure with blob parameters (ID is ignored)*/
772 /* pImg - current image */
773 /* pImgFG - current foreground mask */
774 /* return pointer to new added blob */
775 virtual CvBlob* AddBlob(CvBlob* pBlob, IplImage* pImg, IplImage* pImgFG = NULL ) = 0;
776 /* return number of currently tracked blobs */
777 virtual int GetBlobNum() = 0;
778 /* return pointer to specified by index blob */
779 virtual CvBlob* GetBlob(int BlobIndex) = 0;
781 /* delete blob by its index */
782 virtual void DelBlob(int BlobIndex) = 0;
783 /* process current image and track all existed blobs */
784 virtual void Process(IplImage* pImg, IplImage* pImgFG = NULL) = 0;
785 /* release blob tracker */
786 virtual void Release() = 0;
789 /* Process on blob (for multi hypothesis tracing) */
790 virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
796 pB = GetBlob(BlobIndex);
801 /* get confidence/wieght/probability (0-1) for blob */
802 virtual double GetConfidence(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
806 virtual double GetConfidenceList(CvBlobSeq* pBlobList, IplImage* pImg, IplImage* pImgFG = NULL)
808 int b,bN = pBlobList->GetBlobNum();
812 CvBlob* pB = pBlobList->GetBlob(b);
813 int BI = GetBlobIndexByID(pB->ID);
814 W *= GetConfidence(BI,pB,pImg,pImgFG);
818 virtual void UpdateBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
819 /* update all blob models */
820 virtual void Update(IplImage* pImg, IplImage* pImgFG = NULL)
823 for(i=GetBlobNum();i>0;i--)
825 CvBlob* pB=GetBlob(i-1);
826 UpdateBlob(i-1, pB, pImg, pImgFG);
831 /* return pinter to blob by its unique ID */
832 virtual int GetBlobIndexByID(int BlobID)
835 for(i=GetBlobNum();i>0;i--)
837 CvBlob* pB=GetBlob(i-1);
838 if(CV_BLOB_ID(pB) == BlobID) return i-1;
842 /* return pinter to blob by its unique ID */
843 virtual CvBlob* GetBlobByID(int BlobID){return GetBlob(GetBlobIndexByID(BlobID));};
844 /* delete blob by its ID */
845 virtual void DelBlobByID(int BlobID){DelBlob(GetBlobIndexByID(BlobID));};
846 /* Set new parameters for specified (by index) blob */
847 virtual void SetBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
848 /* Set new parameters for specified (by ID) blob */
849 virtual void SetBlobByID(int BlobID, CvBlob* pBlob)
851 SetBlob(GetBlobIndexByID(BlobID),pBlob);
854 /* =============== MULTI HYPOTHESIS INTERFACE ================== */
855 /* return number of position hyposetis of currently tracked blob */
856 virtual int GetBlobHypNum(int /*BlobIdx*/){return 1;};
857 /* return pointer to specified blob hypothesis by index blob */
858 virtual CvBlob* GetBlobHyp(int BlobIndex, int /*hypothesis*/){return GetBlob(BlobIndex);};
859 /* Set new parameters for specified (by index) blob hyp (can be called several times for each hyp )*/
860 virtual void SetBlobHyp(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
862 inline void cvReleaseBlobTracker(CvBlobTracker**ppT )
867 /* BLOB TRACKER INTERFACE */
869 /*BLOB TRACKER ONE INTERFACE */
870 class CV_EXPORTS CvBlobTrackerOne:public CvVSModule
873 virtual void Init(CvBlob* pBlobInit, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
874 virtual CvBlob* Process(CvBlob* pBlobPrev, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
875 virtual void Release() = 0;
876 /*not required methods */
877 virtual void SkipProcess(CvBlob* /*pBlobPrev*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
878 virtual void Update(CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
879 virtual void SetCollision(int /*CollisionFlag*/){}; /* call in case of blob collision situation*/
880 virtual double GetConfidence(CvBlob* /*pBlob*/, IplImage* /*pImg*/,
881 IplImage* /*pImgFG*/ = NULL, IplImage* /*pImgUnusedReg*/ = NULL)
886 inline void cvReleaseBlobTrackerOne(CvBlobTrackerOne **ppT )
891 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerList(CvBlobTrackerOne* (*create)());
892 /*BLOB TRACKER ONE INTERFACE */
894 /* declaration of constructors of implemented modules */
896 /* some declaration for specific MeanShift tracker */
897 #define PROFILE_EPANECHNIKOV 0
898 #define PROFILE_DOG 1
899 struct CvBlobTrackerParamMS
902 int appearance_profile;
903 int meanshift_profile;
907 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1(CvBlobTrackerParamMS* param);
908 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS2(CvBlobTrackerParamMS* param);
909 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1ByList();
911 /* some declaration for specific Liklyhood tracker */
912 struct CvBlobTrackerParamLH
914 int HistType; /* see Prob.h */
918 /* no scale optimization */
919 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHR(CvBlobTrackerParamLH* /*param*/ = NULL);
920 /* scale optimization */
921 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHRS(CvBlobTrackerParamLH* /*param*/ = NULL);
923 /* simple blob tracker based on connected component tracking */
924 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCC();
925 /* connected component tracking and MSPF resolver for collision */
926 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCCMSPF();
927 /* blob tracker that integrate MS and CC */
928 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFG();
929 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFGS();
931 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS();
932 /* particle filtering using bahata... coefficient */
933 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSPF();
935 /* =========== tracker integrators trackers =============*/
936 /* integrator based on Partical Filtering method */
937 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPF();
938 /* rule based integrator */
939 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIRB();
940 /* integrator based on data fusion used particle filtering */
941 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPFDF();
946 /* Trajectory postprocessing module */
947 class CV_EXPORTS CvBlobTrackPostProc: public CvVSModule
950 virtual void AddBlob(CvBlob* pBlob) = 0;
951 virtual void Process() = 0;
952 virtual int GetBlobNum() = 0;
953 virtual CvBlob* GetBlob(int index) = 0;
954 virtual void Release() = 0;
956 /* additional functionality */
957 virtual CvBlob* GetBlobByID(int BlobID)
960 for(i=GetBlobNum();i>0;i--)
962 CvBlob* pB=GetBlob(i-1);
963 if(pB->ID==BlobID) return pB;
969 inline void cvReleaseBlobTrackPostProc(CvBlobTrackPostProc** pBTPP)
971 if(pBTPP == NULL) return;
972 if(*pBTPP)(*pBTPP)->Release();
976 /* Trajectory generation module */
977 class CV_EXPORTS CvBlobTrackPostProcOne: public CvVSModule
980 virtual CvBlob* Process(CvBlob* pBlob) = 0;
981 virtual void Release() = 0;
983 /* create blob traking post processing module based on simle module */
984 CV_EXPORTS CvBlobTrackPostProc* cvCreateBlobTrackPostProcList(CvBlobTrackPostProcOne* (*create)());
987 /* declaration of constructors of implemented modules */
988 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcKalman();
989 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverRect();
990 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverExp();
995 class CvBlobTrackPredictor: public CvVSModule
998 virtual CvBlob* Predict() = 0;
999 virtual void Update(CvBlob* pBlob) = 0;
1000 virtual void Release() = 0;
1002 CV_EXPORTS CvBlobTrackPredictor* cvCreateModuleBlobTrackPredictKalman();
1006 /* Trajectory analyser module */
1007 class CV_EXPORTS CvBlobTrackAnalysis: public CvVSModule
1010 virtual void AddBlob(CvBlob* pBlob) = 0;
1011 virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
1012 virtual float GetState(int BlobID) = 0;
1013 /* return 0 if trajectory is normal
1014 return >0 if trajectory abnormal */
1015 virtual char* GetStateDesc(int /*BlobID*/){return NULL;};
1016 virtual void SetFileName(char* /*DataBaseName*/){};
1017 virtual void Release() = 0;
1021 inline void cvReleaseBlobTrackAnalysis(CvBlobTrackAnalysis** pBTPP)
1023 if(pBTPP == NULL) return;
1024 if(*pBTPP)(*pBTPP)->Release();
1028 /* feature vector generation module */
1029 class CV_EXPORTS CvBlobTrackFVGen : public CvVSModule
1032 virtual void AddBlob(CvBlob* pBlob) = 0;
1033 virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
1034 virtual void Release() = 0;
1035 virtual int GetFVSize() = 0;
1036 virtual int GetFVNum() = 0;
1037 virtual float* GetFV(int index, int* pFVID) = 0; /* pointer to FV, if return 0 then FV does not created */
1038 virtual float* GetFVVar(){return NULL;}; /* returned pointer to array of variation of values of FV, if return 0 then FVVar is not exist */
1039 virtual float* GetFVMin() = 0; /* returned pointer to array of minimal values of FV, if return 0 then FVrange is not exist */
1040 virtual float* GetFVMax() = 0; /* returned pointer to array of maximal values of FV, if return 0 then FVrange is not exist */
1044 /* Trajectory Analyser module */
1045 class CV_EXPORTS CvBlobTrackAnalysisOne
1048 virtual ~CvBlobTrackAnalysisOne() {};
1049 virtual int Process(CvBlob* pBlob, IplImage* pImg, IplImage* pFG) = 0;
1050 /* return 0 if trajectory is normal
1051 return >0 if trajectory abnormal */
1052 virtual void Release() = 0;
1055 /* create blob traking post processing module based on simle module */
1056 CV_EXPORTS CvBlobTrackAnalysis* cvCreateBlobTrackAnalysisList(CvBlobTrackAnalysisOne* (*create)());
1058 /* declaration of constructors of implemented modules */
1059 /* based on histogramm analysis of 2D FV (x,y)*/
1060 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistP();
1061 /* based on histogramm analysis of 4D FV (x,y,vx,vy)*/
1062 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPV();
1063 /* based on histogramm analysis of 5D FV (x,y,vx,vy,state)*/
1064 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPVS();
1065 /* based on histogramm analysis of 4D FV (startpos,stoppos)*/
1066 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistSS();
1068 /* based on SVM classifier analysis of 2D FV (x,y)*/
1069 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP();
1070 /* based on SVM classifier analysis of 4D FV (x,y,vx,vy)*/
1071 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPV();
1072 /* based on SVM classifier analysis of 5D FV (x,y,vx,vy,state)*/
1073 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS();
1074 /* based on SVM classifier analysis of 4D FV (startpos,stoppos)*/
1075 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS();
1077 /* track analysis based on distance between tracks */
1078 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisTrackDist();
1080 /* analizer based on reation Road and height map*/
1081 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysis3DRoadMap();
1083 /* analizer that make OR desicion using set of analizers */
1084 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR();
1086 /* estimator of human height */
1087 class CV_EXPORTS CvBlobTrackAnalysisHeight: public CvBlobTrackAnalysis
1090 virtual double GetHeight(CvBlob* pB) = 0;
1092 //CV_EXPORTS CvBlobTrackAnalysisHeight* cvCreateModuleBlobTrackAnalysisHeightScale();
1096 /* AUTO BLOB TRACKER INTERFACE - pipeline of 3 modules */
1097 class CV_EXPORTS CvBlobTrackerAuto: public CvVSModule
1100 virtual void Process(IplImage* pImg, IplImage* pMask = NULL) = 0;
1101 virtual CvBlob* GetBlob(int index) = 0;
1102 virtual CvBlob* GetBlobByID(int ID) = 0;
1103 virtual int GetBlobNum() = 0;
1104 virtual IplImage* GetFGMask(){return NULL;};
1105 virtual float GetState(int BlobID) = 0;
1106 virtual char* GetStateDesc(int BlobID) = 0;
1107 /* return 0 if trajectory is normal
1108 return >0 if trajectory abnormal */
1109 virtual void Release() = 0;
1111 inline void cvReleaseBlobTrackerAuto(CvBlobTrackerAuto** ppT)
1116 /* END AUTO BLOB TRACKER INTERFACE */
1119 /* creation function and data for specific BlobTRackerAuto modules */
1120 /* parameters of blobtracker auto ver1 */
1121 struct CvBlobTrackerAutoParam1
1123 int FGTrainFrames; /* number of frames are needed for FG detector to train */
1124 CvFGDetector* pFG; /* FGDetector module, if this filed is NULL the Process FG mask is used */
1125 CvBlobDetector* pBD; /* existed blob detector module
1126 if this filed is NULL default blobdetector module will be created */
1127 CvBlobTracker* pBT; /* existed blob tracking module
1128 if this filed is NULL default blobtracker module will be created */
1129 CvBlobTrackGen* pBTGen; /* existed blob trajectory generator,
1130 if this filed is NULL no any generator is used */
1131 CvBlobTrackPostProc* pBTPP; /* existed blob trajectory postprocessing module
1132 if this filed is NULL no any postprocessing is used */
1134 CvBlobTrackAnalysis* pBTA; /* existed blob trajectory analysis module */
1135 /* if this filed is NULL no any analysis is made */
1138 /* create blob tracker auto ver1 */
1139 CV_EXPORTS CvBlobTrackerAuto* cvCreateBlobTrackerAuto1(CvBlobTrackerAutoParam1* param = NULL);
1141 /* simple loader for many auto trackers by its type */
1142 inline CvBlobTrackerAuto* cvCreateBlobTrackerAuto(int type, void* param)
1144 if(type == 0) return cvCreateBlobTrackerAuto1((CvBlobTrackerAutoParam1*)param);
1150 struct CvTracksTimePos
1155 int comLen; //common length for two tracks
1159 /*CV_EXPORTS int cvCompareTracks( CvBlobTrackSeq *groundTruth,
1160 CvBlobTrackSeq *result,
1164 /* Create functions */
1166 CV_EXPORTS void cvCreateTracks_One(CvBlobTrackSeq *TS);
1167 CV_EXPORTS void cvCreateTracks_Same(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2);
1168 CV_EXPORTS void cvCreateTracks_AreaErr(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2, int addW, int addH);
1172 class CV_EXPORTS CvProb
1175 virtual ~CvProb() {};
1176 /* calculate probability value */
1177 virtual double Value(int* /*comp*/, int /*x*/ = 0, int /*y*/ = 0){return -1;};
1178 /* update histograpp Pnew = (1-W)*Pold + W*Padd*/
1179 /* W weight of new added prob */
1180 /* comps - matrix of new fetature vectors used to update prob */
1181 virtual void AddFeature(float W, int* comps, int x =0, int y = 0) = 0;
1182 virtual void Scale(float factor = 0, int x = -1, int y = -1) = 0;
1183 virtual void Release() = 0;
1185 inline void cvReleaseProb(CvProb** ppProb){ppProb[0]->Release();ppProb[0]=NULL;}
1189 CV_EXPORTS CvProb* cvCreateProbS(int dim, CvSize size, int sample_num);
1190 CV_EXPORTS CvProb* cvCreateProbMG(int dim, CvSize size, int sample_num);
1191 CV_EXPORTS CvProb* cvCreateProbMG2(int dim, CvSize size, int sample_num);
1192 CV_EXPORTS CvProb* cvCreateProbHist(int dim, CvSize size);
1194 #define CV_BT_HIST_TYPE_S 0
1195 #define CV_BT_HIST_TYPE_MG 1
1196 #define CV_BT_HIST_TYPE_MG2 2
1197 #define CV_BT_HIST_TYPE_H 3
1198 inline CvProb* cvCreateProb(int type, int dim, CvSize size = cvSize(1,1), void* /*param*/ = NULL)
1200 if(type == CV_BT_HIST_TYPE_S) return cvCreateProbS(dim, size, -1);
1201 if(type == CV_BT_HIST_TYPE_MG) return cvCreateProbMG(dim, size, -1);
1202 if(type == CV_BT_HIST_TYPE_MG2) return cvCreateProbMG2(dim, size, -1);
1203 if(type == CV_BT_HIST_TYPE_H) return cvCreateProbHist(dim, size);
1209 /* noise types defenition */
1210 #define CV_NOISE_NONE 0
1211 #define CV_NOISE_GAUSSIAN 1
1212 #define CV_NOISE_UNIFORM 2
1213 #define CV_NOISE_SPECKLE 3
1214 #define CV_NOISE_SALT_AND_PEPPER 4
1215 /* Add some noise to image */
1216 /* pImg - (input) image without noise */
1217 /* pImg - (output) image with noise */
1218 /* noise_type - type of added noise */
1219 /* CV_NOISE_GAUSSIAN - pImg += n , n - is gaussian noise with Ampl standart deviation */
1220 /* CV_NOISE_UNIFORM - pImg += n , n - is uniform noise with Ampl standart deviation */
1221 /* CV_NOISE_SPECKLE - pImg += n*pImg , n - is gaussian noise with Ampl standart deviation */
1222 /* CV_NOISE_SALT_AND_PAPPER - pImg = pImg with blacked and whited pixels,
1223 Ampl is density of brocken pixels (0-there are not broken pixels, 1 - all pixels are broken)*/
1224 /* Ampl - "amplitude" of noise */
1225 CV_EXPORTS void cvAddNoise(IplImage* pImg, int noise_type, double Ampl, CvRandState* rnd_state = NULL);
1227 /*================== GENERATOR OF TEST VIDEO SEQUENCE ===================== */
1228 typedef void CvTestSeq;
1230 /* pConfigfile - name of file (yml or xml) with description of test sequence */
1231 /* videos - array of names of test videos described in "pConfigfile" file */
1232 /* numvideos - size of "videos" array */
1233 CV_EXPORTS CvTestSeq* cvCreateTestSeq(char* pConfigfile, char** videos, int numvideo, float Scale = 1, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
1234 CV_EXPORTS void cvReleaseTestSeq(CvTestSeq** ppTestSeq);
1236 /* generete next frame from test video seq and return pointer to it */
1237 CV_EXPORTS IplImage* cvTestSeqQueryFrame(CvTestSeq* pTestSeq);
1238 /* return pointer to current foreground mask */
1239 CV_EXPORTS IplImage* cvTestSeqGetFGMask(CvTestSeq* pTestSeq);
1240 /* return pointer to current image */
1241 CV_EXPORTS IplImage* cvTestSeqGetImage(CvTestSeq* pTestSeq);
1242 /* return frame size of result test video */
1243 CV_EXPORTS CvSize cvTestSeqGetImageSize(CvTestSeq* pTestSeq);
1244 /* return number of frames result test video */
1245 CV_EXPORTS int cvTestSeqFrameNum(CvTestSeq* pTestSeq);
1247 /* return number of existed objects
1248 this is general number of any objects.
1249 for example number of trajectories may be equal or less than returned value*/
1250 CV_EXPORTS int cvTestSeqGetObjectNum(CvTestSeq* pTestSeq);
1252 /* return 0 if there is not position for current defined on current frame */
1253 /* return 1 if there is object position and pPos was filled */
1254 CV_EXPORTS int cvTestSeqGetObjectPos(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pPos);
1255 CV_EXPORTS int cvTestSeqGetObjectSize(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pSize);
1257 /* add noise to finile image */
1258 CV_EXPORTS void cvTestSeqAddNoise(CvTestSeq* pTestSeq, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
1259 /* add Intensity variation */
1260 CV_EXPORTS void cvTestSeqAddIntensityVariation(CvTestSeq* pTestSeq, float DI_per_frame, float MinI, float MaxI);
1261 CV_EXPORTS void cvTestSeqSetFrame(CvTestSeq* pTestSeq, int n);