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
55 #define strdup _strdup
56 #define stricmp _stricmp
58 #elif defined __GNUC__
59 #define cv_stricmp strcasecmp
60 #define cv_strnicmp strncasecmp
62 #error Do not know how to make case-insensitive string comparison on this platform
68 struct CvDefParam* next;
81 class CV_EXPORTS CvVSModule
83 private: /* Internal data: */
84 CvDefParam* m_pParamList;
85 char* m_pModuleTypeName;
90 public: /* Constructor and destructor: */
95 m_pModuleTypeName = NULL;
98 AddParam("DebugWnd",&m_Wnd);
100 virtual ~CvVSModule()
102 CvDefParam* p = m_pParamList;
110 if(m_pModuleTypeName)free(m_pModuleTypeName);
111 if(m_pModuleName)free(m_pModuleName);
113 private: /* Internal functions: */
114 void FreeParam(CvDefParam** pp)
116 CvDefParam* p = pp[0];
117 if(p->Str)free(p->Str);
118 if(p->pName)free(p->pName);
119 if(p->pComment)free(p->pComment);
122 CvDefParam* NewParam(const char* name)
124 CvDefParam* pNew = (CvDefParam*)cvAlloc(sizeof(CvDefParam));
125 memset(pNew,0,sizeof(CvDefParam));
126 pNew->pName = strdup(name);
127 if(m_pParamList==NULL)
133 CvDefParam* p = m_pParamList;
134 for(;p->next;p=p->next) ;
140 CvDefParam* GetParamPtr(int index)
142 CvDefParam* p = m_pParamList;
143 for(;index>0 && p;index--,p=p->next) ;
146 CvDefParam* GetParamPtr(const char* name)
148 CvDefParam* p = m_pParamList;
151 if(cv_stricmp(p->pName,name)==0) break;
155 protected: /* INTERNAL INTERFACE */
156 int IsParam(const char* name)
158 return GetParamPtr(name)?1:0;
160 void AddParam(const char* name, double* pAddr)
162 NewParam(name)->pDouble = pAddr;
164 void AddParam(const char* name, float* pAddr)
166 NewParam(name)->pFloat=pAddr;
168 void AddParam(const char* name, int* pAddr)
170 NewParam(name)->pInt=pAddr;
172 void AddParam(const char* name, const char** pAddr)
174 CvDefParam* pP = NewParam(name);
175 const char* p = pAddr?pAddr[0]:NULL;
176 pP->pStr = pAddr?(char**)pAddr:&(pP->Str);
180 pP->pStr[0] = pP->Str;
183 void AddParam(const char* name)
185 CvDefParam* p = NewParam(name);
186 p->pDouble = &p->Double;
188 void CommentParam(const char* name, const char* pComment)
190 CvDefParam* p = GetParamPtr(name);
191 if(p)p->pComment = pComment ? strdup(pComment) : 0;
193 void SetTypeName(const char* name){m_pModuleTypeName = strdup(name);}
194 void SetModuleName(const char* name){m_pModuleName = strdup(name);}
195 void DelParam(const char* name)
197 CvDefParam* p = m_pParamList;
198 CvDefParam* pPrev = NULL;
201 if(cv_stricmp(p->pName,name)==0) break;
208 pPrev->next = p->next;
212 m_pParamList = p->next;
218 public: /* EXTERNAL INTERFACE */
219 const char* GetParamName(int index)
221 CvDefParam* p = GetParamPtr(index);
222 return p?p->pName:NULL;
224 const char* GetParamComment(const char* name)
226 CvDefParam* p = GetParamPtr(name);
227 if(p && p->pComment) return p->pComment;
230 double GetParam(const char* name)
232 CvDefParam* p = GetParamPtr(name);
235 if(p->pDouble) return p->pDouble[0];
236 if(p->pFloat) return p->pFloat[0];
237 if(p->pInt) return p->pInt[0];
242 const char* GetParamStr(const char* name)
244 CvDefParam* p = GetParamPtr(name);
245 return p?p->Str:NULL;
247 void SetParam(const char* name, double val)
249 CvDefParam* p = m_pParamList;
252 if(cv_stricmp(p->pName,name) != 0) continue;
253 if(p->pDouble)p->pDouble[0] = val;
254 if(p->pFloat)p->pFloat[0] = (float)val;
255 if(p->pInt)p->pInt[0] = cvRound(val);
258 void SetParamStr(const char* name, const char* str)
260 CvDefParam* p = m_pParamList;
263 if(cv_stricmp(p->pName,name) != 0) continue;
266 if(p->Str)free(p->Str);
268 if(str)p->Str = strdup(str);
272 /* Convert to double and set: */
273 if(str) SetParam(name,atof(str));
275 void TransferParamsFromChild(CvVSModule* pM, const char* prefix = NULL)
278 const char* FN = NULL;
282 const char* N = pM->GetParamName(i);
294 if(pM->GetParamStr(N))
296 AddParam(FN,(const char**)NULL);
303 if(pM->GetParamStr(N))
305 const char* val = pM->GetParamStr(N);
310 double val = pM->GetParam(N);
313 CommentParam(FN, pM->GetParamComment(N));
314 }/* transfer next param */
315 }/* Transfer params */
317 void TransferParamsToChild(CvVSModule* pM, char* prefix = NULL)
323 const char* N = pM->GetParamName(i);
339 pM->SetParamStr(N,GetParamStr(tmp));
341 pM->SetParam(N,GetParam(tmp));
343 }/* Transfer next parameter */
345 }/* Transfer params */
347 virtual void ParamUpdate(){};
348 const char* GetTypeName()
350 return m_pModuleTypeName;
352 int IsModuleTypeName(const char* name)
354 return m_pModuleTypeName?(cv_stricmp(m_pModuleTypeName,name)==0):0;
356 char* GetModuleName()
358 return m_pModuleName;
360 int IsModuleName(const char* name)
362 return m_pModuleName?(cv_stricmp(m_pModuleName,name)==0):0;
364 void SetNickName(const char* pStr)
372 m_pNickName = strdup(pStr);
374 const char* GetNickName()
376 return m_pNickName ? m_pNickName : "unknown";
378 virtual void SaveState(CvFileStorage*){};
379 virtual void LoadState(CvFileStorage*, CvFileNode*){};
381 virtual void Release() = 0;
383 void inline cvWriteStruct(CvFileStorage* fs, const char* name, void* addr, const char* desc, int num=1)
385 cvStartWriteStruct(fs,name,CV_NODE_SEQ|CV_NODE_FLOW);
386 cvWriteRawData(fs,addr,num,desc);
387 cvEndWriteStruct(fs);
389 void inline cvReadStructByName(CvFileStorage* fs, CvFileNode* node, const char* name, void* addr, const char* desc)
391 CvFileNode* pSeqNode = cvGetFileNodeByName(fs, node, name);
394 printf("WARNING!!! Can't read structure %s\n",name);
398 if(CV_NODE_IS_SEQ(pSeqNode->tag))
400 cvReadRawData( fs, pSeqNode, addr, desc );
404 printf("WARNING!!! Structure %s is not sequence and can not be read\n",name);
410 /* FOREGROUND DETECTOR INTERFACE */
411 class CV_EXPORTS CvFGDetector: public CvVSModule
414 CvFGDetector(){SetTypeName("FGDetector");};
415 virtual IplImage* GetMask() = 0;
416 /* Process current image: */
417 virtual void Process(IplImage* pImg) = 0;
418 /* Release foreground detector: */
419 virtual void Release() = 0;
421 inline void cvReleaseFGDetector(CvFGDetector** ppT )
426 /* FOREGROUND DETECTOR INTERFACE */
428 CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param);
434 float x,y; /* blob position */
435 float w,h; /* blob sizes */
436 int ID; /* blob ID */
439 inline CvBlob cvBlob(float x,float y, float w, float h)
441 CvBlob B = {x,y,w,h,0};
444 #define CV_BLOB_MINW 5
445 #define CV_BLOB_MINH 5
446 #define CV_BLOB_ID(pB) (((CvBlob*)(pB))->ID)
447 #define CV_BLOB_CENTER(pB) cvPoint2D32f(((CvBlob*)(pB))->x,((CvBlob*)(pB))->y)
448 #define CV_BLOB_X(pB) (((CvBlob*)(pB))->x)
449 #define CV_BLOB_Y(pB) (((CvBlob*)(pB))->y)
450 #define CV_BLOB_WX(pB) (((CvBlob*)(pB))->w)
451 #define CV_BLOB_WY(pB) (((CvBlob*)(pB))->h)
452 #define CV_BLOB_RX(pB) (0.5f*CV_BLOB_WX(pB))
453 #define CV_BLOB_RY(pB) (0.5f*CV_BLOB_WY(pB))
454 #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)))
455 /* END BLOB STRUCTURE*/
458 /* simple BLOBLIST */
459 class CV_EXPORTS CvBlobSeq
462 CvBlobSeq(int BlobSize = sizeof(CvBlob))
464 m_pMem = cvCreateMemStorage();
465 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),BlobSize,m_pMem);
466 strcpy(m_pElemFormat,"ffffi");
470 cvReleaseMemStorage(&m_pMem);
472 virtual CvBlob* GetBlob(int BlobIndex)
474 return (CvBlob*)cvGetSeqElem(m_pSeq,BlobIndex);
476 virtual CvBlob* GetBlobByID(int BlobID)
479 for(i=0; i<m_pSeq->total; ++i)
480 if(BlobID == CV_BLOB_ID(GetBlob(i)))
484 virtual void DelBlob(int BlobIndex)
486 cvSeqRemove(m_pSeq,BlobIndex);
488 virtual void DelBlobByID(int BlobID)
491 for(i=0; i<m_pSeq->total; ++i)
493 if(BlobID == CV_BLOB_ID(GetBlob(i)))
504 virtual void AddBlob(CvBlob* pB)
506 cvSeqPush(m_pSeq,pB);
508 virtual int GetBlobNum()
510 return m_pSeq->total;
512 virtual void Write(CvFileStorage* fs, const char* name)
514 const char* attr[] = {"dt",m_pElemFormat,NULL};
517 cvWrite(fs,name,m_pSeq,cvAttrList(attr,NULL));
520 virtual void Load(CvFileStorage* fs, CvFileNode* node)
523 CvSeq* pSeq = (CvSeq*)cvRead(fs, node);
528 for(i=0;i<pSeq->total;++i)
530 void* pB = cvGetSeqElem( pSeq, i );
531 cvSeqPush( m_pSeq, pB );
535 void AddFormat(const char* str){strcat(m_pElemFormat,str);}
537 CvMemStorage* m_pMem;
539 char m_pElemFormat[1024];
541 /* simple BLOBLIST */
544 /* simple TRACKLIST */
552 class CV_EXPORTS CvBlobTrackSeq
555 CvBlobTrackSeq(int TrackSize = sizeof(CvBlobTrack))
557 m_pMem = cvCreateMemStorage();
558 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),TrackSize,m_pMem);
560 virtual ~CvBlobTrackSeq()
563 cvReleaseMemStorage(&m_pMem);
565 virtual CvBlobTrack* GetBlobTrack(int TrackIndex)
567 return (CvBlobTrack*)cvGetSeqElem(m_pSeq,TrackIndex);
569 virtual CvBlobTrack* GetBlobTrackByID(int TrackID)
572 for(i=0; i<m_pSeq->total; ++i)
574 CvBlobTrack* pP = GetBlobTrack(i);
575 if(pP && pP->TrackID == TrackID)
580 virtual void DelBlobTrack(int TrackIndex)
582 CvBlobTrack* pP = GetBlobTrack(TrackIndex);
583 if(pP && pP->pBlobSeq) delete pP->pBlobSeq;
584 cvSeqRemove(m_pSeq,TrackIndex);
586 virtual void DelBlobTrackByID(int TrackID)
589 for(i=0; i<m_pSeq->total; ++i)
591 CvBlobTrack* pP = GetBlobTrack(i);
592 if(TrackID == pP->TrackID)
602 for(i=GetBlobTrackNum();i>0;i--)
608 virtual void AddBlobTrack(int TrackID, int StartFrame = 0)
612 N.StartFrame = StartFrame;
613 N.pBlobSeq = new CvBlobSeq;
614 cvSeqPush(m_pSeq,&N);
616 virtual int GetBlobTrackNum()
618 return m_pSeq->total;
621 CvMemStorage* m_pMem;
625 /* simple TRACKLIST */
628 /* BLOB DETECTOR INTERFACE */
629 class CV_EXPORTS CvBlobDetector: public CvVSModule
632 CvBlobDetector(){SetTypeName("BlobDetector");};
633 /* Try to detect new blob entrance based on foreground mask. */
634 /* pFGMask - image of foreground mask */
635 /* pNewBlob - pointer to CvBlob structure which will be filled if new blob entrance detected */
636 /* pOldBlobList - pointer to blob list which already exist on image */
637 virtual int DetectNewBlob(IplImage* pImg, IplImage* pImgFG, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList) = 0;
638 /* release blob detector */
639 virtual void Release()=0;
641 /* Release any blob detector: */
642 inline void cvReleaseBlobDetector(CvBlobDetector** ppBD)
647 /* END BLOB DETECTOR INTERFACE */
649 /* Declarations of constructors of implemented modules: */
650 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorSimple();
651 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorCC();
654 struct CV_EXPORTS CvDetectedBlob : public CvBlob
659 CV_INLINE CvDetectedBlob cvDetectedBlob( float x, float y, float w, float h, int ID = 0, float response = 0.0F )
662 b.x = x; b.y = y; b.w = w; b.h = h; b.ID = ID; b.response = response;
667 class CV_EXPORTS CvObjectDetector
670 CvObjectDetector( const char* /*detector_file_name*/ = 0 ) {};
672 ~CvObjectDetector() {};
675 * Release the current detector and load new detector from file
676 * (if detector_file_name is not 0)
677 * Return true on success:
679 bool Load( const char* /*detector_file_name*/ = 0 ) { return false; }
681 /* Return min detector window size: */
682 CvSize GetMinWindowSize() const { return cvSize(0,0); }
684 /* Return max border: */
685 int GetMaxBorderSize() const { return 0; }
688 * Detect the object on the image and push the detected
689 * blobs into <detected_blob_seq> which must be the sequence of <CvDetectedBlob>s
691 void Detect( const CvArr* /*img*/, /* out */ CvBlobSeq* /*detected_blob_seq*/ = 0 ) {};
694 class CvObjectDetectorImpl* impl;
698 CV_INLINE CvRect cvRectIntersection( const CvRect r1, const CvRect r2 )
700 CvRect r = cvRect( MAX(r1.x, r2.x), MAX(r1.y, r2.y), 0, 0 );
702 r.width = MIN(r1.x + r1.width, r2.x + r2.width) - r.x;
703 r.height = MIN(r1.y + r1.height, r2.y + r2.height) - r.y;
712 * Draw on an image the specified ROIs from the source image and
713 * given blobs as ellipses or rectangles:
718 enum {RECT, ELLIPSE} shape;
722 /*extern const CvDrawShape icv_shape[] =
724 { CvDrawShape::ELLIPSE, CV_RGB(255,0,0) },
725 { CvDrawShape::ELLIPSE, CV_RGB(0,255,0) },
726 { CvDrawShape::ELLIPSE, CV_RGB(0,0,255) },
727 { CvDrawShape::ELLIPSE, CV_RGB(255,255,0) },
728 { CvDrawShape::ELLIPSE, CV_RGB(0,255,255) },
729 { CvDrawShape::ELLIPSE, CV_RGB(255,0,255) }
732 class CV_EXPORTS CvImageDrawer
735 CvImageDrawer() : m_image(0) {}
736 ~CvImageDrawer() { cvReleaseImage( &m_image ); }
737 void SetShapes( const CvDrawShape* shapes, int num );
738 /* <blob_seq> must be the sequence of <CvDetectedBlob>s */
739 IplImage* Draw( const CvArr* src, CvBlobSeq* blob_seq = 0, const CvSeq* roi_seq = 0 );
740 IplImage* GetImage() { return m_image; }
742 //static const int MAX_SHAPES = sizeof(icv_shape) / sizeof(icv_shape[0]);;
745 CvDrawShape m_shape[16];
750 /* Trajectory generation module: */
751 class CV_EXPORTS CvBlobTrackGen: public CvVSModule
754 CvBlobTrackGen(){SetTypeName("BlobTrackGen");};
755 virtual void SetFileName(char* pFileName) = 0;
756 virtual void AddBlob(CvBlob* pBlob) = 0;
757 virtual void Process(IplImage* pImg = NULL, IplImage* pFG = NULL) = 0;
758 virtual void Release() = 0;
761 inline void cvReleaseBlobTrackGen(CvBlobTrackGen** pBTGen)
763 if(*pBTGen)(*pBTGen)->Release();
767 /* Declarations of constructors of implemented modules: */
768 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGen1();
769 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGenYML();
773 /* BLOB TRACKER INTERFACE */
774 class CV_EXPORTS CvBlobTracker: public CvVSModule
777 CvBlobTracker(){SetTypeName("BlobTracker");};
779 /* Add new blob to track it and assign to this blob personal ID */
780 /* pBlob - pointer to structure with blob parameters (ID is ignored)*/
781 /* pImg - current image */
782 /* pImgFG - current foreground mask */
783 /* Return pointer to new added blob: */
784 virtual CvBlob* AddBlob(CvBlob* pBlob, IplImage* pImg, IplImage* pImgFG = NULL ) = 0;
786 /* Return number of currently tracked blobs: */
787 virtual int GetBlobNum() = 0;
789 /* Return pointer to specified by index blob: */
790 virtual CvBlob* GetBlob(int BlobIndex) = 0;
792 /* Delete blob by its index: */
793 virtual void DelBlob(int BlobIndex) = 0;
795 /* Process current image and track all existed blobs: */
796 virtual void Process(IplImage* pImg, IplImage* pImgFG = NULL) = 0;
798 /* Release blob tracker: */
799 virtual void Release() = 0;
802 /* Process one blob (for multi hypothesis tracing): */
803 virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
809 pB = GetBlob(BlobIndex);
815 /* Get confidence/wieght/probability (0-1) for blob: */
816 virtual double GetConfidence(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
821 virtual double GetConfidenceList(CvBlobSeq* pBlobList, IplImage* pImg, IplImage* pImgFG = NULL)
823 int b,bN = pBlobList->GetBlobNum();
827 CvBlob* pB = pBlobList->GetBlob(b);
828 int BI = GetBlobIndexByID(pB->ID);
829 W *= GetConfidence(BI,pB,pImg,pImgFG);
834 virtual void UpdateBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
836 /* Update all blob models: */
837 virtual void Update(IplImage* pImg, IplImage* pImgFG = NULL)
840 for(i=GetBlobNum();i>0;i--)
842 CvBlob* pB=GetBlob(i-1);
843 UpdateBlob(i-1, pB, pImg, pImgFG);
848 /* Return pointer to blob by its unique ID: */
849 virtual int GetBlobIndexByID(int BlobID)
852 for(i=GetBlobNum();i>0;i--)
854 CvBlob* pB=GetBlob(i-1);
855 if(CV_BLOB_ID(pB) == BlobID) return i-1;
860 /* Return pointer to blob by its unique ID: */
861 virtual CvBlob* GetBlobByID(int BlobID){return GetBlob(GetBlobIndexByID(BlobID));};
863 /* Delete blob by its ID: */
864 virtual void DelBlobByID(int BlobID){DelBlob(GetBlobIndexByID(BlobID));};
866 /* Set new parameters for specified (by index) blob: */
867 virtual void SetBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
869 /* Set new parameters for specified (by ID) blob: */
870 virtual void SetBlobByID(int BlobID, CvBlob* pBlob)
872 SetBlob(GetBlobIndexByID(BlobID),pBlob);
875 /* =============== MULTI HYPOTHESIS INTERFACE ================== */
877 /* Return number of position hyposetis of currently tracked blob: */
878 virtual int GetBlobHypNum(int /*BlobIdx*/){return 1;};
880 /* Return pointer to specified blob hypothesis by index blob: */
881 virtual CvBlob* GetBlobHyp(int BlobIndex, int /*hypothesis*/){return GetBlob(BlobIndex);};
883 /* Set new parameters for specified (by index) blob hyp
884 * (can be called several times for each hyp ):
886 virtual void SetBlobHyp(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
888 inline void cvReleaseBlobTracker(CvBlobTracker**ppT )
893 /* BLOB TRACKER INTERFACE */
895 /*BLOB TRACKER ONE INTERFACE */
896 class CV_EXPORTS CvBlobTrackerOne:public CvVSModule
899 virtual void Init(CvBlob* pBlobInit, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
900 virtual CvBlob* Process(CvBlob* pBlobPrev, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
901 virtual void Release() = 0;
903 /* Non-required methods: */
904 virtual void SkipProcess(CvBlob* /*pBlobPrev*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
905 virtual void Update(CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
906 virtual void SetCollision(int /*CollisionFlag*/){}; /* call in case of blob collision situation*/
907 virtual double GetConfidence(CvBlob* /*pBlob*/, IplImage* /*pImg*/,
908 IplImage* /*pImgFG*/ = NULL, IplImage* /*pImgUnusedReg*/ = NULL)
913 inline void cvReleaseBlobTrackerOne(CvBlobTrackerOne **ppT )
918 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerList(CvBlobTrackerOne* (*create)());
919 /*BLOB TRACKER ONE INTERFACE */
921 /* Declarations of constructors of implemented modules: */
923 /* Some declarations for specific MeanShift tracker: */
924 #define PROFILE_EPANECHNIKOV 0
925 #define PROFILE_DOG 1
926 struct CvBlobTrackerParamMS
929 int appearance_profile;
930 int meanshift_profile;
934 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1(CvBlobTrackerParamMS* param);
935 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS2(CvBlobTrackerParamMS* param);
936 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1ByList();
938 /* Some declarations for specific Likelihood tracker: */
939 struct CvBlobTrackerParamLH
941 int HistType; /* see Prob.h */
945 /* Without scale optimization: */
946 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHR(CvBlobTrackerParamLH* /*param*/ = NULL);
948 /* With scale optimization: */
949 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHRS(CvBlobTrackerParamLH* /*param*/ = NULL);
951 /* Simple blob tracker based on connected component tracking: */
952 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCC();
954 /* Connected component tracking and mean-shift particle filter collion-resolver: */
955 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCCMSPF();
957 /* Blob tracker that integrates meanshift and connected components: */
958 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFG();
959 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFGS();
961 /* Meanshift without connected-components */
962 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS();
964 /* Particle filtering via Bhattacharya coefficient, which */
965 /* is roughly the dot-product of two probability densities. */
966 /* See: Real-Time Tracking of Non-Rigid Objects using Mean Shift */
967 /* Comanicius, Ramesh, Meer, 2000, 8p */
968 /* http://citeseer.ist.psu.edu/321441.html */
969 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSPF();
971 /* =========== tracker integrators trackers =============*/
973 /* Integrator based on Particle Filtering method: */
974 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPF();
976 /* Rule based integrator: */
977 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIRB();
979 /* Integrator based on data fusion using particle filtering: */
980 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPFDF();
985 /* Trajectory postprocessing module: */
986 class CV_EXPORTS CvBlobTrackPostProc: public CvVSModule
989 CvBlobTrackPostProc(){SetTypeName("BlobTrackPostProc");};
990 virtual void AddBlob(CvBlob* pBlob) = 0;
991 virtual void Process() = 0;
992 virtual int GetBlobNum() = 0;
993 virtual CvBlob* GetBlob(int index) = 0;
994 virtual void Release() = 0;
996 /* Additional functionality: */
997 virtual CvBlob* GetBlobByID(int BlobID)
1000 for(i=GetBlobNum();i>0;i--)
1002 CvBlob* pB=GetBlob(i-1);
1003 if(pB->ID==BlobID) return pB;
1009 inline void cvReleaseBlobTrackPostProc(CvBlobTrackPostProc** pBTPP)
1011 if(pBTPP == NULL) return;
1012 if(*pBTPP)(*pBTPP)->Release();
1016 /* Trajectory generation module: */
1017 class CV_EXPORTS CvBlobTrackPostProcOne: public CvVSModule
1020 CvBlobTrackPostProcOne(){SetTypeName("BlobTrackPostOne");};
1021 virtual CvBlob* Process(CvBlob* pBlob) = 0;
1022 virtual void Release() = 0;
1025 /* Create blob tracking post processing module based on simle module: */
1026 CV_EXPORTS CvBlobTrackPostProc* cvCreateBlobTrackPostProcList(CvBlobTrackPostProcOne* (*create)());
1029 /* Declarations of constructors of implemented modules: */
1030 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcKalman();
1031 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverRect();
1032 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverExp();
1036 /* blob PREDICTOR */
1037 class CvBlobTrackPredictor: public CvVSModule
1040 CvBlobTrackPredictor(){SetTypeName("BlobTrackPredictor");};
1041 virtual CvBlob* Predict() = 0;
1042 virtual void Update(CvBlob* pBlob) = 0;
1043 virtual void Release() = 0;
1045 CV_EXPORTS CvBlobTrackPredictor* cvCreateModuleBlobTrackPredictKalman();
1049 /* Trajectory analyser module: */
1050 class CV_EXPORTS CvBlobTrackAnalysis: public CvVSModule
1053 CvBlobTrackAnalysis(){SetTypeName("BlobTrackAnalysis");};
1054 virtual void AddBlob(CvBlob* pBlob) = 0;
1055 virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
1056 virtual float GetState(int BlobID) = 0;
1057 /* return 0 if trajectory is normal
1058 return >0 if trajectory abnormal */
1059 virtual const char* GetStateDesc(int /*BlobID*/){return NULL;};
1060 virtual void SetFileName(char* /*DataBaseName*/){};
1061 virtual void Release() = 0;
1065 inline void cvReleaseBlobTrackAnalysis(CvBlobTrackAnalysis** pBTPP)
1067 if(pBTPP == NULL) return;
1068 if(*pBTPP)(*pBTPP)->Release();
1072 /* Feature-vector generation module: */
1073 class CV_EXPORTS CvBlobTrackFVGen : public CvVSModule
1076 CvBlobTrackFVGen(){SetTypeName("BlobTrackFVGen");};
1077 virtual void AddBlob(CvBlob* pBlob) = 0;
1078 virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
1079 virtual void Release() = 0;
1080 virtual int GetFVSize() = 0;
1081 virtual int GetFVNum() = 0;
1082 virtual float* GetFV(int index, int* pFVID) = 0; /* Returns pointer to FV, if return 0 then FV not created */
1083 virtual float* GetFVVar(){return NULL;}; /* Returns pointer to array of variation of values of FV, if returns 0 then FVVar does not exist. */
1084 virtual float* GetFVMin() = 0; /* Returns pointer to array of minimal values of FV, if returns 0 then FVrange does not exist */
1085 virtual float* GetFVMax() = 0; /* Returns pointer to array of maximal values of FV, if returns 0 then FVrange does not exist */
1089 /* Trajectory Analyser module: */
1090 class CV_EXPORTS CvBlobTrackAnalysisOne
1093 virtual ~CvBlobTrackAnalysisOne() {};
1094 virtual int Process(CvBlob* pBlob, IplImage* pImg, IplImage* pFG) = 0;
1095 /* return 0 if trajectory is normal
1096 return >0 if trajectory abnormal */
1097 virtual void Release() = 0;
1100 /* Create blob tracking post processing module based on simle module: */
1101 CV_EXPORTS CvBlobTrackAnalysis* cvCreateBlobTrackAnalysisList(CvBlobTrackAnalysisOne* (*create)());
1103 /* Declarations of constructors of implemented modules: */
1105 /* Based on histogram analysis of 2D FV (x,y): */
1106 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistP();
1108 /* Based on histogram analysis of 4D FV (x,y,vx,vy): */
1109 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPV();
1111 /* Based on histogram analysis of 5D FV (x,y,vx,vy,state): */
1112 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPVS();
1114 /* Based on histogram analysis of 4D FV (startpos,stoppos): */
1115 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistSS();
1119 /* Based on SVM classifier analysis of 2D FV (x,y): */
1120 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP();
1122 /* Based on SVM classifier analysis of 4D FV (x,y,vx,vy): */
1123 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPV();
1125 /* Based on SVM classifier analysis of 5D FV (x,y,vx,vy,state): */
1126 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS();
1128 /* Based on SVM classifier analysis of 4D FV (startpos,stoppos): */
1129 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS();
1131 /* Track analysis based on distance between tracks: */
1132 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisTrackDist();
1134 /* Analyzer based on reation Road and height map: */
1135 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysis3DRoadMap();
1137 /* Analyzer that makes OR decision using set of analyzers: */
1138 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR();
1140 /* Estimator of human height: */
1141 class CV_EXPORTS CvBlobTrackAnalysisHeight: public CvBlobTrackAnalysis
1144 virtual double GetHeight(CvBlob* pB) = 0;
1146 //CV_EXPORTS CvBlobTrackAnalysisHeight* cvCreateModuleBlobTrackAnalysisHeightScale();
1150 /* AUTO BLOB TRACKER INTERFACE -- pipeline of 3 modules: */
1151 class CV_EXPORTS CvBlobTrackerAuto: public CvVSModule
1154 CvBlobTrackerAuto(){SetTypeName("BlobTrackerAuto");};
1155 virtual void Process(IplImage* pImg, IplImage* pMask = NULL) = 0;
1156 virtual CvBlob* GetBlob(int index) = 0;
1157 virtual CvBlob* GetBlobByID(int ID) = 0;
1158 virtual int GetBlobNum() = 0;
1159 virtual IplImage* GetFGMask(){return NULL;};
1160 virtual float GetState(int BlobID) = 0;
1161 virtual const char* GetStateDesc(int BlobID) = 0;
1162 /* return 0 if trajectory is normal;
1163 * return >0 if trajectory abnormal. */
1164 virtual void Release() = 0;
1166 inline void cvReleaseBlobTrackerAuto(CvBlobTrackerAuto** ppT)
1171 /* END AUTO BLOB TRACKER INTERFACE */
1174 /* Constructor functions and data for specific BlobTRackerAuto modules: */
1176 /* Parameters of blobtracker auto ver1: */
1177 struct CvBlobTrackerAutoParam1
1179 int FGTrainFrames; /* Number of frames needed for FG (foreground) detector to train. */
1181 CvFGDetector* pFG; /* FGDetector module. If this field is NULL the Process FG mask is used. */
1183 CvBlobDetector* pBD; /* Selected blob detector module. */
1184 /* If this field is NULL default blobdetector module will be created. */
1186 CvBlobTracker* pBT; /* Selected blob tracking module. */
1187 /* If this field is NULL default blobtracker module will be created. */
1189 CvBlobTrackGen* pBTGen; /* Selected blob trajectory generator. */
1190 /* If this field is NULL no generator is used. */
1192 CvBlobTrackPostProc* pBTPP; /* Selected blob trajectory postprocessing module. */
1193 /* If this field is NULL no postprocessing is done. */
1197 CvBlobTrackAnalysis* pBTA; /* Selected blob trajectory analysis module. */
1198 /* If this field is NULL no track analysis is done. */
1201 /* Create blob tracker auto ver1: */
1202 CV_EXPORTS CvBlobTrackerAuto* cvCreateBlobTrackerAuto1(CvBlobTrackerAutoParam1* param = NULL);
1204 /* Simple loader for many auto trackers by its type : */
1205 inline CvBlobTrackerAuto* cvCreateBlobTrackerAuto(int type, void* param)
1207 if(type == 0) return cvCreateBlobTrackerAuto1((CvBlobTrackerAutoParam1*)param);
1213 struct CvTracksTimePos
1218 int comLen; //common length for two tracks
1222 /*CV_EXPORTS int cvCompareTracks( CvBlobTrackSeq *groundTruth,
1223 CvBlobTrackSeq *result,
1227 /* Constructor functions: */
1229 CV_EXPORTS void cvCreateTracks_One(CvBlobTrackSeq *TS);
1230 CV_EXPORTS void cvCreateTracks_Same(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2);
1231 CV_EXPORTS void cvCreateTracks_AreaErr(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2, int addW, int addH);
1235 class CV_EXPORTS CvProb
1238 virtual ~CvProb() {};
1240 /* Calculate probability value: */
1241 virtual double Value(int* /*comp*/, int /*x*/ = 0, int /*y*/ = 0){return -1;};
1243 /* Update histograpp Pnew = (1-W)*Pold + W*Padd*/
1244 /* W weight of new added prob */
1245 /* comps - matrix of new fetature vectors used to update prob */
1246 virtual void AddFeature(float W, int* comps, int x =0, int y = 0) = 0;
1247 virtual void Scale(float factor = 0, int x = -1, int y = -1) = 0;
1248 virtual void Release() = 0;
1250 inline void cvReleaseProb(CvProb** ppProb){ppProb[0]->Release();ppProb[0]=NULL;}
1254 CV_EXPORTS CvProb* cvCreateProbS(int dim, CvSize size, int sample_num);
1255 CV_EXPORTS CvProb* cvCreateProbMG(int dim, CvSize size, int sample_num);
1256 CV_EXPORTS CvProb* cvCreateProbMG2(int dim, CvSize size, int sample_num);
1257 CV_EXPORTS CvProb* cvCreateProbHist(int dim, CvSize size);
1259 #define CV_BT_HIST_TYPE_S 0
1260 #define CV_BT_HIST_TYPE_MG 1
1261 #define CV_BT_HIST_TYPE_MG2 2
1262 #define CV_BT_HIST_TYPE_H 3
1263 inline CvProb* cvCreateProb(int type, int dim, CvSize size = cvSize(1,1), void* /*param*/ = NULL)
1265 if(type == CV_BT_HIST_TYPE_S) return cvCreateProbS(dim, size, -1);
1266 if(type == CV_BT_HIST_TYPE_MG) return cvCreateProbMG(dim, size, -1);
1267 if(type == CV_BT_HIST_TYPE_MG2) return cvCreateProbMG2(dim, size, -1);
1268 if(type == CV_BT_HIST_TYPE_H) return cvCreateProbHist(dim, size);
1274 /* Noise type definitions: */
1275 #define CV_NOISE_NONE 0
1276 #define CV_NOISE_GAUSSIAN 1
1277 #define CV_NOISE_UNIFORM 2
1278 #define CV_NOISE_SPECKLE 3
1279 #define CV_NOISE_SALT_AND_PEPPER 4
1281 /* Add some noise to image: */
1282 /* pImg - (input) image without noise */
1283 /* pImg - (output) image with noise */
1284 /* noise_type - type of added noise */
1285 /* CV_NOISE_GAUSSIAN - pImg += n , n - is gaussian noise with Ampl standart deviation */
1286 /* CV_NOISE_UNIFORM - pImg += n , n - is uniform noise with Ampl standart deviation */
1287 /* CV_NOISE_SPECKLE - pImg += n*pImg , n - is gaussian noise with Ampl standart deviation */
1288 /* CV_NOISE_SALT_AND_PAPPER - pImg = pImg with blacked and whited pixels,
1289 Ampl is density of brocken pixels (0-there are not broken pixels, 1 - all pixels are broken)*/
1290 /* Ampl - "amplitude" of noise */
1291 CV_EXPORTS void cvAddNoise(IplImage* pImg, int noise_type, double Ampl, CvRandState* rnd_state = NULL);
1293 /*================== GENERATOR OF TEST VIDEO SEQUENCE ===================== */
1294 typedef void CvTestSeq;
1296 /* pConfigfile - Name of file (yml or xml) with description of test sequence */
1297 /* videos - array of names of test videos described in "pConfigfile" file */
1298 /* numvideos - size of "videos" array */
1299 CV_EXPORTS CvTestSeq* cvCreateTestSeq(char* pConfigfile, char** videos, int numvideo, float Scale = 1, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
1300 CV_EXPORTS void cvReleaseTestSeq(CvTestSeq** ppTestSeq);
1302 /* Generate next frame from test video seq and return pointer to it: */
1303 CV_EXPORTS IplImage* cvTestSeqQueryFrame(CvTestSeq* pTestSeq);
1305 /* Return pointer to current foreground mask: */
1306 CV_EXPORTS IplImage* cvTestSeqGetFGMask(CvTestSeq* pTestSeq);
1308 /* Return pointer to current image: */
1309 CV_EXPORTS IplImage* cvTestSeqGetImage(CvTestSeq* pTestSeq);
1311 /* Return frame size of result test video: */
1312 CV_EXPORTS CvSize cvTestSeqGetImageSize(CvTestSeq* pTestSeq);
1314 /* Return number of frames result test video: */
1315 CV_EXPORTS int cvTestSeqFrameNum(CvTestSeq* pTestSeq);
1317 /* Return number of existing objects.
1318 * This is general number of any objects.
1319 * For example number of trajectories may be equal or less than returned value:
1321 CV_EXPORTS int cvTestSeqGetObjectNum(CvTestSeq* pTestSeq);
1323 /* Return 0 if there is not position for current defined on current frame */
1324 /* Return 1 if there is object position and pPos was filled */
1325 CV_EXPORTS int cvTestSeqGetObjectPos(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pPos);
1326 CV_EXPORTS int cvTestSeqGetObjectSize(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pSize);
1328 /* Add noise to final image: */
1329 CV_EXPORTS void cvTestSeqAddNoise(CvTestSeq* pTestSeq, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
1331 /* Add Intensity variation: */
1332 CV_EXPORTS void cvTestSeqAddIntensityVariation(CvTestSeq* pTestSeq, float DI_per_frame, float MinI, float MaxI);
1333 CV_EXPORTS void cvTestSeqSetFrame(CvTestSeq* pTestSeq, int n);