Update to 2.0.0 tree from current Fremantle build
[opencv] / include / opencv / cvvidsurv.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
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.
25 //
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.
28 //
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.
39 //
40 //M*/
41
42
43 #ifndef __CVVIDEOSURVEILLANCE_H__
44 #define __CVVIDEOSURVEILLANCE_H__
45
46 /* Turn off the functionality until cvaux/src/Makefile.am gets updated: */
47 //#if _MSC_VER >= 1200
48
49 #include <stdio.h>
50
51 #if _MSC_VER >= 1200 || defined __BORLANDC__
52 #define cv_stricmp stricmp
53 #define cv_strnicmp strnicmp
54 #if defined WINCE
55 #define strdup _strdup
56 #define stricmp _stricmp
57 #endif
58 #elif defined __GNUC__
59 #define cv_stricmp strcasecmp
60 #define cv_strnicmp strncasecmp
61 #else
62 #error Do not know how to make case-insensitive string comparison on this platform
63 #endif
64
65 //struct DefParam;
66 struct CvDefParam
67 {
68     struct CvDefParam*    next;
69     char*               pName;
70     char*               pComment;
71     double*             pDouble;
72     double              Double;
73     float*              pFloat;
74     float               Float;
75     int*                pInt;
76     int                 Int;
77     char**              pStr;
78     char*               Str;
79 };
80
81 class CV_EXPORTS CvVSModule
82 {
83 private: /* Internal data: */
84     CvDefParam*   m_pParamList;
85     char*       m_pModuleTypeName;
86     char*       m_pModuleName;
87     char*       m_pNickName;
88 protected:
89     int         m_Wnd;
90 public: /* Constructor and destructor: */
91     CvVSModule()
92     {
93         m_pNickName = NULL;
94         m_pParamList = NULL;
95         m_pModuleTypeName = NULL;
96         m_pModuleName = NULL;
97         m_Wnd = 0;
98         AddParam("DebugWnd",&m_Wnd);
99     }
100     virtual ~CvVSModule()
101     {
102         CvDefParam* p = m_pParamList;
103         for(;p;)
104         {
105             CvDefParam* pf = p;
106             p=p->next;
107             FreeParam(&pf);
108         }
109         m_pParamList=NULL;
110         if(m_pModuleTypeName)free(m_pModuleTypeName);
111         if(m_pModuleName)free(m_pModuleName);
112     }
113 private: /* Internal functions: */
114     void    FreeParam(CvDefParam** pp)
115     {
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);
120         cvFree(pp);
121     }
122     CvDefParam* NewParam(const char* name)
123     {
124         CvDefParam* pNew = (CvDefParam*)cvAlloc(sizeof(CvDefParam));
125         memset(pNew,0,sizeof(CvDefParam));
126         pNew->pName = strdup(name);
127         if(m_pParamList==NULL)
128         {
129             m_pParamList = pNew;
130         }
131         else
132         {
133             CvDefParam* p = m_pParamList;
134             for(;p->next;p=p->next) ;
135             p->next = pNew;
136         }
137         return pNew;
138     };
139
140     CvDefParam* GetParamPtr(int index)
141     {
142         CvDefParam* p = m_pParamList;
143         for(;index>0 && p;index--,p=p->next) ;
144         return p;
145     }
146     CvDefParam* GetParamPtr(const char* name)
147     {
148         CvDefParam* p = m_pParamList;
149         for(;p;p=p->next)
150         {
151             if(cv_stricmp(p->pName,name)==0) break;
152         }
153         return p;
154     }
155 protected: /* INTERNAL INTERFACE */
156     int  IsParam(const char* name)
157     {
158         return GetParamPtr(name)?1:0;
159     };
160     void AddParam(const char* name, double* pAddr)
161     {
162         NewParam(name)->pDouble = pAddr;
163     };
164     void AddParam(const char* name, float* pAddr)
165     {
166         NewParam(name)->pFloat=pAddr;
167     };
168     void AddParam(const char* name, int* pAddr)
169     {
170         NewParam(name)->pInt=pAddr;
171     };
172     void AddParam(const char* name, const char** pAddr)
173     {
174         CvDefParam* pP = NewParam(name);
175         const char* p = pAddr?pAddr[0]:NULL;
176         pP->pStr = pAddr?(char**)pAddr:&(pP->Str);
177         if(p)
178         {
179             pP->Str = strdup(p);
180             pP->pStr[0] = pP->Str;
181         }
182     };
183     void AddParam(const char* name)
184     {
185         CvDefParam* p = NewParam(name);
186         p->pDouble = &p->Double;
187     };
188     void CommentParam(const char* name, const char* pComment)
189     {
190         CvDefParam* p = GetParamPtr(name);
191         if(p)p->pComment = pComment ? strdup(pComment) : 0;
192     };
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)
196     {
197         CvDefParam* p = m_pParamList;
198         CvDefParam* pPrev = NULL;
199         for(;p;p=p->next)
200         {
201             if(cv_stricmp(p->pName,name)==0) break;
202             pPrev = p;
203         }
204         if(p)
205         {
206             if(pPrev)
207             {
208                 pPrev->next = p->next;
209             }
210             else
211             {
212                 m_pParamList = p->next;
213             }
214             FreeParam(&p);
215         }
216     }/* DelParam */
217
218 public: /* EXTERNAL INTERFACE */
219     const char* GetParamName(int index)
220     {
221         CvDefParam* p = GetParamPtr(index);
222         return p?p->pName:NULL;
223     }
224     const char* GetParamComment(const char* name)
225     {
226         CvDefParam* p = GetParamPtr(name);
227         if(p && p->pComment) return p->pComment;
228         return NULL;
229     }
230     double GetParam(const char* name)
231     {
232         CvDefParam* p = GetParamPtr(name);
233         if(p)
234         {
235             if(p->pDouble) return p->pDouble[0];
236             if(p->pFloat) return p->pFloat[0];
237             if(p->pInt) return p->pInt[0];
238         }
239         return 0;
240     };
241
242     const char* GetParamStr(const char* name)
243     {
244         CvDefParam* p = GetParamPtr(name);
245         return p?p->Str:NULL;
246     }
247     void   SetParam(const char* name, double val)
248     {
249         CvDefParam* p = m_pParamList;
250         for(;p;p=p->next)
251         {
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);
256         }
257     }
258     void   SetParamStr(const char* name, const char* str)
259     {
260         CvDefParam* p = m_pParamList;
261         for(; p; p=p->next)
262         {
263             if(cv_stricmp(p->pName,name) != 0) continue;
264             if(p->pStr)
265             {
266                 if(p->Str)free(p->Str);
267                 p->Str = NULL;
268                 if(str)p->Str = strdup(str);
269                 p->pStr[0] = p->Str;
270             }
271         }
272         /* Convert to double and set: */
273         if(str) SetParam(name,atof(str));
274     }
275     void TransferParamsFromChild(CvVSModule* pM, const char* prefix = NULL)
276     {
277         char    tmp[1024];
278         const char*   FN = NULL;
279         int i;
280         for(i=0;;++i)
281         {
282             const char* N = pM->GetParamName(i);
283             if(N == NULL) break;
284             FN = N;
285             if(prefix)
286             {
287                 strcpy(tmp,prefix);
288                 strcat(tmp,"_");
289                 FN = strcat(tmp,N);
290             }
291
292             if(!IsParam(FN))
293             {
294                 if(pM->GetParamStr(N))
295                 {
296                     AddParam(FN,(const char**)NULL);
297                 }
298                 else
299                 {
300                     AddParam(FN);
301                 }
302             }
303             if(pM->GetParamStr(N))
304             {
305                 const char* val = pM->GetParamStr(N);
306                 SetParamStr(FN,val);
307             }
308             else
309             {
310                 double val = pM->GetParam(N);
311                 SetParam(FN,val);
312             }
313             CommentParam(FN, pM->GetParamComment(N));
314         }/* transfer next param */
315     }/* Transfer params */
316
317     void TransferParamsToChild(CvVSModule* pM, char* prefix = NULL)
318     {
319         char    tmp[1024];
320         int i;
321         for(i=0;;++i)
322         {
323             const char* N = pM->GetParamName(i);
324             if(N == NULL) break;
325             if(prefix)
326             {
327                 strcpy(tmp,prefix);
328                 strcat(tmp,"_");
329                 strcat(tmp,N);
330             }
331             else
332             {
333                 strcpy(tmp,N);
334             }
335
336             if(IsParam(tmp))
337             {
338                 if(GetParamStr(tmp))
339                     pM->SetParamStr(N,GetParamStr(tmp));
340                 else
341                     pM->SetParam(N,GetParam(tmp));
342             }
343         }/* Transfer next parameter */
344         pM->ParamUpdate();
345     }/* Transfer params */
346
347     virtual void ParamUpdate(){};
348     const char*   GetTypeName()
349     {
350         return m_pModuleTypeName;
351     }
352     int     IsModuleTypeName(const char* name)
353     {
354         return m_pModuleTypeName?(cv_stricmp(m_pModuleTypeName,name)==0):0;
355     }
356     char*   GetModuleName()
357     {
358         return m_pModuleName;
359     }
360     int     IsModuleName(const char* name)
361     {
362         return m_pModuleName?(cv_stricmp(m_pModuleName,name)==0):0;
363     }
364     void SetNickName(const char* pStr)
365     {
366         if(m_pNickName)
367             free(m_pNickName);
368
369         m_pNickName = NULL;
370
371         if(pStr)
372             m_pNickName = strdup(pStr);
373     }
374     const char* GetNickName()
375     {
376         return m_pNickName ? m_pNickName : "unknown";
377     }
378     virtual void SaveState(CvFileStorage*){};
379     virtual void LoadState(CvFileStorage*, CvFileNode*){};
380
381     virtual void Release() = 0;
382 };/* CvVMModule */
383 void inline cvWriteStruct(CvFileStorage* fs, const char* name, void* addr, const char* desc, int num=1)
384 {
385     cvStartWriteStruct(fs,name,CV_NODE_SEQ|CV_NODE_FLOW);
386     cvWriteRawData(fs,addr,num,desc);
387     cvEndWriteStruct(fs);
388 }
389 void inline cvReadStructByName(CvFileStorage* fs, CvFileNode* node, const char* name, void* addr, const char* desc)
390 {
391     CvFileNode* pSeqNode = cvGetFileNodeByName(fs, node, name);
392     if(pSeqNode==NULL)
393     {
394         printf("WARNING!!! Can't read structure %s\n",name);
395     }
396     else
397     {
398         if(CV_NODE_IS_SEQ(pSeqNode->tag))
399         {
400             cvReadRawData( fs, pSeqNode, addr, desc );
401         }
402         else
403         {
404             printf("WARNING!!! Structure %s is not sequence and can not be read\n",name);
405         }
406     }
407 }
408
409
410 /* FOREGROUND DETECTOR INTERFACE */
411 class CV_EXPORTS CvFGDetector: public CvVSModule
412 {
413 public:
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;
420 };
421 inline void cvReleaseFGDetector(CvFGDetector** ppT )
422 {
423     ppT[0]->Release();
424     ppT[0] = 0;
425 }
426 /* FOREGROUND DETECTOR INTERFACE */
427
428 CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param);
429
430
431 /* BLOB STRUCTURE*/
432 struct CvBlob
433 {
434     float   x,y; /* blob position   */
435     float   w,h; /* blob sizes      */
436     int     ID;  /* blob ID         */
437 };
438
439 inline CvBlob cvBlob(float x,float y, float w, float h)
440 {
441     CvBlob B = {x,y,w,h,0};
442     return B;
443 }
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*/
456
457
458 /* simple BLOBLIST */
459 class CV_EXPORTS CvBlobSeq
460 {
461 public:
462     CvBlobSeq(int BlobSize = sizeof(CvBlob))
463     {
464         m_pMem = cvCreateMemStorage();
465         m_pSeq = cvCreateSeq(0,sizeof(CvSeq),BlobSize,m_pMem);
466         strcpy(m_pElemFormat,"ffffi");
467     }
468     virtual ~CvBlobSeq()
469     {
470         cvReleaseMemStorage(&m_pMem);
471     };
472     virtual CvBlob* GetBlob(int BlobIndex)
473     {
474         return (CvBlob*)cvGetSeqElem(m_pSeq,BlobIndex);
475     };
476     virtual CvBlob* GetBlobByID(int BlobID)
477     {
478         int i;
479         for(i=0; i<m_pSeq->total; ++i)
480             if(BlobID == CV_BLOB_ID(GetBlob(i)))
481                 return GetBlob(i);
482         return NULL;
483     };
484     virtual void DelBlob(int BlobIndex)
485     {
486         cvSeqRemove(m_pSeq,BlobIndex);
487     };
488     virtual void DelBlobByID(int BlobID)
489     {
490         int i;
491         for(i=0; i<m_pSeq->total; ++i)
492         {
493             if(BlobID == CV_BLOB_ID(GetBlob(i)))
494             {
495                 DelBlob(i);
496                 return;
497             }
498         }
499     };
500     virtual void Clear()
501     {
502         cvClearSeq(m_pSeq);
503     };
504     virtual void AddBlob(CvBlob* pB)
505     {
506         cvSeqPush(m_pSeq,pB);
507     };
508     virtual int GetBlobNum()
509     {
510         return m_pSeq->total;
511     };
512     virtual void Write(CvFileStorage* fs, const char* name)
513     {
514         const char*  attr[] = {"dt",m_pElemFormat,NULL};
515         if(fs)
516         {
517             cvWrite(fs,name,m_pSeq,cvAttrList(attr,NULL));
518         }
519     }
520     virtual void Load(CvFileStorage* fs, CvFileNode* node)
521     {
522         if(fs==NULL) return;
523         CvSeq* pSeq = (CvSeq*)cvRead(fs, node);
524         if(pSeq)
525         {
526             int i;
527             cvClearSeq(m_pSeq);
528             for(i=0;i<pSeq->total;++i)
529             {
530                 void* pB = cvGetSeqElem( pSeq, i );
531                 cvSeqPush( m_pSeq, pB );
532             }
533         }
534     }
535     void AddFormat(const char* str){strcat(m_pElemFormat,str);}
536 protected:
537     CvMemStorage*   m_pMem;
538     CvSeq*          m_pSeq;
539     char            m_pElemFormat[1024];
540 };
541 /* simple BLOBLIST */
542
543
544 /* simple TRACKLIST */
545 struct CvBlobTrack
546 {
547     int         TrackID;
548     int         StartFrame;
549     CvBlobSeq*  pBlobSeq;
550 };
551
552 class CV_EXPORTS CvBlobTrackSeq
553 {
554 public:
555     CvBlobTrackSeq(int TrackSize = sizeof(CvBlobTrack))
556     {
557         m_pMem = cvCreateMemStorage();
558         m_pSeq = cvCreateSeq(0,sizeof(CvSeq),TrackSize,m_pMem);
559     }
560     virtual ~CvBlobTrackSeq()
561     {
562         Clear();
563         cvReleaseMemStorage(&m_pMem);
564     };
565     virtual CvBlobTrack* GetBlobTrack(int TrackIndex)
566     {
567         return (CvBlobTrack*)cvGetSeqElem(m_pSeq,TrackIndex);
568     };
569     virtual CvBlobTrack* GetBlobTrackByID(int TrackID)
570     {
571         int i;
572         for(i=0; i<m_pSeq->total; ++i)
573         {
574             CvBlobTrack* pP = GetBlobTrack(i);
575             if(pP && pP->TrackID == TrackID)
576                 return pP;
577         }
578         return NULL;
579     };
580     virtual void DelBlobTrack(int TrackIndex)
581     {
582         CvBlobTrack* pP = GetBlobTrack(TrackIndex);
583         if(pP && pP->pBlobSeq) delete pP->pBlobSeq;
584         cvSeqRemove(m_pSeq,TrackIndex);
585     };
586     virtual void DelBlobTrackByID(int TrackID)
587     {
588         int i;
589         for(i=0; i<m_pSeq->total; ++i)
590         {
591             CvBlobTrack* pP = GetBlobTrack(i);
592             if(TrackID == pP->TrackID)
593             {
594                 DelBlobTrack(i);
595                 return;
596             }
597         }
598     };
599     virtual void Clear()
600     {
601         int i;
602         for(i=GetBlobTrackNum();i>0;i--)
603         {
604             DelBlobTrack(i-1);
605         }
606         cvClearSeq(m_pSeq);
607     };
608     virtual void AddBlobTrack(int TrackID, int StartFrame = 0)
609     {
610         CvBlobTrack N;
611         N.TrackID = TrackID;
612         N.StartFrame = StartFrame;
613         N.pBlobSeq = new CvBlobSeq;
614         cvSeqPush(m_pSeq,&N);
615     };
616     virtual int GetBlobTrackNum()
617     {
618         return m_pSeq->total;
619     };
620 protected:
621     CvMemStorage*   m_pMem;
622     CvSeq*          m_pSeq;
623 };
624
625 /* simple TRACKLIST */
626
627
628 /* BLOB DETECTOR INTERFACE */
629 class CV_EXPORTS CvBlobDetector: public CvVSModule
630 {
631 public:
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;
640 };
641 /* Release any blob detector: */
642 inline void cvReleaseBlobDetector(CvBlobDetector** ppBD)
643 {
644     ppBD[0]->Release();
645     ppBD[0] = NULL;
646 }
647 /* END BLOB DETECTOR INTERFACE */
648
649 /* Declarations of constructors of implemented modules: */
650 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorSimple();
651 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorCC();
652
653
654 struct CV_EXPORTS CvDetectedBlob : public CvBlob
655 {
656     float response;
657 };
658
659 CV_INLINE CvDetectedBlob cvDetectedBlob( float x, float y, float w, float h, int ID = 0, float response = 0.0F )
660 {
661     CvDetectedBlob b;
662     b.x = x; b.y = y; b.w = w; b.h = h; b.ID = ID; b.response = response;
663     return b;
664 }
665
666
667 class CV_EXPORTS CvObjectDetector
668 {
669 public:
670     CvObjectDetector( const char* /*detector_file_name*/ = 0 ) {};
671
672     ~CvObjectDetector() {};
673
674     /*
675      * Release the current detector and load new detector from file
676      * (if detector_file_name is not 0)
677      * Return true on success:
678      */
679     bool Load( const char* /*detector_file_name*/ = 0 ) { return false; }
680
681     /* Return min detector window size: */
682     CvSize GetMinWindowSize() const { return cvSize(0,0); }
683
684     /* Return max border: */
685     int GetMaxBorderSize() const { return 0; }
686
687     /*
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
690      */
691     void Detect( const CvArr* /*img*/, /* out */ CvBlobSeq* /*detected_blob_seq*/ = 0 ) {};
692
693 protected:
694     class CvObjectDetectorImpl* impl;
695 };
696
697
698 CV_INLINE CvRect cvRectIntersection( const CvRect r1, const CvRect r2 )
699 {
700     CvRect r = cvRect( MAX(r1.x, r2.x), MAX(r1.y, r2.y), 0, 0 );
701
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;
704
705     return r;
706 }
707
708
709 /*
710  * CvImageDrawer
711  *
712  * Draw on an image the specified ROIs from the source image and
713  * given blobs as ellipses or rectangles:
714  */
715
716 struct CvDrawShape
717 {
718     enum {RECT, ELLIPSE} shape;
719     CvScalar color;
720 };
721
722 /*extern const CvDrawShape icv_shape[] =
723 {
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) }
730 };*/
731
732 class CV_EXPORTS CvImageDrawer
733 {
734 public:
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; }
741 protected:
742     //static const int MAX_SHAPES = sizeof(icv_shape) / sizeof(icv_shape[0]);;
743
744     IplImage* m_image;
745     CvDrawShape m_shape[16];
746 };
747
748
749
750 /* Trajectory generation module: */
751 class CV_EXPORTS CvBlobTrackGen: public CvVSModule
752 {
753 public:
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;
759 };
760
761 inline void cvReleaseBlobTrackGen(CvBlobTrackGen** pBTGen)
762 {
763     if(*pBTGen)(*pBTGen)->Release();
764     *pBTGen = 0;
765 }
766
767 /* Declarations of constructors of implemented modules: */
768 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGen1();
769 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGenYML();
770
771
772
773 /* BLOB TRACKER INTERFACE */
774 class CV_EXPORTS CvBlobTracker: public CvVSModule
775 {
776 public:
777     CvBlobTracker(){SetTypeName("BlobTracker");};
778
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;
785
786     /* Return number of currently tracked blobs: */
787     virtual int     GetBlobNum() = 0;
788
789     /* Return pointer to specified by index blob: */
790     virtual CvBlob* GetBlob(int BlobIndex) = 0;
791
792     /* Delete blob by its index: */
793     virtual void    DelBlob(int BlobIndex) = 0;
794
795     /* Process current image and track all existed blobs: */
796     virtual void    Process(IplImage* pImg, IplImage* pImgFG = NULL) = 0;
797
798     /* Release blob tracker: */
799     virtual void    Release() = 0;
800
801
802     /* Process one blob (for multi hypothesis tracing): */
803     virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
804     {
805         CvBlob* pB;
806         int ID = 0;
807         assert(pBlob);
808         //pBlob->ID;
809         pB = GetBlob(BlobIndex);
810         if(pB)
811             pBlob[0] = pB[0];
812         pBlob->ID = ID;
813     };
814
815     /* Get confidence/wieght/probability (0-1) for blob: */
816     virtual double  GetConfidence(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
817     {
818         return 1;
819     };
820
821     virtual double GetConfidenceList(CvBlobSeq* pBlobList, IplImage* pImg, IplImage* pImgFG = NULL)
822     {
823         int     b,bN = pBlobList->GetBlobNum();
824         double  W = 1;
825         for(b=0;b<bN;++b)
826         {
827             CvBlob* pB = pBlobList->GetBlob(b);
828             int     BI = GetBlobIndexByID(pB->ID);
829             W *= GetConfidence(BI,pB,pImg,pImgFG);
830         }
831         return W;
832     };
833
834     virtual void UpdateBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
835
836     /* Update all blob models: */
837     virtual void Update(IplImage* pImg, IplImage* pImgFG = NULL)
838     {
839         int i;
840         for(i=GetBlobNum();i>0;i--)
841         {
842             CvBlob* pB=GetBlob(i-1);
843             UpdateBlob(i-1, pB, pImg, pImgFG);
844         }
845
846     };
847
848     /* Return pointer to blob by its unique ID: */
849     virtual int     GetBlobIndexByID(int BlobID)
850     {
851         int i;
852         for(i=GetBlobNum();i>0;i--)
853         {
854             CvBlob* pB=GetBlob(i-1);
855             if(CV_BLOB_ID(pB) == BlobID) return i-1;
856         }
857         return -1;
858     };
859
860     /* Return pointer to blob by its unique ID: */
861     virtual CvBlob* GetBlobByID(int BlobID){return GetBlob(GetBlobIndexByID(BlobID));};
862
863     /* Delete blob by its ID: */
864     virtual void    DelBlobByID(int BlobID){DelBlob(GetBlobIndexByID(BlobID));};
865
866     /* Set new parameters for specified (by index) blob: */
867     virtual void    SetBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
868
869     /* Set new parameters for specified (by ID) blob: */
870     virtual void    SetBlobByID(int BlobID, CvBlob* pBlob)
871     {
872         SetBlob(GetBlobIndexByID(BlobID),pBlob);
873     };
874
875     /*  ===============  MULTI HYPOTHESIS INTERFACE ==================  */
876
877     /* Return number of position hyposetis of currently tracked blob: */
878     virtual int     GetBlobHypNum(int /*BlobIdx*/){return 1;};
879
880     /* Return pointer to specified blob hypothesis by index blob: */
881     virtual CvBlob* GetBlobHyp(int BlobIndex, int /*hypothesis*/){return GetBlob(BlobIndex);};
882
883     /* Set new parameters for specified (by index) blob hyp
884      * (can be called several times for each hyp ):
885      */
886     virtual void    SetBlobHyp(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
887 };
888 inline void cvReleaseBlobTracker(CvBlobTracker**ppT )
889 {
890     ppT[0]->Release();
891     ppT[0] = 0;
892 }
893 /* BLOB TRACKER INTERFACE */
894
895 /*BLOB TRACKER ONE INTERFACE */
896 class CV_EXPORTS CvBlobTrackerOne:public CvVSModule
897 {
898 public:
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;
902
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)
909     {
910         return 1;
911     };
912 };
913 inline void cvReleaseBlobTrackerOne(CvBlobTrackerOne **ppT )
914 {
915     ppT[0]->Release();
916     ppT[0] = 0;
917 }
918 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerList(CvBlobTrackerOne* (*create)());
919 /*BLOB TRACKER ONE INTERFACE */
920
921 /* Declarations of constructors of implemented modules: */
922
923 /* Some declarations for specific MeanShift tracker: */
924 #define PROFILE_EPANECHNIKOV    0
925 #define PROFILE_DOG             1
926 struct CvBlobTrackerParamMS
927 {
928     int     noOfSigBits;
929     int     appearance_profile;
930     int     meanshift_profile;
931     float   sigma;
932 };
933
934 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1(CvBlobTrackerParamMS* param);
935 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS2(CvBlobTrackerParamMS* param);
936 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1ByList();
937
938 /* Some declarations for specific Likelihood tracker: */
939 struct CvBlobTrackerParamLH
940 {
941     int     HistType; /* see Prob.h */
942     int     ScaleAfter;
943 };
944
945 /* Without scale optimization: */
946 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHR(CvBlobTrackerParamLH* /*param*/ = NULL);
947
948 /* With scale optimization: */
949 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHRS(CvBlobTrackerParamLH* /*param*/ = NULL);
950
951 /* Simple blob tracker based on connected component tracking: */
952 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCC();
953
954 /* Connected component tracking and mean-shift particle filter collion-resolver: */
955 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCCMSPF();
956
957 /* Blob tracker that integrates meanshift and connected components: */
958 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFG();
959 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFGS();
960
961 /* Meanshift without connected-components */
962 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS();
963
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();
970
971 /* =========== tracker integrators trackers =============*/
972
973 /* Integrator based on Particle Filtering method: */
974 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPF();
975
976 /* Rule based integrator: */
977 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIRB();
978
979 /* Integrator based on data fusion using particle filtering: */
980 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPFDF();
981
982
983
984
985 /* Trajectory postprocessing module: */
986 class CV_EXPORTS CvBlobTrackPostProc: public CvVSModule
987 {
988 public:
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;
995
996     /* Additional functionality: */
997     virtual CvBlob* GetBlobByID(int BlobID)
998     {
999         int i;
1000         for(i=GetBlobNum();i>0;i--)
1001         {
1002             CvBlob* pB=GetBlob(i-1);
1003             if(pB->ID==BlobID) return pB;
1004         }
1005         return NULL;
1006     };
1007 };
1008
1009 inline void cvReleaseBlobTrackPostProc(CvBlobTrackPostProc** pBTPP)
1010 {
1011     if(pBTPP == NULL) return;
1012     if(*pBTPP)(*pBTPP)->Release();
1013     *pBTPP = 0;
1014 }
1015
1016 /* Trajectory generation module: */
1017 class CV_EXPORTS CvBlobTrackPostProcOne: public CvVSModule
1018 {
1019 public:
1020         CvBlobTrackPostProcOne(){SetTypeName("BlobTrackPostOne");};
1021     virtual CvBlob* Process(CvBlob* pBlob) = 0;
1022     virtual void    Release() = 0;
1023 };
1024
1025 /* Create blob tracking post processing module based on simle module: */
1026 CV_EXPORTS CvBlobTrackPostProc* cvCreateBlobTrackPostProcList(CvBlobTrackPostProcOne* (*create)());
1027
1028
1029 /* Declarations of constructors of implemented modules: */
1030 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcKalman();
1031 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverRect();
1032 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverExp();
1033
1034
1035 /* PREDICTORS */
1036 /* blob PREDICTOR */
1037 class CvBlobTrackPredictor: public CvVSModule
1038 {
1039 public:
1040         CvBlobTrackPredictor(){SetTypeName("BlobTrackPredictor");};
1041     virtual CvBlob* Predict() = 0;
1042     virtual void    Update(CvBlob* pBlob) = 0;
1043     virtual void    Release() = 0;
1044 };
1045 CV_EXPORTS CvBlobTrackPredictor* cvCreateModuleBlobTrackPredictKalman();
1046
1047
1048
1049 /* Trajectory analyser module: */
1050 class CV_EXPORTS CvBlobTrackAnalysis: public CvVSModule
1051 {
1052 public:
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;
1062 };
1063
1064
1065 inline void cvReleaseBlobTrackAnalysis(CvBlobTrackAnalysis** pBTPP)
1066 {
1067     if(pBTPP == NULL) return;
1068     if(*pBTPP)(*pBTPP)->Release();
1069     *pBTPP = 0;
1070 }
1071
1072 /* Feature-vector generation module: */
1073 class CV_EXPORTS CvBlobTrackFVGen : public CvVSModule
1074 {
1075 public:
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 */
1086 };
1087
1088
1089 /* Trajectory Analyser module: */
1090 class CV_EXPORTS CvBlobTrackAnalysisOne
1091 {
1092 public:
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;
1098 };
1099
1100 /* Create blob tracking post processing module based on simle module: */
1101 CV_EXPORTS CvBlobTrackAnalysis* cvCreateBlobTrackAnalysisList(CvBlobTrackAnalysisOne* (*create)());
1102
1103 /* Declarations of constructors of implemented modules: */
1104
1105 /* Based on histogram analysis of 2D FV (x,y): */
1106 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistP();
1107
1108 /* Based on histogram analysis of 4D FV (x,y,vx,vy): */
1109 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPV();
1110
1111 /* Based on histogram analysis of 5D FV (x,y,vx,vy,state): */
1112 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPVS();
1113
1114 /* Based on histogram analysis of 4D FV (startpos,stoppos): */
1115 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistSS();
1116
1117
1118
1119 /* Based on SVM classifier analysis of 2D FV (x,y): */
1120 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP();
1121
1122 /* Based on SVM classifier analysis of 4D FV (x,y,vx,vy): */
1123 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPV();
1124
1125 /* Based on SVM classifier analysis of 5D FV (x,y,vx,vy,state): */
1126 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS();
1127
1128 /* Based on SVM classifier analysis of 4D FV (startpos,stoppos): */
1129 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS();
1130
1131 /* Track analysis based on distance between tracks: */
1132 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisTrackDist();
1133
1134 /* Analyzer based on reation Road and height map: */
1135 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysis3DRoadMap();
1136
1137 /* Analyzer that makes OR decision using set of analyzers: */
1138 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR();
1139
1140 /* Estimator of human height: */
1141 class CV_EXPORTS CvBlobTrackAnalysisHeight: public CvBlobTrackAnalysis
1142 {
1143 public:
1144     virtual double  GetHeight(CvBlob* pB) = 0;
1145 };
1146 //CV_EXPORTS CvBlobTrackAnalysisHeight* cvCreateModuleBlobTrackAnalysisHeightScale();
1147
1148
1149
1150 /* AUTO BLOB TRACKER INTERFACE -- pipeline of 3 modules: */
1151 class CV_EXPORTS CvBlobTrackerAuto: public CvVSModule
1152 {
1153 public:
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;
1165 };
1166 inline void cvReleaseBlobTrackerAuto(CvBlobTrackerAuto** ppT)
1167 {
1168     ppT[0]->Release();
1169     ppT[0] = 0;
1170 }
1171 /* END AUTO BLOB TRACKER INTERFACE */
1172
1173
1174 /* Constructor functions and data for specific BlobTRackerAuto modules: */
1175
1176 /* Parameters of blobtracker auto ver1: */
1177 struct CvBlobTrackerAutoParam1
1178 {
1179     int                     FGTrainFrames; /* Number of frames needed for FG (foreground) detector to train.        */
1180
1181     CvFGDetector*           pFG;           /* FGDetector module. If this field is NULL the Process FG mask is used. */
1182
1183     CvBlobDetector*         pBD;           /* Selected blob detector module.                                        */
1184                                            /* If this field is NULL default blobdetector module will be created.    */
1185
1186     CvBlobTracker*          pBT;           /* Selected blob tracking module.                                        */
1187                                            /* If this field is NULL default blobtracker module will be created.     */
1188
1189     CvBlobTrackGen*         pBTGen;        /* Selected blob trajectory generator.                                   */
1190                                            /* If this field is NULL no generator is used.                           */
1191
1192     CvBlobTrackPostProc*    pBTPP;         /* Selected blob trajectory postprocessing module.                       */
1193                                            /* If this field is NULL no postprocessing is done.                      */
1194
1195     int                     UsePPData;
1196
1197     CvBlobTrackAnalysis*    pBTA;          /* Selected blob trajectory analysis module.                             */
1198                                            /* If this field is NULL no track analysis is done.                      */
1199 };
1200
1201 /* Create blob tracker auto ver1: */
1202 CV_EXPORTS CvBlobTrackerAuto* cvCreateBlobTrackerAuto1(CvBlobTrackerAutoParam1* param = NULL);
1203
1204 /* Simple loader for many auto trackers by its type : */
1205 inline CvBlobTrackerAuto* cvCreateBlobTrackerAuto(int type, void* param)
1206 {
1207     if(type == 0) return cvCreateBlobTrackerAuto1((CvBlobTrackerAutoParam1*)param);
1208     return 0;
1209 }
1210
1211
1212
1213 struct CvTracksTimePos
1214 {
1215     int len1,len2;
1216     int beg1,beg2;
1217     int end1,end2;
1218     int comLen; //common length for two tracks
1219     int shift1,shift2;
1220 };
1221
1222 /*CV_EXPORTS int cvCompareTracks( CvBlobTrackSeq *groundTruth,
1223                    CvBlobTrackSeq *result,
1224                    FILE *file);*/
1225
1226
1227 /* Constructor functions:  */
1228
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);
1232
1233
1234 /* HIST API */
1235 class CV_EXPORTS CvProb
1236 {
1237 public:
1238     virtual ~CvProb() {};
1239
1240     /* Calculate probability value: */
1241     virtual double Value(int* /*comp*/, int /*x*/ = 0, int /*y*/ = 0){return -1;};
1242
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;
1249 };
1250 inline void cvReleaseProb(CvProb** ppProb){ppProb[0]->Release();ppProb[0]=NULL;}
1251 /* HIST API */
1252
1253 /* Some Prob: */
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);
1258
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)
1264 {
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);
1269     return NULL;
1270 }
1271
1272
1273
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
1280
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);
1292
1293 /*================== GENERATOR OF TEST VIDEO SEQUENCE ===================== */
1294 typedef void CvTestSeq;
1295
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);
1301
1302 /* Generate next frame from test video seq and return pointer to it: */
1303 CV_EXPORTS IplImage* cvTestSeqQueryFrame(CvTestSeq* pTestSeq);
1304
1305 /* Return pointer to current foreground mask: */
1306 CV_EXPORTS IplImage* cvTestSeqGetFGMask(CvTestSeq* pTestSeq);
1307
1308 /* Return pointer to current image: */
1309 CV_EXPORTS IplImage* cvTestSeqGetImage(CvTestSeq* pTestSeq);
1310
1311 /* Return frame size of result test video: */
1312 CV_EXPORTS CvSize cvTestSeqGetImageSize(CvTestSeq* pTestSeq);
1313
1314 /* Return number of frames result test video: */
1315 CV_EXPORTS int cvTestSeqFrameNum(CvTestSeq* pTestSeq);
1316
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:
1320  */
1321 CV_EXPORTS int cvTestSeqGetObjectNum(CvTestSeq* pTestSeq);
1322
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);
1327
1328 /* Add noise to final image: */
1329 CV_EXPORTS void cvTestSeqAddNoise(CvTestSeq* pTestSeq, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
1330
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);
1334
1335 #endif
1336
1337 /* End of file. */