00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // Intel License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000, Intel Corporation, all rights reserved. 00014 // Third party copyrights are property of their respective owners. 00015 // 00016 // Redistribution and use in source and binary forms, with or without modification, 00017 // are permitted provided that the following conditions are met: 00018 // 00019 // * Redistribution's of source code must retain the above copyright notice, 00020 // this list of conditions and the following disclaimer. 00021 // 00022 // * Redistribution's in binary form must reproduce the above copyright notice, 00023 // this list of conditions and the following disclaimer in the documentation 00024 // and/or other materials provided with the distribution. 00025 // 00026 // * The name of Intel Corporation may not be used to endorse or promote products 00027 // derived from this software without specific prior written permission. 00028 // 00029 // This software is provided by the copyright holders and contributors "as is" and 00030 // any express or implied warranties, including, but not limited to, the implied 00031 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00032 // In no event shall the Intel Corporation or contributors be liable for any direct, 00033 // indirect, incidental, special, exemplary, or consequential damages 00034 // (including, but not limited to, procurement of substitute goods or services; 00035 // loss of use, data, or profits; or business interruption) however caused 00036 // and on any theory of liability, whether in contract, strict liability, 00037 // or tort (including negligence or otherwise) arising in any way out of 00038 // the use of this software, even if advised of the possibility of such damage. 00039 // 00040 //M*/ 00041 00042 00043 #ifndef __OPENCV_VIDEOSURVEILLANCE_H__ 00044 #define __OPENCV_VIDEOSURVEILLANCE_H__ 00045 00046 /* Turn off the functionality until cvaux/src/Makefile.am gets updated: */ 00047 //#if _MSC_VER >= 1200 00048 00049 #include <stdio.h> 00050 00051 #if _MSC_VER >= 1200 || defined __BORLANDC__ 00052 #define cv_stricmp stricmp 00053 #define cv_strnicmp strnicmp 00054 #if defined WINCE 00055 #define strdup _strdup 00056 #define stricmp _stricmp 00057 #endif 00058 #elif defined __GNUC__ 00059 #define cv_stricmp strcasecmp 00060 #define cv_strnicmp strncasecmp 00061 #else 00062 #error Do not know how to make case-insensitive string comparison on this platform 00063 #endif 00064 00065 //struct DefParam; 00066 struct CvDefParam 00067 { 00068 struct CvDefParam* next; 00069 char* pName; 00070 char* pComment; 00071 double* pDouble; 00072 double Double; 00073 float* pFloat; 00074 float Float; 00075 int* pInt; 00076 int Int; 00077 char** pStr; 00078 char* Str; 00079 }; 00080 00081 class CV_EXPORTS CvVSModule 00082 { 00083 private: /* Internal data: */ 00084 CvDefParam* m_pParamList; 00085 char* m_pModuleTypeName; 00086 char* m_pModuleName; 00087 char* m_pNickName; 00088 protected: 00089 int m_Wnd; 00090 public: /* Constructor and destructor: */ 00091 CvVSModule() 00092 { 00093 m_pNickName = NULL; 00094 m_pParamList = NULL; 00095 m_pModuleTypeName = NULL; 00096 m_pModuleName = NULL; 00097 m_Wnd = 0; 00098 AddParam("DebugWnd",&m_Wnd); 00099 } 00100 virtual ~CvVSModule() 00101 { 00102 CvDefParam* p = m_pParamList; 00103 for(;p;) 00104 { 00105 CvDefParam* pf = p; 00106 p=p->next; 00107 FreeParam(&pf); 00108 } 00109 m_pParamList=NULL; 00110 if(m_pModuleTypeName)free(m_pModuleTypeName); 00111 if(m_pModuleName)free(m_pModuleName); 00112 } 00113 private: /* Internal functions: */ 00114 void FreeParam(CvDefParam** pp) 00115 { 00116 CvDefParam* p = pp[0]; 00117 if(p->Str)free(p->Str); 00118 if(p->pName)free(p->pName); 00119 if(p->pComment)free(p->pComment); 00120 cvFree(pp); 00121 } 00122 CvDefParam* NewParam(const char* name) 00123 { 00124 CvDefParam* pNew = (CvDefParam*)cvAlloc(sizeof(CvDefParam)); 00125 memset(pNew,0,sizeof(CvDefParam)); 00126 pNew->pName = strdup(name); 00127 if(m_pParamList==NULL) 00128 { 00129 m_pParamList = pNew; 00130 } 00131 else 00132 { 00133 CvDefParam* p = m_pParamList; 00134 for(;p->next;p=p->next) ; 00135 p->next = pNew; 00136 } 00137 return pNew; 00138 }; 00139 00140 CvDefParam* GetParamPtr(int index) 00141 { 00142 CvDefParam* p = m_pParamList; 00143 for(;index>0 && p;index--,p=p->next) ; 00144 return p; 00145 } 00146 CvDefParam* GetParamPtr(const char* name) 00147 { 00148 CvDefParam* p = m_pParamList; 00149 for(;p;p=p->next) 00150 { 00151 if(cv_stricmp(p->pName,name)==0) break; 00152 } 00153 return p; 00154 } 00155 protected: /* INTERNAL INTERFACE */ 00156 int IsParam(const char* name) 00157 { 00158 return GetParamPtr(name)?1:0; 00159 }; 00160 void AddParam(const char* name, double* pAddr) 00161 { 00162 NewParam(name)->pDouble = pAddr; 00163 }; 00164 void AddParam(const char* name, float* pAddr) 00165 { 00166 NewParam(name)->pFloat=pAddr; 00167 }; 00168 void AddParam(const char* name, int* pAddr) 00169 { 00170 NewParam(name)->pInt=pAddr; 00171 }; 00172 void AddParam(const char* name, const char** pAddr) 00173 { 00174 CvDefParam* pP = NewParam(name); 00175 const char* p = pAddr?pAddr[0]:NULL; 00176 pP->pStr = pAddr?(char**)pAddr:&(pP->Str); 00177 if(p) 00178 { 00179 pP->Str = strdup(p); 00180 pP->pStr[0] = pP->Str; 00181 } 00182 }; 00183 void AddParam(const char* name) 00184 { 00185 CvDefParam* p = NewParam(name); 00186 p->pDouble = &p->Double; 00187 }; 00188 void CommentParam(const char* name, const char* pComment) 00189 { 00190 CvDefParam* p = GetParamPtr(name); 00191 if(p)p->pComment = pComment ? strdup(pComment) : 0; 00192 }; 00193 void SetTypeName(const char* name){m_pModuleTypeName = strdup(name);} 00194 void SetModuleName(const char* name){m_pModuleName = strdup(name);} 00195 void DelParam(const char* name) 00196 { 00197 CvDefParam* p = m_pParamList; 00198 CvDefParam* pPrev = NULL; 00199 for(;p;p=p->next) 00200 { 00201 if(cv_stricmp(p->pName,name)==0) break; 00202 pPrev = p; 00203 } 00204 if(p) 00205 { 00206 if(pPrev) 00207 { 00208 pPrev->next = p->next; 00209 } 00210 else 00211 { 00212 m_pParamList = p->next; 00213 } 00214 FreeParam(&p); 00215 } 00216 }/* DelParam */ 00217 00218 public: /* EXTERNAL INTERFACE */ 00219 const char* GetParamName(int index) 00220 { 00221 CvDefParam* p = GetParamPtr(index); 00222 return p?p->pName:NULL; 00223 } 00224 const char* GetParamComment(const char* name) 00225 { 00226 CvDefParam* p = GetParamPtr(name); 00227 if(p && p->pComment) return p->pComment; 00228 return NULL; 00229 } 00230 double GetParam(const char* name) 00231 { 00232 CvDefParam* p = GetParamPtr(name); 00233 if(p) 00234 { 00235 if(p->pDouble) return p->pDouble[0]; 00236 if(p->pFloat) return p->pFloat[0]; 00237 if(p->pInt) return p->pInt[0]; 00238 } 00239 return 0; 00240 }; 00241 00242 const char* GetParamStr(const char* name) 00243 { 00244 CvDefParam* p = GetParamPtr(name); 00245 return p?p->Str:NULL; 00246 } 00247 void SetParam(const char* name, double val) 00248 { 00249 CvDefParam* p = m_pParamList; 00250 for(;p;p=p->next) 00251 { 00252 if(cv_stricmp(p->pName,name) != 0) continue; 00253 if(p->pDouble)p->pDouble[0] = val; 00254 if(p->pFloat)p->pFloat[0] = (float)val; 00255 if(p->pInt)p->pInt[0] = cvRound(val); 00256 } 00257 } 00258 void SetParamStr(const char* name, const char* str) 00259 { 00260 CvDefParam* p = m_pParamList; 00261 for(; p; p=p->next) 00262 { 00263 if(cv_stricmp(p->pName,name) != 0) continue; 00264 if(p->pStr) 00265 { 00266 if(p->Str)free(p->Str); 00267 p->Str = NULL; 00268 if(str)p->Str = strdup(str); 00269 p->pStr[0] = p->Str; 00270 } 00271 } 00272 /* Convert to double and set: */ 00273 if(str) SetParam(name,atof(str)); 00274 } 00275 void TransferParamsFromChild(CvVSModule* pM, const char* prefix = NULL) 00276 { 00277 char tmp[1024]; 00278 const char* FN = NULL; 00279 int i; 00280 for(i=0;;++i) 00281 { 00282 const char* N = pM->GetParamName(i); 00283 if(N == NULL) break; 00284 FN = N; 00285 if(prefix) 00286 { 00287 strcpy(tmp,prefix); 00288 strcat(tmp,"_"); 00289 FN = strcat(tmp,N); 00290 } 00291 00292 if(!IsParam(FN)) 00293 { 00294 if(pM->GetParamStr(N)) 00295 { 00296 AddParam(FN,(const char**)NULL); 00297 } 00298 else 00299 { 00300 AddParam(FN); 00301 } 00302 } 00303 if(pM->GetParamStr(N)) 00304 { 00305 const char* val = pM->GetParamStr(N); 00306 SetParamStr(FN,val); 00307 } 00308 else 00309 { 00310 double val = pM->GetParam(N); 00311 SetParam(FN,val); 00312 } 00313 CommentParam(FN, pM->GetParamComment(N)); 00314 }/* transfer next param */ 00315 }/* Transfer params */ 00316 00317 void TransferParamsToChild(CvVSModule* pM, char* prefix = NULL) 00318 { 00319 char tmp[1024]; 00320 int i; 00321 for(i=0;;++i) 00322 { 00323 const char* N = pM->GetParamName(i); 00324 if(N == NULL) break; 00325 if(prefix) 00326 { 00327 strcpy(tmp,prefix); 00328 strcat(tmp,"_"); 00329 strcat(tmp,N); 00330 } 00331 else 00332 { 00333 strcpy(tmp,N); 00334 } 00335 00336 if(IsParam(tmp)) 00337 { 00338 if(GetParamStr(tmp)) 00339 pM->SetParamStr(N,GetParamStr(tmp)); 00340 else 00341 pM->SetParam(N,GetParam(tmp)); 00342 } 00343 }/* Transfer next parameter */ 00344 pM->ParamUpdate(); 00345 }/* Transfer params */ 00346 00347 virtual void ParamUpdate(){}; 00348 const char* GetTypeName() 00349 { 00350 return m_pModuleTypeName; 00351 } 00352 int IsModuleTypeName(const char* name) 00353 { 00354 return m_pModuleTypeName?(cv_stricmp(m_pModuleTypeName,name)==0):0; 00355 } 00356 char* GetModuleName() 00357 { 00358 return m_pModuleName; 00359 } 00360 int IsModuleName(const char* name) 00361 { 00362 return m_pModuleName?(cv_stricmp(m_pModuleName,name)==0):0; 00363 } 00364 void SetNickName(const char* pStr) 00365 { 00366 if(m_pNickName) 00367 free(m_pNickName); 00368 00369 m_pNickName = NULL; 00370 00371 if(pStr) 00372 m_pNickName = strdup(pStr); 00373 } 00374 const char* GetNickName() 00375 { 00376 return m_pNickName ? m_pNickName : "unknown"; 00377 } 00378 virtual void SaveState(CvFileStorage*){}; 00379 virtual void LoadState(CvFileStorage*, CvFileNode*){}; 00380 00381 virtual void Release() = 0; 00382 };/* CvVMModule */ 00383 void inline cvWriteStruct(CvFileStorage* fs, const char* name, void* addr, const char* desc, int num=1) 00384 { 00385 cvStartWriteStruct(fs,name,CV_NODE_SEQ|CV_NODE_FLOW); 00386 cvWriteRawData(fs,addr,num,desc); 00387 cvEndWriteStruct(fs); 00388 } 00389 void inline cvReadStructByName(CvFileStorage* fs, CvFileNode* node, const char* name, void* addr, const char* desc) 00390 { 00391 CvFileNode* pSeqNode = cvGetFileNodeByName(fs, node, name); 00392 if(pSeqNode==NULL) 00393 { 00394 printf("WARNING!!! Can't read structure %s\n",name); 00395 } 00396 else 00397 { 00398 if(CV_NODE_IS_SEQ(pSeqNode->tag)) 00399 { 00400 cvReadRawData( fs, pSeqNode, addr, desc ); 00401 } 00402 else 00403 { 00404 printf("WARNING!!! Structure %s is not sequence and can not be read\n",name); 00405 } 00406 } 00407 } 00408 00409 00410 /* FOREGROUND DETECTOR INTERFACE */ 00411 class CV_EXPORTS CvFGDetector: public CvVSModule 00412 { 00413 public: 00414 CvFGDetector(){SetTypeName("FGDetector");}; 00415 virtual IplImage* GetMask() = 0; 00416 /* Process current image: */ 00417 virtual void Process(IplImage* pImg) = 0; 00418 /* Release foreground detector: */ 00419 virtual void Release() = 0; 00420 }; 00421 inline void cvReleaseFGDetector(CvFGDetector** ppT ) 00422 { 00423 ppT[0]->Release(); 00424 ppT[0] = 0; 00425 } 00426 /* FOREGROUND DETECTOR INTERFACE */ 00427 00428 CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param); 00429 00430 00431 /* BLOB STRUCTURE*/ 00432 struct CvBlob 00433 { 00434 float x,y; /* blob position */ 00435 float w,h; /* blob sizes */ 00436 int ID; /* blob ID */ 00437 }; 00438 00439 inline CvBlob cvBlob(float x,float y, float w, float h) 00440 { 00441 CvBlob B = {x,y,w,h,0}; 00442 return B; 00443 } 00444 #define CV_BLOB_MINW 5 00445 #define CV_BLOB_MINH 5 00446 #define CV_BLOB_ID(pB) (((CvBlob*)(pB))->ID) 00447 #define CV_BLOB_CENTER(pB) cvPoint2D32f(((CvBlob*)(pB))->x,((CvBlob*)(pB))->y) 00448 #define CV_BLOB_X(pB) (((CvBlob*)(pB))->x) 00449 #define CV_BLOB_Y(pB) (((CvBlob*)(pB))->y) 00450 #define CV_BLOB_WX(pB) (((CvBlob*)(pB))->w) 00451 #define CV_BLOB_WY(pB) (((CvBlob*)(pB))->h) 00452 #define CV_BLOB_RX(pB) (0.5f*CV_BLOB_WX(pB)) 00453 #define CV_BLOB_RY(pB) (0.5f*CV_BLOB_WY(pB)) 00454 #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))) 00455 /* END BLOB STRUCTURE*/ 00456 00457 00458 /* simple BLOBLIST */ 00459 class CV_EXPORTS CvBlobSeq 00460 { 00461 public: 00462 CvBlobSeq(int BlobSize = sizeof(CvBlob)) 00463 { 00464 m_pMem = cvCreateMemStorage(); 00465 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),BlobSize,m_pMem); 00466 strcpy(m_pElemFormat,"ffffi"); 00467 } 00468 virtual ~CvBlobSeq() 00469 { 00470 cvReleaseMemStorage(&m_pMem); 00471 }; 00472 virtual CvBlob* GetBlob(int BlobIndex) 00473 { 00474 return (CvBlob*)cvGetSeqElem(m_pSeq,BlobIndex); 00475 }; 00476 virtual CvBlob* GetBlobByID(int BlobID) 00477 { 00478 int i; 00479 for(i=0; i<m_pSeq->total; ++i) 00480 if(BlobID == CV_BLOB_ID(GetBlob(i))) 00481 return GetBlob(i); 00482 return NULL; 00483 }; 00484 virtual void DelBlob(int BlobIndex) 00485 { 00486 cvSeqRemove(m_pSeq,BlobIndex); 00487 }; 00488 virtual void DelBlobByID(int BlobID) 00489 { 00490 int i; 00491 for(i=0; i<m_pSeq->total; ++i) 00492 { 00493 if(BlobID == CV_BLOB_ID(GetBlob(i))) 00494 { 00495 DelBlob(i); 00496 return; 00497 } 00498 } 00499 }; 00500 virtual void Clear() 00501 { 00502 cvClearSeq(m_pSeq); 00503 }; 00504 virtual void AddBlob(CvBlob* pB) 00505 { 00506 cvSeqPush(m_pSeq,pB); 00507 }; 00508 virtual int GetBlobNum() 00509 { 00510 return m_pSeq->total; 00511 }; 00512 virtual void Write(CvFileStorage* fs, const char* name) 00513 { 00514 const char* attr[] = {"dt",m_pElemFormat,NULL}; 00515 if(fs) 00516 { 00517 cvWrite(fs,name,m_pSeq,cvAttrList(attr,NULL)); 00518 } 00519 } 00520 virtual void Load(CvFileStorage* fs, CvFileNode* node) 00521 { 00522 if(fs==NULL) return; 00523 CvSeq* pSeq = (CvSeq*)cvRead(fs, node); 00524 if(pSeq) 00525 { 00526 int i; 00527 cvClearSeq(m_pSeq); 00528 for(i=0;i<pSeq->total;++i) 00529 { 00530 void* pB = cvGetSeqElem( pSeq, i ); 00531 cvSeqPush( m_pSeq, pB ); 00532 } 00533 } 00534 } 00535 void AddFormat(const char* str){strcat(m_pElemFormat,str);} 00536 protected: 00537 CvMemStorage* m_pMem; 00538 CvSeq* m_pSeq; 00539 char m_pElemFormat[1024]; 00540 }; 00541 /* simple BLOBLIST */ 00542 00543 00544 /* simple TRACKLIST */ 00545 struct CvBlobTrack 00546 { 00547 int TrackID; 00548 int StartFrame; 00549 CvBlobSeq* pBlobSeq; 00550 }; 00551 00552 class CV_EXPORTS CvBlobTrackSeq 00553 { 00554 public: 00555 CvBlobTrackSeq(int TrackSize = sizeof(CvBlobTrack)) 00556 { 00557 m_pMem = cvCreateMemStorage(); 00558 m_pSeq = cvCreateSeq(0,sizeof(CvSeq),TrackSize,m_pMem); 00559 } 00560 virtual ~CvBlobTrackSeq() 00561 { 00562 Clear(); 00563 cvReleaseMemStorage(&m_pMem); 00564 }; 00565 virtual CvBlobTrack* GetBlobTrack(int TrackIndex) 00566 { 00567 return (CvBlobTrack*)cvGetSeqElem(m_pSeq,TrackIndex); 00568 }; 00569 virtual CvBlobTrack* GetBlobTrackByID(int TrackID) 00570 { 00571 int i; 00572 for(i=0; i<m_pSeq->total; ++i) 00573 { 00574 CvBlobTrack* pP = GetBlobTrack(i); 00575 if(pP && pP->TrackID == TrackID) 00576 return pP; 00577 } 00578 return NULL; 00579 }; 00580 virtual void DelBlobTrack(int TrackIndex) 00581 { 00582 CvBlobTrack* pP = GetBlobTrack(TrackIndex); 00583 if(pP && pP->pBlobSeq) delete pP->pBlobSeq; 00584 cvSeqRemove(m_pSeq,TrackIndex); 00585 }; 00586 virtual void DelBlobTrackByID(int TrackID) 00587 { 00588 int i; 00589 for(i=0; i<m_pSeq->total; ++i) 00590 { 00591 CvBlobTrack* pP = GetBlobTrack(i); 00592 if(TrackID == pP->TrackID) 00593 { 00594 DelBlobTrack(i); 00595 return; 00596 } 00597 } 00598 }; 00599 virtual void Clear() 00600 { 00601 int i; 00602 for(i=GetBlobTrackNum();i>0;i--) 00603 { 00604 DelBlobTrack(i-1); 00605 } 00606 cvClearSeq(m_pSeq); 00607 }; 00608 virtual void AddBlobTrack(int TrackID, int StartFrame = 0) 00609 { 00610 CvBlobTrack N; 00611 N.TrackID = TrackID; 00612 N.StartFrame = StartFrame; 00613 N.pBlobSeq = new CvBlobSeq; 00614 cvSeqPush(m_pSeq,&N); 00615 }; 00616 virtual int GetBlobTrackNum() 00617 { 00618 return m_pSeq->total; 00619 }; 00620 protected: 00621 CvMemStorage* m_pMem; 00622 CvSeq* m_pSeq; 00623 }; 00624 00625 /* simple TRACKLIST */ 00626 00627 00628 /* BLOB DETECTOR INTERFACE */ 00629 class CV_EXPORTS CvBlobDetector: public CvVSModule 00630 { 00631 public: 00632 CvBlobDetector(){SetTypeName("BlobDetector");}; 00633 /* Try to detect new blob entrance based on foreground mask. */ 00634 /* pFGMask - image of foreground mask */ 00635 /* pNewBlob - pointer to CvBlob structure which will be filled if new blob entrance detected */ 00636 /* pOldBlobList - pointer to blob list which already exist on image */ 00637 virtual int DetectNewBlob(IplImage* pImg, IplImage* pImgFG, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList) = 0; 00638 /* release blob detector */ 00639 virtual void Release()=0; 00640 }; 00641 /* Release any blob detector: */ 00642 inline void cvReleaseBlobDetector(CvBlobDetector** ppBD) 00643 { 00644 ppBD[0]->Release(); 00645 ppBD[0] = NULL; 00646 } 00647 /* END BLOB DETECTOR INTERFACE */ 00648 00649 /* Declarations of constructors of implemented modules: */ 00650 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorSimple(); 00651 CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorCC(); 00652 00653 00654 struct CV_EXPORTS CvDetectedBlob : public CvBlob 00655 { 00656 float response; 00657 }; 00658 00659 CV_INLINE CvDetectedBlob cvDetectedBlob( float x, float y, float w, float h, int ID = 0, float response = 0.0F ) 00660 { 00661 CvDetectedBlob b; 00662 b.x = x; b.y = y; b.w = w; b.h = h; b.ID = ID; b.response = response; 00663 return b; 00664 } 00665 00666 00667 class CV_EXPORTS CvObjectDetector 00668 { 00669 public: 00670 CvObjectDetector( const char* /*detector_file_name*/ = 0 ) {}; 00671 00672 ~CvObjectDetector() {}; 00673 00674 /* 00675 * Release the current detector and load new detector from file 00676 * (if detector_file_name is not 0) 00677 * Return true on success: 00678 */ 00679 bool Load( const char* /*detector_file_name*/ = 0 ) { return false; } 00680 00681 /* Return min detector window size: */ 00682 CvSize GetMinWindowSize() const { return cvSize(0,0); } 00683 00684 /* Return max border: */ 00685 int GetMaxBorderSize() const { return 0; } 00686 00687 /* 00688 * Detect the object on the image and push the detected 00689 * blobs into <detected_blob_seq> which must be the sequence of <CvDetectedBlob>s 00690 */ 00691 void Detect( const CvArr* /*img*/, /* out */ CvBlobSeq* /*detected_blob_seq*/ = 0 ) {}; 00692 00693 protected: 00694 class CvObjectDetectorImpl* impl; 00695 }; 00696 00697 00698 CV_INLINE CvRect cvRectIntersection( const CvRect r1, const CvRect r2 ) 00699 { 00700 CvRect r = cvRect( MAX(r1.x, r2.x), MAX(r1.y, r2.y), 0, 0 ); 00701 00702 r.width = MIN(r1.x + r1.width, r2.x + r2.width) - r.x; 00703 r.height = MIN(r1.y + r1.height, r2.y + r2.height) - r.y; 00704 00705 return r; 00706 } 00707 00708 00709 /* 00710 * CvImageDrawer 00711 * 00712 * Draw on an image the specified ROIs from the source image and 00713 * given blobs as ellipses or rectangles: 00714 */ 00715 00716 struct CvDrawShape 00717 { 00718 enum {RECT, ELLIPSE} shape; 00719 CvScalar color; 00720 }; 00721 00722 /*extern const CvDrawShape icv_shape[] = 00723 { 00724 { CvDrawShape::ELLIPSE, CV_RGB(255,0,0) }, 00725 { CvDrawShape::ELLIPSE, CV_RGB(0,255,0) }, 00726 { CvDrawShape::ELLIPSE, CV_RGB(0,0,255) }, 00727 { CvDrawShape::ELLIPSE, CV_RGB(255,255,0) }, 00728 { CvDrawShape::ELLIPSE, CV_RGB(0,255,255) }, 00729 { CvDrawShape::ELLIPSE, CV_RGB(255,0,255) } 00730 };*/ 00731 00732 class CV_EXPORTS CvImageDrawer 00733 { 00734 public: 00735 CvImageDrawer() : m_image(0) {} 00736 ~CvImageDrawer() { cvReleaseImage( &m_image ); } 00737 void SetShapes( const CvDrawShape* shapes, int num ); 00738 /* <blob_seq> must be the sequence of <CvDetectedBlob>s */ 00739 IplImage* Draw( const CvArr* src, CvBlobSeq* blob_seq = 0, const CvSeq* roi_seq = 0 ); 00740 IplImage* GetImage() { return m_image; } 00741 protected: 00742 //static const int MAX_SHAPES = sizeof(icv_shape) / sizeof(icv_shape[0]);; 00743 00744 IplImage* m_image; 00745 CvDrawShape m_shape[16]; 00746 }; 00747 00748 00749 00750 /* Trajectory generation module: */ 00751 class CV_EXPORTS CvBlobTrackGen: public CvVSModule 00752 { 00753 public: 00754 CvBlobTrackGen(){SetTypeName("BlobTrackGen");}; 00755 virtual void SetFileName(char* pFileName) = 0; 00756 virtual void AddBlob(CvBlob* pBlob) = 0; 00757 virtual void Process(IplImage* pImg = NULL, IplImage* pFG = NULL) = 0; 00758 virtual void Release() = 0; 00759 }; 00760 00761 inline void cvReleaseBlobTrackGen(CvBlobTrackGen** pBTGen) 00762 { 00763 if(*pBTGen)(*pBTGen)->Release(); 00764 *pBTGen = 0; 00765 } 00766 00767 /* Declarations of constructors of implemented modules: */ 00768 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGen1(); 00769 CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGenYML(); 00770 00771 00772 00773 /* BLOB TRACKER INTERFACE */ 00774 class CV_EXPORTS CvBlobTracker: public CvVSModule 00775 { 00776 public: 00777 CvBlobTracker(){SetTypeName("BlobTracker");}; 00778 00779 /* Add new blob to track it and assign to this blob personal ID */ 00780 /* pBlob - pointer to structure with blob parameters (ID is ignored)*/ 00781 /* pImg - current image */ 00782 /* pImgFG - current foreground mask */ 00783 /* Return pointer to new added blob: */ 00784 virtual CvBlob* AddBlob(CvBlob* pBlob, IplImage* pImg, IplImage* pImgFG = NULL ) = 0; 00785 00786 /* Return number of currently tracked blobs: */ 00787 virtual int GetBlobNum() = 0; 00788 00789 /* Return pointer to specified by index blob: */ 00790 virtual CvBlob* GetBlob(int BlobIndex) = 0; 00791 00792 /* Delete blob by its index: */ 00793 virtual void DelBlob(int BlobIndex) = 0; 00794 00795 /* Process current image and track all existed blobs: */ 00796 virtual void Process(IplImage* pImg, IplImage* pImgFG = NULL) = 0; 00797 00798 /* Release blob tracker: */ 00799 virtual void Release() = 0; 00800 00801 00802 /* Process one blob (for multi hypothesis tracing): */ 00803 virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL) 00804 { 00805 CvBlob* pB; 00806 int ID = 0; 00807 assert(pBlob); 00808 //pBlob->ID; 00809 pB = GetBlob(BlobIndex); 00810 if(pB) 00811 pBlob[0] = pB[0]; 00812 pBlob->ID = ID; 00813 }; 00814 00815 /* Get confidence/wieght/probability (0-1) for blob: */ 00816 virtual double GetConfidence(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL) 00817 { 00818 return 1; 00819 }; 00820 00821 virtual double GetConfidenceList(CvBlobSeq* pBlobList, IplImage* pImg, IplImage* pImgFG = NULL) 00822 { 00823 int b,bN = pBlobList->GetBlobNum(); 00824 double W = 1; 00825 for(b=0;b<bN;++b) 00826 { 00827 CvBlob* pB = pBlobList->GetBlob(b); 00828 int BI = GetBlobIndexByID(pB->ID); 00829 W *= GetConfidence(BI,pB,pImg,pImgFG); 00830 } 00831 return W; 00832 }; 00833 00834 virtual void UpdateBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){}; 00835 00836 /* Update all blob models: */ 00837 virtual void Update(IplImage* pImg, IplImage* pImgFG = NULL) 00838 { 00839 int i; 00840 for(i=GetBlobNum();i>0;i--) 00841 { 00842 CvBlob* pB=GetBlob(i-1); 00843 UpdateBlob(i-1, pB, pImg, pImgFG); 00844 } 00845 00846 }; 00847 00848 /* Return pointer to blob by its unique ID: */ 00849 virtual int GetBlobIndexByID(int BlobID) 00850 { 00851 int i; 00852 for(i=GetBlobNum();i>0;i--) 00853 { 00854 CvBlob* pB=GetBlob(i-1); 00855 if(CV_BLOB_ID(pB) == BlobID) return i-1; 00856 } 00857 return -1; 00858 }; 00859 00860 /* Return pointer to blob by its unique ID: */ 00861 virtual CvBlob* GetBlobByID(int BlobID){return GetBlob(GetBlobIndexByID(BlobID));}; 00862 00863 /* Delete blob by its ID: */ 00864 virtual void DelBlobByID(int BlobID){DelBlob(GetBlobIndexByID(BlobID));}; 00865 00866 /* Set new parameters for specified (by index) blob: */ 00867 virtual void SetBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/){}; 00868 00869 /* Set new parameters for specified (by ID) blob: */ 00870 virtual void SetBlobByID(int BlobID, CvBlob* pBlob) 00871 { 00872 SetBlob(GetBlobIndexByID(BlobID),pBlob); 00873 }; 00874 00875 /* =============== MULTI HYPOTHESIS INTERFACE ================== */ 00876 00877 /* Return number of position hyposetis of currently tracked blob: */ 00878 virtual int GetBlobHypNum(int /*BlobIdx*/){return 1;}; 00879 00880 /* Return pointer to specified blob hypothesis by index blob: */ 00881 virtual CvBlob* GetBlobHyp(int BlobIndex, int /*hypothesis*/){return GetBlob(BlobIndex);}; 00882 00883 /* Set new parameters for specified (by index) blob hyp 00884 * (can be called several times for each hyp ): 00885 */ 00886 virtual void SetBlobHyp(int /*BlobIndex*/, CvBlob* /*pBlob*/){}; 00887 }; 00888 inline void cvReleaseBlobTracker(CvBlobTracker**ppT ) 00889 { 00890 ppT[0]->Release(); 00891 ppT[0] = 0; 00892 } 00893 /* BLOB TRACKER INTERFACE */ 00894 00895 /*BLOB TRACKER ONE INTERFACE */ 00896 class CV_EXPORTS CvBlobTrackerOne:public CvVSModule 00897 { 00898 public: 00899 virtual void Init(CvBlob* pBlobInit, IplImage* pImg, IplImage* pImgFG = NULL) = 0; 00900 virtual CvBlob* Process(CvBlob* pBlobPrev, IplImage* pImg, IplImage* pImgFG = NULL) = 0; 00901 virtual void Release() = 0; 00902 00903 /* Non-required methods: */ 00904 virtual void SkipProcess(CvBlob* /*pBlobPrev*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){}; 00905 virtual void Update(CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){}; 00906 virtual void SetCollision(int /*CollisionFlag*/){}; /* call in case of blob collision situation*/ 00907 virtual double GetConfidence(CvBlob* /*pBlob*/, IplImage* /*pImg*/, 00908 IplImage* /*pImgFG*/ = NULL, IplImage* /*pImgUnusedReg*/ = NULL) 00909 { 00910 return 1; 00911 }; 00912 }; 00913 inline void cvReleaseBlobTrackerOne(CvBlobTrackerOne **ppT ) 00914 { 00915 ppT[0]->Release(); 00916 ppT[0] = 0; 00917 } 00918 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerList(CvBlobTrackerOne* (*create)()); 00919 /*BLOB TRACKER ONE INTERFACE */ 00920 00921 /* Declarations of constructors of implemented modules: */ 00922 00923 /* Some declarations for specific MeanShift tracker: */ 00924 #define PROFILE_EPANECHNIKOV 0 00925 #define PROFILE_DOG 1 00926 struct CvBlobTrackerParamMS 00927 { 00928 int noOfSigBits; 00929 int appearance_profile; 00930 int meanshift_profile; 00931 float sigma; 00932 }; 00933 00934 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1(CvBlobTrackerParamMS* param); 00935 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS2(CvBlobTrackerParamMS* param); 00936 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1ByList(); 00937 00938 /* Some declarations for specific Likelihood tracker: */ 00939 struct CvBlobTrackerParamLH 00940 { 00941 int HistType; /* see Prob.h */ 00942 int ScaleAfter; 00943 }; 00944 00945 /* Without scale optimization: */ 00946 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHR(CvBlobTrackerParamLH* /*param*/ = NULL); 00947 00948 /* With scale optimization: */ 00949 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHRS(CvBlobTrackerParamLH* /*param*/ = NULL); 00950 00951 /* Simple blob tracker based on connected component tracking: */ 00952 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCC(); 00953 00954 /* Connected component tracking and mean-shift particle filter collion-resolver: */ 00955 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCCMSPF(); 00956 00957 /* Blob tracker that integrates meanshift and connected components: */ 00958 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFG(); 00959 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFGS(); 00960 00961 /* Meanshift without connected-components */ 00962 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS(); 00963 00964 /* Particle filtering via Bhattacharya coefficient, which */ 00965 /* is roughly the dot-product of two probability densities. */ 00966 /* See: Real-Time Tracking of Non-Rigid Objects using Mean Shift */ 00967 /* Comanicius, Ramesh, Meer, 2000, 8p */ 00968 /* http://citeseer.ist.psu.edu/321441.html */ 00969 CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSPF(); 00970 00971 /* =========== tracker integrators trackers =============*/ 00972 00973 /* Integrator based on Particle Filtering method: */ 00974 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPF(); 00975 00976 /* Rule based integrator: */ 00977 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIRB(); 00978 00979 /* Integrator based on data fusion using particle filtering: */ 00980 //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPFDF(); 00981 00982 00983 00984 00985 /* Trajectory postprocessing module: */ 00986 class CV_EXPORTS CvBlobTrackPostProc: public CvVSModule 00987 { 00988 public: 00989 CvBlobTrackPostProc(){SetTypeName("BlobTrackPostProc");}; 00990 virtual void AddBlob(CvBlob* pBlob) = 0; 00991 virtual void Process() = 0; 00992 virtual int GetBlobNum() = 0; 00993 virtual CvBlob* GetBlob(int index) = 0; 00994 virtual void Release() = 0; 00995 00996 /* Additional functionality: */ 00997 virtual CvBlob* GetBlobByID(int BlobID) 00998 { 00999 int i; 01000 for(i=GetBlobNum();i>0;i--) 01001 { 01002 CvBlob* pB=GetBlob(i-1); 01003 if(pB->ID==BlobID) return pB; 01004 } 01005 return NULL; 01006 }; 01007 }; 01008 01009 inline void cvReleaseBlobTrackPostProc(CvBlobTrackPostProc** pBTPP) 01010 { 01011 if(pBTPP == NULL) return; 01012 if(*pBTPP)(*pBTPP)->Release(); 01013 *pBTPP = 0; 01014 } 01015 01016 /* Trajectory generation module: */ 01017 class CV_EXPORTS CvBlobTrackPostProcOne: public CvVSModule 01018 { 01019 public: 01020 CvBlobTrackPostProcOne(){SetTypeName("BlobTrackPostOne");}; 01021 virtual CvBlob* Process(CvBlob* pBlob) = 0; 01022 virtual void Release() = 0; 01023 }; 01024 01025 /* Create blob tracking post processing module based on simle module: */ 01026 CV_EXPORTS CvBlobTrackPostProc* cvCreateBlobTrackPostProcList(CvBlobTrackPostProcOne* (*create)()); 01027 01028 01029 /* Declarations of constructors of implemented modules: */ 01030 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcKalman(); 01031 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverRect(); 01032 CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverExp(); 01033 01034 01035 /* PREDICTORS */ 01036 /* blob PREDICTOR */ 01037 class CvBlobTrackPredictor: public CvVSModule 01038 { 01039 public: 01040 CvBlobTrackPredictor(){SetTypeName("BlobTrackPredictor");}; 01041 virtual CvBlob* Predict() = 0; 01042 virtual void Update(CvBlob* pBlob) = 0; 01043 virtual void Release() = 0; 01044 }; 01045 CV_EXPORTS CvBlobTrackPredictor* cvCreateModuleBlobTrackPredictKalman(); 01046 01047 01048 01049 /* Trajectory analyser module: */ 01050 class CV_EXPORTS CvBlobTrackAnalysis: public CvVSModule 01051 { 01052 public: 01053 CvBlobTrackAnalysis(){SetTypeName("BlobTrackAnalysis");}; 01054 virtual void AddBlob(CvBlob* pBlob) = 0; 01055 virtual void Process(IplImage* pImg, IplImage* pFG) = 0; 01056 virtual float GetState(int BlobID) = 0; 01057 /* return 0 if trajectory is normal 01058 return >0 if trajectory abnormal */ 01059 virtual const char* GetStateDesc(int /*BlobID*/){return NULL;}; 01060 virtual void SetFileName(char* /*DataBaseName*/){}; 01061 virtual void Release() = 0; 01062 }; 01063 01064 01065 inline void cvReleaseBlobTrackAnalysis(CvBlobTrackAnalysis** pBTPP) 01066 { 01067 if(pBTPP == NULL) return; 01068 if(*pBTPP)(*pBTPP)->Release(); 01069 *pBTPP = 0; 01070 } 01071 01072 /* Feature-vector generation module: */ 01073 class CV_EXPORTS CvBlobTrackFVGen : public CvVSModule 01074 { 01075 public: 01076 CvBlobTrackFVGen(){SetTypeName("BlobTrackFVGen");}; 01077 virtual void AddBlob(CvBlob* pBlob) = 0; 01078 virtual void Process(IplImage* pImg, IplImage* pFG) = 0; 01079 virtual void Release() = 0; 01080 virtual int GetFVSize() = 0; 01081 virtual int GetFVNum() = 0; 01082 virtual float* GetFV(int index, int* pFVID) = 0; /* Returns pointer to FV, if return 0 then FV not created */ 01083 virtual float* GetFVVar(){return NULL;}; /* Returns pointer to array of variation of values of FV, if returns 0 then FVVar does not exist. */ 01084 virtual float* GetFVMin() = 0; /* Returns pointer to array of minimal values of FV, if returns 0 then FVrange does not exist */ 01085 virtual float* GetFVMax() = 0; /* Returns pointer to array of maximal values of FV, if returns 0 then FVrange does not exist */ 01086 }; 01087 01088 01089 /* Trajectory Analyser module: */ 01090 class CV_EXPORTS CvBlobTrackAnalysisOne 01091 { 01092 public: 01093 virtual ~CvBlobTrackAnalysisOne() {}; 01094 virtual int Process(CvBlob* pBlob, IplImage* pImg, IplImage* pFG) = 0; 01095 /* return 0 if trajectory is normal 01096 return >0 if trajectory abnormal */ 01097 virtual void Release() = 0; 01098 }; 01099 01100 /* Create blob tracking post processing module based on simle module: */ 01101 CV_EXPORTS CvBlobTrackAnalysis* cvCreateBlobTrackAnalysisList(CvBlobTrackAnalysisOne* (*create)()); 01102 01103 /* Declarations of constructors of implemented modules: */ 01104 01105 /* Based on histogram analysis of 2D FV (x,y): */ 01106 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistP(); 01107 01108 /* Based on histogram analysis of 4D FV (x,y,vx,vy): */ 01109 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPV(); 01110 01111 /* Based on histogram analysis of 5D FV (x,y,vx,vy,state): */ 01112 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPVS(); 01113 01114 /* Based on histogram analysis of 4D FV (startpos,stoppos): */ 01115 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistSS(); 01116 01117 01118 01119 /* Based on SVM classifier analysis of 2D FV (x,y): */ 01120 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP(); 01121 01122 /* Based on SVM classifier analysis of 4D FV (x,y,vx,vy): */ 01123 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPV(); 01124 01125 /* Based on SVM classifier analysis of 5D FV (x,y,vx,vy,state): */ 01126 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS(); 01127 01128 /* Based on SVM classifier analysis of 4D FV (startpos,stoppos): */ 01129 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS(); 01130 01131 /* Track analysis based on distance between tracks: */ 01132 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisTrackDist(); 01133 01134 /* Analyzer based on reation Road and height map: */ 01135 //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysis3DRoadMap(); 01136 01137 /* Analyzer that makes OR decision using set of analyzers: */ 01138 CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR(); 01139 01140 /* Estimator of human height: */ 01141 class CV_EXPORTS CvBlobTrackAnalysisHeight: public CvBlobTrackAnalysis 01142 { 01143 public: 01144 virtual double GetHeight(CvBlob* pB) = 0; 01145 }; 01146 //CV_EXPORTS CvBlobTrackAnalysisHeight* cvCreateModuleBlobTrackAnalysisHeightScale(); 01147 01148 01149 01150 /* AUTO BLOB TRACKER INTERFACE -- pipeline of 3 modules: */ 01151 class CV_EXPORTS CvBlobTrackerAuto: public CvVSModule 01152 { 01153 public: 01154 CvBlobTrackerAuto(){SetTypeName("BlobTrackerAuto");}; 01155 virtual void Process(IplImage* pImg, IplImage* pMask = NULL) = 0; 01156 virtual CvBlob* GetBlob(int index) = 0; 01157 virtual CvBlob* GetBlobByID(int ID) = 0; 01158 virtual int GetBlobNum() = 0; 01159 virtual IplImage* GetFGMask(){return NULL;}; 01160 virtual float GetState(int BlobID) = 0; 01161 virtual const char* GetStateDesc(int BlobID) = 0; 01162 /* return 0 if trajectory is normal; 01163 * return >0 if trajectory abnormal. */ 01164 virtual void Release() = 0; 01165 }; 01166 inline void cvReleaseBlobTrackerAuto(CvBlobTrackerAuto** ppT) 01167 { 01168 ppT[0]->Release(); 01169 ppT[0] = 0; 01170 } 01171 /* END AUTO BLOB TRACKER INTERFACE */ 01172 01173 01174 /* Constructor functions and data for specific BlobTRackerAuto modules: */ 01175 01176 /* Parameters of blobtracker auto ver1: */ 01177 struct CvBlobTrackerAutoParam1 01178 { 01179 int FGTrainFrames; /* Number of frames needed for FG (foreground) detector to train. */ 01180 01181 CvFGDetector* pFG; /* FGDetector module. If this field is NULL the Process FG mask is used. */ 01182 01183 CvBlobDetector* pBD; /* Selected blob detector module. */ 01184 /* If this field is NULL default blobdetector module will be created. */ 01185 01186 CvBlobTracker* pBT; /* Selected blob tracking module. */ 01187 /* If this field is NULL default blobtracker module will be created. */ 01188 01189 CvBlobTrackGen* pBTGen; /* Selected blob trajectory generator. */ 01190 /* If this field is NULL no generator is used. */ 01191 01192 CvBlobTrackPostProc* pBTPP; /* Selected blob trajectory postprocessing module. */ 01193 /* If this field is NULL no postprocessing is done. */ 01194 01195 int UsePPData; 01196 01197 CvBlobTrackAnalysis* pBTA; /* Selected blob trajectory analysis module. */ 01198 /* If this field is NULL no track analysis is done. */ 01199 }; 01200 01201 /* Create blob tracker auto ver1: */ 01202 CV_EXPORTS CvBlobTrackerAuto* cvCreateBlobTrackerAuto1(CvBlobTrackerAutoParam1* param = NULL); 01203 01204 /* Simple loader for many auto trackers by its type : */ 01205 inline CvBlobTrackerAuto* cvCreateBlobTrackerAuto(int type, void* param) 01206 { 01207 if(type == 0) return cvCreateBlobTrackerAuto1((CvBlobTrackerAutoParam1*)param); 01208 return 0; 01209 } 01210 01211 01212 01213 struct CvTracksTimePos 01214 { 01215 int len1,len2; 01216 int beg1,beg2; 01217 int end1,end2; 01218 int comLen; //common length for two tracks 01219 int shift1,shift2; 01220 }; 01221 01222 /*CV_EXPORTS int cvCompareTracks( CvBlobTrackSeq *groundTruth, 01223 CvBlobTrackSeq *result, 01224 FILE *file);*/ 01225 01226 01227 /* Constructor functions: */ 01228 01229 CV_EXPORTS void cvCreateTracks_One(CvBlobTrackSeq *TS); 01230 CV_EXPORTS void cvCreateTracks_Same(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2); 01231 CV_EXPORTS void cvCreateTracks_AreaErr(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2, int addW, int addH); 01232 01233 01234 /* HIST API */ 01235 class CV_EXPORTS CvProb 01236 { 01237 public: 01238 virtual ~CvProb() {}; 01239 01240 /* Calculate probability value: */ 01241 virtual double Value(int* /*comp*/, int /*x*/ = 0, int /*y*/ = 0){return -1;}; 01242 01243 /* Update histograpp Pnew = (1-W)*Pold + W*Padd*/ 01244 /* W weight of new added prob */ 01245 /* comps - matrix of new fetature vectors used to update prob */ 01246 virtual void AddFeature(float W, int* comps, int x =0, int y = 0) = 0; 01247 virtual void Scale(float factor = 0, int x = -1, int y = -1) = 0; 01248 virtual void Release() = 0; 01249 }; 01250 inline void cvReleaseProb(CvProb** ppProb){ppProb[0]->Release();ppProb[0]=NULL;} 01251 /* HIST API */ 01252 01253 /* Some Prob: */ 01254 CV_EXPORTS CvProb* cvCreateProbS(int dim, CvSize size, int sample_num); 01255 CV_EXPORTS CvProb* cvCreateProbMG(int dim, CvSize size, int sample_num); 01256 CV_EXPORTS CvProb* cvCreateProbMG2(int dim, CvSize size, int sample_num); 01257 CV_EXPORTS CvProb* cvCreateProbHist(int dim, CvSize size); 01258 01259 #define CV_BT_HIST_TYPE_S 0 01260 #define CV_BT_HIST_TYPE_MG 1 01261 #define CV_BT_HIST_TYPE_MG2 2 01262 #define CV_BT_HIST_TYPE_H 3 01263 inline CvProb* cvCreateProb(int type, int dim, CvSize size = cvSize(1,1), void* /*param*/ = NULL) 01264 { 01265 if(type == CV_BT_HIST_TYPE_S) return cvCreateProbS(dim, size, -1); 01266 if(type == CV_BT_HIST_TYPE_MG) return cvCreateProbMG(dim, size, -1); 01267 if(type == CV_BT_HIST_TYPE_MG2) return cvCreateProbMG2(dim, size, -1); 01268 if(type == CV_BT_HIST_TYPE_H) return cvCreateProbHist(dim, size); 01269 return NULL; 01270 } 01271 01272 01273 01274 /* Noise type definitions: */ 01275 #define CV_NOISE_NONE 0 01276 #define CV_NOISE_GAUSSIAN 1 01277 #define CV_NOISE_UNIFORM 2 01278 #define CV_NOISE_SPECKLE 3 01279 #define CV_NOISE_SALT_AND_PEPPER 4 01280 01281 /* Add some noise to image: */ 01282 /* pImg - (input) image without noise */ 01283 /* pImg - (output) image with noise */ 01284 /* noise_type - type of added noise */ 01285 /* CV_NOISE_GAUSSIAN - pImg += n , n - is gaussian noise with Ampl standart deviation */ 01286 /* CV_NOISE_UNIFORM - pImg += n , n - is uniform noise with Ampl standart deviation */ 01287 /* CV_NOISE_SPECKLE - pImg += n*pImg , n - is gaussian noise with Ampl standart deviation */ 01288 /* CV_NOISE_SALT_AND_PAPPER - pImg = pImg with blacked and whited pixels, 01289 Ampl is density of brocken pixels (0-there are not broken pixels, 1 - all pixels are broken)*/ 01290 /* Ampl - "amplitude" of noise */ 01291 CV_EXPORTS void cvAddNoise(IplImage* pImg, int noise_type, double Ampl, CvRandState* rnd_state = NULL); 01292 01293 /*================== GENERATOR OF TEST VIDEO SEQUENCE ===================== */ 01294 typedef void CvTestSeq; 01295 01296 /* pConfigfile - Name of file (yml or xml) with description of test sequence */ 01297 /* videos - array of names of test videos described in "pConfigfile" file */ 01298 /* numvideos - size of "videos" array */ 01299 CV_EXPORTS CvTestSeq* cvCreateTestSeq(char* pConfigfile, char** videos, int numvideo, float Scale = 1, int noise_type = CV_NOISE_NONE, double noise_ampl = 0); 01300 CV_EXPORTS void cvReleaseTestSeq(CvTestSeq** ppTestSeq); 01301 01302 /* Generate next frame from test video seq and return pointer to it: */ 01303 CV_EXPORTS IplImage* cvTestSeqQueryFrame(CvTestSeq* pTestSeq); 01304 01305 /* Return pointer to current foreground mask: */ 01306 CV_EXPORTS IplImage* cvTestSeqGetFGMask(CvTestSeq* pTestSeq); 01307 01308 /* Return pointer to current image: */ 01309 CV_EXPORTS IplImage* cvTestSeqGetImage(CvTestSeq* pTestSeq); 01310 01311 /* Return frame size of result test video: */ 01312 CV_EXPORTS CvSize cvTestSeqGetImageSize(CvTestSeq* pTestSeq); 01313 01314 /* Return number of frames result test video: */ 01315 CV_EXPORTS int cvTestSeqFrameNum(CvTestSeq* pTestSeq); 01316 01317 /* Return number of existing objects. 01318 * This is general number of any objects. 01319 * For example number of trajectories may be equal or less than returned value: 01320 */ 01321 CV_EXPORTS int cvTestSeqGetObjectNum(CvTestSeq* pTestSeq); 01322 01323 /* Return 0 if there is not position for current defined on current frame */ 01324 /* Return 1 if there is object position and pPos was filled */ 01325 CV_EXPORTS int cvTestSeqGetObjectPos(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pPos); 01326 CV_EXPORTS int cvTestSeqGetObjectSize(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pSize); 01327 01328 /* Add noise to final image: */ 01329 CV_EXPORTS void cvTestSeqAddNoise(CvTestSeq* pTestSeq, int noise_type = CV_NOISE_NONE, double noise_ampl = 0); 01330 01331 /* Add Intensity variation: */ 01332 CV_EXPORTS void cvTestSeqAddIntensityVariation(CvTestSeq* pTestSeq, float DI_per_frame, float MinI, float MaxI); 01333 CV_EXPORTS void cvTestSeqSetFrame(CvTestSeq* pTestSeq, int n); 01334 01335 #endif 01336 01337 /* End of file. */