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