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 parameter */
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)
368 m_pNickName = strdup(pStr);
372 return m_pNickName ? m_pNickName : (char *)"unknown";
374 virtual void SaveState(CvFileStorage*){};
375 virtual void LoadState(CvFileStorage*, CvFileNode*){};
377 virtual void Release() = 0;
379 void inline cvWriteStruct(CvFileStorage* fs, char* name, void* addr, char* desc, int num=1)
381 cvStartWriteStruct(fs,name,CV_NODE_SEQ|CV_NODE_FLOW);
382 cvWriteRawData(fs,addr,num,desc);
383 cvEndWriteStruct(fs);
385 void inline cvReadStructByName(CvFileStorage* fs, CvFileNode* node, char* name, void* addr, char* desc)
387 CvFileNode* pSeqNode = cvGetFileNodeByName(fs, node, name);
390 printf("WARNING!!! Can't read structure %s\n",name);
394 if(CV_NODE_IS_SEQ(pSeqNode->tag))
396 cvReadRawData( fs, pSeqNode, addr, desc );
400 printf("WARNING!!! Structure %s is not sequence and can not be read\n",name);
406 /* FOREGROUND DETECTOR INTERFACE */
407 class CV_EXPORTS CvFGDetector: public CvVSModule
410 virtual IplImage* GetMask() = 0;
411 /* Process current image: */
412 virtual void Process(IplImage* pImg) = 0;
413 /* Release foreground detector: */
414 virtual void Release() = 0;
416 inline void cvReleaseFGDetector(CvFGDetector** ppT )
421 /* FOREGROUND DETECTOR INTERFACE */
423 CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param);
429 float x,y; /* blob position */
430 float w,h; /* blob sizes */
431 int ID; /* blob ID */
434 inline CvBlob cvBlob(float x,float y, float w, float h)
436 CvBlob B = {x,y,w,h,0};
439 #define CV_BLOB_MINW 5
440 #define CV_BLOB_MINH 5
441 #define CV_BLOB_ID(pB) (((CvBlob*)(pB))->ID)
442 #define CV_BLOB_CENTER(pB) cvPoint2D32f(((CvBlob*)(pB))->x,((CvBlob*)(pB))->y)
443 #define CV_BLOB_X(pB) (((CvBlob*)(pB))->x)
444 #define CV_BLOB_Y(pB) (((CvBlob*)(pB))->y)
445 #define CV_BLOB_WX(pB) (((CvBlob*)(pB))->w)
446 #define CV_BLOB_WY(pB) (((CvBlob*)(pB))->h)
447 #define CV_BLOB_RX(pB) (0.5f*CV_BLOB_WX(pB))
448 #define CV_BLOB_RY(pB) (0.5f*CV_BLOB_WY(pB))
449 #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)))
450 /* END BLOB STRUCTURE*/
453 /* simple BLOBLIST */
454 class CV_EXPORTS CvBlobSeq
457 CvBlobSeq(int BlobSize = sizeof(CvBlob))
459 m_pMem = cvCreateMemStorage();
460 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),BlobSize,m_pMem);
461 strcpy(m_pElemFormat,"ffffi");
465 cvReleaseMemStorage(&m_pMem);
467 virtual CvBlob* GetBlob(int BlobIndex)
469 return (CvBlob*)cvGetSeqElem(m_pSeq,BlobIndex);
471 virtual CvBlob* GetBlobByID(int BlobID)
474 for(i=0; i<m_pSeq->total; ++i)
475 if(BlobID == CV_BLOB_ID(GetBlob(i)))
479 virtual void DelBlob(int BlobIndex)
481 cvSeqRemove(m_pSeq,BlobIndex);
483 virtual void DelBlobByID(int BlobID)
486 for(i=0; i<m_pSeq->total; ++i)
488 if(BlobID == CV_BLOB_ID(GetBlob(i)))
499 virtual void AddBlob(CvBlob* pB)
501 cvSeqPush(m_pSeq,pB);
503 virtual int GetBlobNum()
505 return m_pSeq->total;
507 virtual void Write(CvFileStorage* fs, char* name)
509 char* attr[] = {"dt",m_pElemFormat,NULL};
512 cvWrite(fs,name,m_pSeq,cvAttrList((const char**)attr,NULL));
515 virtual void Load(CvFileStorage* fs, CvFileNode* node)
518 CvSeq* pSeq = (CvSeq*)cvRead(fs, node);
523 for(i=0;i<pSeq->total;++i)
525 void* pB = cvGetSeqElem( pSeq, i );
526 cvSeqPush( m_pSeq, pB );
530 void AddFormat(char* str){strcat(m_pElemFormat,str);}
532 CvMemStorage* m_pMem;
534 char m_pElemFormat[1024];
536 /* simple BLOBLIST */
539 /* simple TRACKLIST */
547 class CV_EXPORTS CvBlobTrackSeq
550 CvBlobTrackSeq(int TrackSize = sizeof(CvBlobTrack))
552 m_pMem = cvCreateMemStorage();
553 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),TrackSize,m_pMem);
555 virtual ~CvBlobTrackSeq()
558 cvReleaseMemStorage(&m_pMem);
560 virtual CvBlobTrack* GetBlobTrack(int TrackIndex)
562 return (CvBlobTrack*)cvGetSeqElem(m_pSeq,TrackIndex);
564 virtual CvBlobTrack* GetBlobTrackByID(int TrackID)
567 for(i=0; i<m_pSeq->total; ++i)
569 CvBlobTrack* pP = GetBlobTrack(i);
570 if(pP && pP->TrackID == TrackID)
575 virtual void DelBlobTrack(int TrackIndex)
577 CvBlobTrack* pP = GetBlobTrack(TrackIndex);
578 if(pP && pP->pBlobSeq) delete pP->pBlobSeq;
579 cvSeqRemove(m_pSeq,TrackIndex);
581 virtual void DelBlobTrackByID(int TrackID)
584 for(i=0; i<m_pSeq->total; ++i)
586 CvBlobTrack* pP = GetBlobTrack(i);
587 if(TrackID == pP->TrackID)
597 for(i=GetBlobTrackNum();i>0;i--)
603 virtual void AddBlobTrack(int TrackID, int StartFrame = 0)
607 N.StartFrame = StartFrame;
608 N.pBlobSeq = new CvBlobSeq;
609 cvSeqPush(m_pSeq,&N);
611 virtual int GetBlobTrackNum()
613 return m_pSeq->total;
616 CvMemStorage* m_pMem;
620 /* simple TRACKLIST */
623 /* BLOB DETECTOR INTERFACE */
624 class CV_EXPORTS CvBlobDetector: public CvVSModule
627 /* Try to detect new blob entrance based on foreground mask. */
628 /* pFGMask - image of foreground mask */
629 /* pNewBlob - pointer to CvBlob structure which will be filled if new blob entrance detected */
630 /* pOldBlobList - pointer to blob list which already exist on image */
631 virtual int DetectNewBlob(IplImage* pImg, IplImage* pImgFG, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList) = 0;
632 /* release blob detector */
633 virtual void Release()=0;
635 /* Release any blob detector: */
636 inline void cvReleaseBlobDetector(CvBlobDetector** ppBD)
641 /* END BLOB DETECTOR INTERFACE */
643 /* Declarations of constructors of implemented modules: */
644 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorSimple();
645 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorCC();
648 struct CV_EXPORTS CvDetectedBlob : public CvBlob
653 CV_INLINE CvDetectedBlob cvDetectedBlob( float x, float y, float w, float h, int ID = 0, float response = 0.0F )
656 b.x = x; b.y = y; b.w = w; b.h = h; b.ID = ID; b.response = response;
661 class CV_EXPORTS CvObjectDetector
664 CvObjectDetector( const char* /*detector_file_name*/ = 0 ) {};
666 ~CvObjectDetector() {};
669 * Release the current detector and load new detector from file
670 * (if detector_file_name is not 0)
671 * Return true on success:
673 bool Load( const char* /*detector_file_name*/ = 0 ) { return false; }
675 /* Return min detector window size: */
676 CvSize GetMinWindowSize() const { return cvSize(0,0); }
678 /* Return max border: */
679 int GetMaxBorderSize() const { return 0; }
682 * Detect the object on the image and push the detected
683 * blobs into <detected_blob_seq> which must be the sequence of <CvDetectedBlob>s
685 void Detect( const CvArr* /*img*/, /* out */ CvBlobSeq* /*detected_blob_seq*/ = 0 ) {};
688 class CvObjectDetectorImpl* impl;
692 CV_INLINE CvRect cvRectIntersection( const CvRect r1, const CvRect r2 )
694 CvRect r = cvRect( MAX(r1.x, r2.x), MAX(r1.y, r2.y), 0, 0 );
696 r.width = MIN(r1.x + r1.width, r2.x + r2.width) - r.x;
697 r.height = MIN(r1.y + r1.height, r2.y + r2.height) - r.y;
706 * Draw on an image the specified ROIs from the source image and
707 * given blobs as ellipses or rectangles:
712 enum {RECT, ELLIPSE} shape;
716 /*extern const CvDrawShape icv_shape[] =
718 { CvDrawShape::ELLIPSE, CV_RGB(255,0,0) },
719 { CvDrawShape::ELLIPSE, CV_RGB(0,255,0) },
720 { CvDrawShape::ELLIPSE, CV_RGB(0,0,255) },
721 { CvDrawShape::ELLIPSE, CV_RGB(255,255,0) },
722 { CvDrawShape::ELLIPSE, CV_RGB(0,255,255) },
723 { CvDrawShape::ELLIPSE, CV_RGB(255,0,255) }
726 class CV_EXPORTS CvImageDrawer
729 CvImageDrawer() : m_image(0) {}
730 ~CvImageDrawer() { cvReleaseImage( &m_image ); }
731 void SetShapes( const CvDrawShape* shapes, int num );
732 /* <blob_seq> must be the sequence of <CvDetectedBlob>s */
733 IplImage* Draw( const CvArr* src, CvBlobSeq* blob_seq = 0, const CvSeq* roi_seq = 0 );
734 IplImage* GetImage() { return m_image; }
736 //static const int MAX_SHAPES = sizeof(icv_shape) / sizeof(icv_shape[0]);;
739 CvDrawShape m_shape[16];
744 /* Trajectory generation module: */
745 class CV_EXPORTS CvBlobTrackGen: public CvVSModule
748 virtual void SetFileName(char* pFileName) = 0;
749 virtual void AddBlob(CvBlob* pBlob) = 0;
750 virtual void Process(IplImage* pImg = NULL, IplImage* pFG = NULL) = 0;
751 virtual void Release() = 0;
754 inline void cvReleaseBlobTrackGen(CvBlobTrackGen** pBTGen)
756 if(*pBTGen)(*pBTGen)->Release();
760 /* Declarations of constructors of implemented modules: */
761 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGen1();
762 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGenYML();
766 /* BLOB TRACKER INTERFACE */
767 class CV_EXPORTS CvBlobTracker: public CvVSModule
770 CvBlobTracker(){SetTypeName("BlobTracker");};
772 /* Add new blob to track it and assign to this blob personal ID */
773 /* pBlob - pointer to structure with blob parameters (ID is ignored)*/
774 /* pImg - current image */
775 /* pImgFG - current foreground mask */
776 /* Return pointer to new added blob: */
777 virtual CvBlob* AddBlob(CvBlob* pBlob, IplImage* pImg, IplImage* pImgFG = NULL ) = 0;
779 /* Return number of currently tracked blobs: */
780 virtual int GetBlobNum() = 0;
782 /* Return pointer to specified by index blob: */
783 virtual CvBlob* GetBlob(int BlobIndex) = 0;
785 /* Delete blob by its index: */
786 virtual void DelBlob(int BlobIndex) = 0;
788 /* Process current image and track all existed blobs: */
789 virtual void Process(IplImage* pImg, IplImage* pImgFG = NULL) = 0;
791 /* Release blob tracker: */
792 virtual void Release() = 0;
795 /* Process one blob (for multi hypothesis tracing): */
796 virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
802 pB = GetBlob(BlobIndex);
808 /* Get confidence/wieght/probability (0-1) for blob: */
809 virtual double GetConfidence(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
814 virtual double GetConfidenceList(CvBlobSeq* pBlobList, IplImage* pImg, IplImage* pImgFG = NULL)
816 int b,bN = pBlobList->GetBlobNum();
820 CvBlob* pB = pBlobList->GetBlob(b);
821 int BI = GetBlobIndexByID(pB->ID);
822 W *= GetConfidence(BI,pB,pImg,pImgFG);
827 virtual void UpdateBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
829 /* Update all blob models: */
830 virtual void Update(IplImage* pImg, IplImage* pImgFG = NULL)
833 for(i=GetBlobNum();i>0;i--)
835 CvBlob* pB=GetBlob(i-1);
836 UpdateBlob(i-1, pB, pImg, pImgFG);
841 /* Return pointer to blob by its unique ID: */
842 virtual int GetBlobIndexByID(int BlobID)
845 for(i=GetBlobNum();i>0;i--)
847 CvBlob* pB=GetBlob(i-1);
848 if(CV_BLOB_ID(pB) == BlobID) return i-1;
853 /* Return pointer to blob by its unique ID: */
854 virtual CvBlob* GetBlobByID(int BlobID){return GetBlob(GetBlobIndexByID(BlobID));};
856 /* Delete blob by its ID: */
857 virtual void DelBlobByID(int BlobID){DelBlob(GetBlobIndexByID(BlobID));};
859 /* Set new parameters for specified (by index) blob: */
860 virtual void SetBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
862 /* Set new parameters for specified (by ID) blob: */
863 virtual void SetBlobByID(int BlobID, CvBlob* pBlob)
865 SetBlob(GetBlobIndexByID(BlobID),pBlob);
868 /* =============== MULTI HYPOTHESIS INTERFACE ================== */
870 /* Return number of position hyposetis of currently tracked blob: */
871 virtual int GetBlobHypNum(int /*BlobIdx*/){return 1;};
873 /* Return pointer to specified blob hypothesis by index blob: */
874 virtual CvBlob* GetBlobHyp(int BlobIndex, int /*hypothesis*/){return GetBlob(BlobIndex);};
876 /* Set new parameters for specified (by index) blob hyp
877 * (can be called several times for each hyp ):
879 virtual void SetBlobHyp(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
881 inline void cvReleaseBlobTracker(CvBlobTracker**ppT )
886 /* BLOB TRACKER INTERFACE */
888 /*BLOB TRACKER ONE INTERFACE */
889 class CV_EXPORTS CvBlobTrackerOne:public CvVSModule
892 virtual void Init(CvBlob* pBlobInit, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
893 virtual CvBlob* Process(CvBlob* pBlobPrev, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
894 virtual void Release() = 0;
896 /* Non-required methods: */
897 virtual void SkipProcess(CvBlob* /*pBlobPrev*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
898 virtual void Update(CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
899 virtual void SetCollision(int /*CollisionFlag*/){}; /* call in case of blob collision situation*/
900 virtual double GetConfidence(CvBlob* /*pBlob*/, IplImage* /*pImg*/,
901 IplImage* /*pImgFG*/ = NULL, IplImage* /*pImgUnusedReg*/ = NULL)
906 inline void cvReleaseBlobTrackerOne(CvBlobTrackerOne **ppT )
911 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerList(CvBlobTrackerOne* (*create)());
912 /*BLOB TRACKER ONE INTERFACE */
914 /* Declarations of constructors of implemented modules: */
916 /* Some declarations for specific MeanShift tracker: */
917 #define PROFILE_EPANECHNIKOV 0
918 #define PROFILE_DOG 1
919 struct CvBlobTrackerParamMS
922 int appearance_profile;
923 int meanshift_profile;
927 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1(CvBlobTrackerParamMS* param);
928 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS2(CvBlobTrackerParamMS* param);
929 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1ByList();
931 /* Some declarations for specific Likelihood tracker: */
932 struct CvBlobTrackerParamLH
934 int HistType; /* see Prob.h */
938 /* Without scale optimization: */
939 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHR(CvBlobTrackerParamLH* /*param*/ = NULL);
941 /* With scale optimization: */
942 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHRS(CvBlobTrackerParamLH* /*param*/ = NULL);
944 /* Simple blob tracker based on connected component tracking: */
945 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCC();
947 /* Connected component tracking and mean-shift particle filter collion-resolver: */
948 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCCMSPF();
950 /* Blob tracker that integrates meanshift and connected components: */
951 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFG();
952 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFGS();
954 /* Meanshift without connected-components */
955 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS();
957 /* Particle filtering via Bhattacharya coefficient, which */
958 /* is roughly the dot-product of two probability densities. */
959 /* See: Real-Time Tracking of Non-Rigid Objects using Mean Shift */
960 /* Comanicius, Ramesh, Meer, 2000, 8p */
961 /* http://citeseer.ist.psu.edu/321441.html */
962 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSPF();
964 /* =========== tracker integrators trackers =============*/
966 /* Integrator based on Particle Filtering method: */
967 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPF();
969 /* Rule based integrator: */
970 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIRB();
972 /* Integrator based on data fusion using particle filtering: */
973 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPFDF();
978 /* Trajectory postprocessing module: */
979 class CV_EXPORTS CvBlobTrackPostProc: public CvVSModule
982 virtual void AddBlob(CvBlob* pBlob) = 0;
983 virtual void Process() = 0;
984 virtual int GetBlobNum() = 0;
985 virtual CvBlob* GetBlob(int index) = 0;
986 virtual void Release() = 0;
988 /* Additional functionality: */
989 virtual CvBlob* GetBlobByID(int BlobID)
992 for(i=GetBlobNum();i>0;i--)
994 CvBlob* pB=GetBlob(i-1);
995 if(pB->ID==BlobID) return pB;
1001 inline void cvReleaseBlobTrackPostProc(CvBlobTrackPostProc** pBTPP)
1003 if(pBTPP == NULL) return;
1004 if(*pBTPP)(*pBTPP)->Release();
1008 /* Trajectory generation module: */
1009 class CV_EXPORTS CvBlobTrackPostProcOne: public CvVSModule
1012 virtual CvBlob* Process(CvBlob* pBlob) = 0;
1013 virtual void Release() = 0;
1016 /* Create blob tracking post processing module based on simle module: */
1017 CV_EXPORTS CvBlobTrackPostProc* cvCreateBlobTrackPostProcList(CvBlobTrackPostProcOne* (*create)());
1020 /* Declarations of constructors of implemented modules: */
1021 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcKalman();
1022 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverRect();
1023 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverExp();
1027 /* blob PREDICTOR */
1028 class CvBlobTrackPredictor: public CvVSModule
1031 virtual CvBlob* Predict() = 0;
1032 virtual void Update(CvBlob* pBlob) = 0;
1033 virtual void Release() = 0;
1035 CV_EXPORTS CvBlobTrackPredictor* cvCreateModuleBlobTrackPredictKalman();
1039 /* Trajectory analyser module: */
1040 class CV_EXPORTS CvBlobTrackAnalysis: public CvVSModule
1043 virtual void AddBlob(CvBlob* pBlob) = 0;
1044 virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
1045 virtual float GetState(int BlobID) = 0;
1046 /* return 0 if trajectory is normal
1047 return >0 if trajectory abnormal */
1048 virtual char* GetStateDesc(int /*BlobID*/){return NULL;};
1049 virtual void SetFileName(char* /*DataBaseName*/){};
1050 virtual void Release() = 0;
1054 inline void cvReleaseBlobTrackAnalysis(CvBlobTrackAnalysis** pBTPP)
1056 if(pBTPP == NULL) return;
1057 if(*pBTPP)(*pBTPP)->Release();
1061 /* Feature-vector generation module: */
1062 class CV_EXPORTS CvBlobTrackFVGen : public CvVSModule
1065 virtual void AddBlob(CvBlob* pBlob) = 0;
1066 virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
1067 virtual void Release() = 0;
1068 virtual int GetFVSize() = 0;
1069 virtual int GetFVNum() = 0;
1070 virtual float* GetFV(int index, int* pFVID) = 0; /* Returns pointer to FV, if return 0 then FV not created */
1071 virtual float* GetFVVar(){return NULL;}; /* Returns pointer to array of variation of values of FV, if returns 0 then FVVar does not exist. */
1072 virtual float* GetFVMin() = 0; /* Returns pointer to array of minimal values of FV, if returns 0 then FVrange does not exist */
1073 virtual float* GetFVMax() = 0; /* Returns pointer to array of maximal values of FV, if returns 0 then FVrange does not exist */
1077 /* Trajectory Analyser module: */
1078 class CV_EXPORTS CvBlobTrackAnalysisOne
1081 virtual ~CvBlobTrackAnalysisOne() {};
1082 virtual int Process(CvBlob* pBlob, IplImage* pImg, IplImage* pFG) = 0;
1083 /* return 0 if trajectory is normal
1084 return >0 if trajectory abnormal */
1085 virtual void Release() = 0;
1088 /* Create blob tracking post processing module based on simle module: */
1089 CV_EXPORTS CvBlobTrackAnalysis* cvCreateBlobTrackAnalysisList(CvBlobTrackAnalysisOne* (*create)());
1091 /* Declarations of constructors of implemented modules: */
1093 /* Based on histogram analysis of 2D FV (x,y): */
1094 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistP();
1096 /* Based on histogram analysis of 4D FV (x,y,vx,vy): */
1097 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPV();
1099 /* Based on histogram analysis of 5D FV (x,y,vx,vy,state): */
1100 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPVS();
1102 /* Based on histogram analysis of 4D FV (startpos,stoppos): */
1103 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistSS();
1107 /* Based on SVM classifier analysis of 2D FV (x,y): */
1108 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP();
1110 /* Based on SVM classifier analysis of 4D FV (x,y,vx,vy): */
1111 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPV();
1113 /* Based on SVM classifier analysis of 5D FV (x,y,vx,vy,state): */
1114 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS();
1116 /* Based on SVM classifier analysis of 4D FV (startpos,stoppos): */
1117 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS();
1119 /* Track analysis based on distance between tracks: */
1120 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisTrackDist();
1122 /* Analyzer based on reation Road and height map: */
1123 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysis3DRoadMap();
1125 /* Analyzer that makes OR decision using set of analyzers: */
1126 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR();
1128 /* Estimator of human height: */
1129 class CV_EXPORTS CvBlobTrackAnalysisHeight: public CvBlobTrackAnalysis
1132 virtual double GetHeight(CvBlob* pB) = 0;
1134 //CV_EXPORTS CvBlobTrackAnalysisHeight* cvCreateModuleBlobTrackAnalysisHeightScale();
1138 /* AUTO BLOB TRACKER INTERFACE -- pipeline of 3 modules: */
1139 class CV_EXPORTS CvBlobTrackerAuto: public CvVSModule
1142 virtual void Process(IplImage* pImg, IplImage* pMask = NULL) = 0;
1143 virtual CvBlob* GetBlob(int index) = 0;
1144 virtual CvBlob* GetBlobByID(int ID) = 0;
1145 virtual int GetBlobNum() = 0;
1146 virtual IplImage* GetFGMask(){return NULL;};
1147 virtual float GetState(int BlobID) = 0;
1148 virtual char* GetStateDesc(int BlobID) = 0;
1149 /* return 0 if trajectory is normal;
1150 * return >0 if trajectory abnormal. */
1151 virtual void Release() = 0;
1153 inline void cvReleaseBlobTrackerAuto(CvBlobTrackerAuto** ppT)
1158 /* END AUTO BLOB TRACKER INTERFACE */
1161 /* Constructor functions and data for specific BlobTRackerAuto modules: */
1163 /* Parameters of blobtracker auto ver1: */
1164 struct CvBlobTrackerAutoParam1
1166 int FGTrainFrames; /* Number of frames needed for FG (foreground) detector to train. */
1168 CvFGDetector* pFG; /* FGDetector module. If this field is NULL the Process FG mask is used. */
1170 CvBlobDetector* pBD; /* Selected blob detector module. */
1171 /* If this field is NULL default blobdetector module will be created. */
1173 CvBlobTracker* pBT; /* Selected blob tracking module. */
1174 /* If this field is NULL default blobtracker module will be created. */
1176 CvBlobTrackGen* pBTGen; /* Selected blob trajectory generator. */
1177 /* If this field is NULL no generator is used. */
1179 CvBlobTrackPostProc* pBTPP; /* Selected blob trajectory postprocessing module. */
1180 /* If this field is NULL no postprocessing is done. */
1184 CvBlobTrackAnalysis* pBTA; /* Selected blob trajectory analysis module. */
1185 /* If this field is NULL no track analysis is done. */
1188 /* Create blob tracker auto ver1: */
1189 CV_EXPORTS CvBlobTrackerAuto* cvCreateBlobTrackerAuto1(CvBlobTrackerAutoParam1* param = NULL);
1191 /* Simple loader for many auto trackers by its type : */
1192 inline CvBlobTrackerAuto* cvCreateBlobTrackerAuto(int type, void* param)
1194 if(type == 0) return cvCreateBlobTrackerAuto1((CvBlobTrackerAutoParam1*)param);
1200 struct CvTracksTimePos
1205 int comLen; //common length for two tracks
1209 /*CV_EXPORTS int cvCompareTracks( CvBlobTrackSeq *groundTruth,
1210 CvBlobTrackSeq *result,
1214 /* Constructor functions: */
1216 CV_EXPORTS void cvCreateTracks_One(CvBlobTrackSeq *TS);
1217 CV_EXPORTS void cvCreateTracks_Same(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2);
1218 CV_EXPORTS void cvCreateTracks_AreaErr(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2, int addW, int addH);
1222 class CV_EXPORTS CvProb
1225 virtual ~CvProb() {};
1227 /* Calculate probability value: */
1228 virtual double Value(int* /*comp*/, int /*x*/ = 0, int /*y*/ = 0){return -1;};
1230 /* Update histograpp Pnew = (1-W)*Pold + W*Padd*/
1231 /* W weight of new added prob */
1232 /* comps - matrix of new fetature vectors used to update prob */
1233 virtual void AddFeature(float W, int* comps, int x =0, int y = 0) = 0;
1234 virtual void Scale(float factor = 0, int x = -1, int y = -1) = 0;
1235 virtual void Release() = 0;
1237 inline void cvReleaseProb(CvProb** ppProb){ppProb[0]->Release();ppProb[0]=NULL;}
1241 CV_EXPORTS CvProb* cvCreateProbS(int dim, CvSize size, int sample_num);
1242 CV_EXPORTS CvProb* cvCreateProbMG(int dim, CvSize size, int sample_num);
1243 CV_EXPORTS CvProb* cvCreateProbMG2(int dim, CvSize size, int sample_num);
1244 CV_EXPORTS CvProb* cvCreateProbHist(int dim, CvSize size);
1246 #define CV_BT_HIST_TYPE_S 0
1247 #define CV_BT_HIST_TYPE_MG 1
1248 #define CV_BT_HIST_TYPE_MG2 2
1249 #define CV_BT_HIST_TYPE_H 3
1250 inline CvProb* cvCreateProb(int type, int dim, CvSize size = cvSize(1,1), void* /*param*/ = NULL)
1252 if(type == CV_BT_HIST_TYPE_S) return cvCreateProbS(dim, size, -1);
1253 if(type == CV_BT_HIST_TYPE_MG) return cvCreateProbMG(dim, size, -1);
1254 if(type == CV_BT_HIST_TYPE_MG2) return cvCreateProbMG2(dim, size, -1);
1255 if(type == CV_BT_HIST_TYPE_H) return cvCreateProbHist(dim, size);
1261 /* Noise type definitions: */
1262 #define CV_NOISE_NONE 0
1263 #define CV_NOISE_GAUSSIAN 1
1264 #define CV_NOISE_UNIFORM 2
1265 #define CV_NOISE_SPECKLE 3
1266 #define CV_NOISE_SALT_AND_PEPPER 4
1268 /* Add some noise to image: */
1269 /* pImg - (input) image without noise */
1270 /* pImg - (output) image with noise */
1271 /* noise_type - type of added noise */
1272 /* CV_NOISE_GAUSSIAN - pImg += n , n - is gaussian noise with Ampl standart deviation */
1273 /* CV_NOISE_UNIFORM - pImg += n , n - is uniform noise with Ampl standart deviation */
1274 /* CV_NOISE_SPECKLE - pImg += n*pImg , n - is gaussian noise with Ampl standart deviation */
1275 /* CV_NOISE_SALT_AND_PAPPER - pImg = pImg with blacked and whited pixels,
1276 Ampl is density of brocken pixels (0-there are not broken pixels, 1 - all pixels are broken)*/
1277 /* Ampl - "amplitude" of noise */
1278 CV_EXPORTS void cvAddNoise(IplImage* pImg, int noise_type, double Ampl, CvRandState* rnd_state = NULL);
1280 /*================== GENERATOR OF TEST VIDEO SEQUENCE ===================== */
1281 typedef void CvTestSeq;
1283 /* pConfigfile - Name of file (yml or xml) with description of test sequence */
1284 /* videos - array of names of test videos described in "pConfigfile" file */
1285 /* numvideos - size of "videos" array */
1286 CV_EXPORTS CvTestSeq* cvCreateTestSeq(char* pConfigfile, char** videos, int numvideo, float Scale = 1, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
1287 CV_EXPORTS void cvReleaseTestSeq(CvTestSeq** ppTestSeq);
1289 /* Generate next frame from test video seq and return pointer to it: */
1290 CV_EXPORTS IplImage* cvTestSeqQueryFrame(CvTestSeq* pTestSeq);
1292 /* Return pointer to current foreground mask: */
1293 CV_EXPORTS IplImage* cvTestSeqGetFGMask(CvTestSeq* pTestSeq);
1295 /* Return pointer to current image: */
1296 CV_EXPORTS IplImage* cvTestSeqGetImage(CvTestSeq* pTestSeq);
1298 /* Return frame size of result test video: */
1299 CV_EXPORTS CvSize cvTestSeqGetImageSize(CvTestSeq* pTestSeq);
1301 /* Return number of frames result test video: */
1302 CV_EXPORTS int cvTestSeqFrameNum(CvTestSeq* pTestSeq);
1304 /* Return number of existing objects.
1305 * This is general number of any objects.
1306 * For example number of trajectories may be equal or less than returned value:
1308 CV_EXPORTS int cvTestSeqGetObjectNum(CvTestSeq* pTestSeq);
1310 /* Return 0 if there is not position for current defined on current frame */
1311 /* Return 1 if there is object position and pPos was filled */
1312 CV_EXPORTS int cvTestSeqGetObjectPos(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pPos);
1313 CV_EXPORTS int cvTestSeqGetObjectSize(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pSize);
1315 /* Add noise to final image: */
1316 CV_EXPORTS void cvTestSeqAddNoise(CvTestSeq* pTestSeq, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
1318 /* Add Intensity variation: */
1319 CV_EXPORTS void cvTestSeqAddIntensityVariation(CvTestSeq* pTestSeq, float DI_per_frame, float MinI, float MaxI);
1320 CV_EXPORTS void cvTestSeqSetFrame(CvTestSeq* pTestSeq, int n);