cvvidsurv.hpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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. #ifndef __CVVIDEOSURVEILLANCE_H__
  42. #define __CVVIDEOSURVEILLANCE_H__
  43. /* turn off the functionality until cvaux/src/Makefile.am gets updated */
  44. //#if _MSC_VER >= 1200
  45. #include <stdio.h>
  46. #if _MSC_VER >= 1200 || defined __BORLANDC__
  47. #define cv_stricmp stricmp
  48. #define cv_strnicmp strnicmp
  49. #elif defined __GNUC__
  50. #define cv_stricmp strcasecmp
  51. #define cv_strnicmp strncasecmp
  52. #else
  53. #error Do not know how to make case-insensitive string comparison on this platform
  54. #endif
  55. //struct DefParam;
  56. struct CvDefParam
  57. {
  58. struct CvDefParam* next;
  59. char* pName;
  60. char* pComment;
  61. double* pDouble;
  62. double Double;
  63. float* pFloat;
  64. float Float;
  65. int* pInt;
  66. int Int;
  67. char** pStr;
  68. char* Str;
  69. };
  70. class CV_EXPORTS CvVSModule
  71. {
  72. private: /* internal data */
  73. CvDefParam* m_pParamList;
  74. char* m_pModuleTypeName;
  75. char* m_pModuleName;
  76. char* m_pNickName;
  77. protected:
  78. int m_Wnd;
  79. public: /* constructor and destructor */
  80. CvVSModule()
  81. {
  82. m_pNickName = NULL;
  83. m_pParamList = NULL;
  84. m_pModuleTypeName = NULL;
  85. m_pModuleName = NULL;
  86. m_Wnd = 0;
  87. AddParam("DebugWnd",&m_Wnd);
  88. }
  89. virtual ~CvVSModule()
  90. {
  91. CvDefParam* p = m_pParamList;
  92. for(;p;)
  93. {
  94. CvDefParam* pf = p;
  95. p=p->next;
  96. FreeParam(&pf);
  97. }
  98. m_pParamList=NULL;
  99. if(m_pModuleTypeName)free(m_pModuleTypeName);
  100. if(m_pModuleName)free(m_pModuleName);
  101. }
  102. private: /* internal functions */
  103. void FreeParam(CvDefParam** pp)
  104. {
  105. CvDefParam* p = pp[0];
  106. if(p->Str)free(p->Str);
  107. if(p->pName)free(p->pName);
  108. if(p->pComment)free(p->pComment);
  109. cvFree((void**)pp);
  110. }
  111. CvDefParam* NewParam(char* name)
  112. {
  113. CvDefParam* pNew = (CvDefParam*)cvAlloc(sizeof(CvDefParam));
  114. memset(pNew,0,sizeof(CvDefParam));
  115. pNew->pName = strdup(name);
  116. if(m_pParamList==NULL)
  117. {
  118. m_pParamList = pNew;
  119. }
  120. else
  121. {
  122. CvDefParam* p = m_pParamList;
  123. for(;p->next;p=p->next);
  124. p->next = pNew;
  125. }
  126. return pNew;
  127. };
  128. CvDefParam* GetParamPtr(int index)
  129. {
  130. CvDefParam* p = m_pParamList;
  131. for(;index>0 && p;index--,p=p->next);
  132. return p;
  133. }
  134. CvDefParam* GetParamPtr(char* name)
  135. {
  136. CvDefParam* p = m_pParamList;
  137. for(;p;p=p->next)
  138. {
  139. if(cv_stricmp(p->pName,name)==0) break;
  140. }
  141. return p;
  142. }
  143. protected: /* INTERNAL INTERFACE */
  144. int IsParam(char* name)
  145. {
  146. return GetParamPtr(name)?1:0;
  147. };
  148. void AddParam(char* name, double* pAddr)
  149. {
  150. NewParam(name)->pDouble = pAddr;
  151. };
  152. void AddParam(char* name, float* pAddr)
  153. {
  154. NewParam(name)->pFloat=pAddr;
  155. };
  156. void AddParam(char* name, int* pAddr)
  157. {
  158. NewParam(name)->pInt=pAddr;
  159. };
  160. void AddParam(char* name, char** pAddr)
  161. {
  162. CvDefParam* pP = NewParam(name);
  163. char* p = pAddr?pAddr[0]:NULL;
  164. pP->pStr = pAddr?pAddr:&(pP->Str);
  165. if(p)
  166. {
  167. pP->Str = strdup(p);
  168. pP->pStr[0] = pP->Str;
  169. }
  170. };
  171. void AddParam(char* name)
  172. {
  173. CvDefParam* p = NewParam(name);
  174. p->pDouble = &p->Double;
  175. };
  176. void CommentParam(char* name, char* pComment)
  177. {
  178. CvDefParam* p = GetParamPtr(name);
  179. if(p)p->pComment = pComment ? strdup(pComment) : 0;
  180. };
  181. void SetTypeName(char* name){m_pModuleTypeName = strdup(name);}
  182. void SetModuleName(char* name){m_pModuleName = strdup(name);}
  183. void DelParam(char* name)
  184. {
  185. CvDefParam* p = m_pParamList;
  186. CvDefParam* pPrev = NULL;
  187. for(;p;p=p->next)
  188. {
  189. if(cv_stricmp(p->pName,name)==0) break;
  190. pPrev = p;
  191. }
  192. if(p)
  193. {
  194. if(pPrev)
  195. {
  196. pPrev->next = p->next;
  197. }
  198. else
  199. {
  200. m_pParamList = p->next;
  201. }
  202. FreeParam(&p);
  203. }
  204. }/* DelParam */
  205. public: /* EXTERNAL INTERFACE */
  206. char* GetParamName(int index)
  207. {
  208. CvDefParam* p = GetParamPtr(index);
  209. return p?p->pName:NULL;
  210. }
  211. char* GetParamComment(char* name)
  212. {
  213. CvDefParam* p = GetParamPtr(name);
  214. if(p && p->pComment) return p->pComment;
  215. return NULL;
  216. }
  217. double GetParam(char* name)
  218. {
  219. CvDefParam* p = GetParamPtr(name);
  220. if(p)
  221. {
  222. if(p->pDouble) return p->pDouble[0];
  223. if(p->pFloat) return p->pFloat[0];
  224. if(p->pInt) return p->pInt[0];
  225. }
  226. return 0;
  227. };
  228. char* GetParamStr(char* name)
  229. {
  230. CvDefParam* p = GetParamPtr(name);
  231. return p?p->Str:NULL;
  232. }
  233. void SetParam(char* name, double val)
  234. {
  235. CvDefParam* p = m_pParamList;
  236. for(;p;p=p->next)
  237. {
  238. if(cv_stricmp(p->pName,name) != 0) continue;
  239. if(p->pDouble)p->pDouble[0] = val;
  240. if(p->pFloat)p->pFloat[0] = (float)val;
  241. if(p->pInt)p->pInt[0] = cvRound(val);
  242. }
  243. }
  244. void SetParamStr(char* name, char* str)
  245. {
  246. CvDefParam* p = m_pParamList;
  247. for(;p;p=p->next)
  248. {
  249. if(cv_stricmp(p->pName,name) != 0) continue;
  250. if(p->pStr)
  251. {
  252. if(p->Str)free(p->Str);
  253. p->Str = NULL;
  254. if(str)p->Str = strdup(str);
  255. p->pStr[0] = p->Str;
  256. }
  257. }
  258. /* convert to double and set */
  259. if(str)SetParam(name,atof(str));
  260. }
  261. void TransferParamsFromChild(CvVSModule* pM, char* prefix = NULL)
  262. {
  263. char tmp[1024];
  264. char* FN = NULL;
  265. int i;
  266. for(i=0;;++i)
  267. {
  268. char* N = pM->GetParamName(i);
  269. if(N == NULL) break;
  270. FN = N;
  271. if(prefix)
  272. {
  273. strcpy(tmp,prefix);
  274. strcat(tmp,"_");
  275. FN = strcat(tmp,N);
  276. }
  277. if(!IsParam(FN))
  278. {
  279. if(pM->GetParamStr(N))
  280. {
  281. AddParam(FN,(char**)NULL);
  282. }
  283. else
  284. {
  285. AddParam(FN);
  286. }
  287. }
  288. if(pM->GetParamStr(N))
  289. {
  290. char* val = pM->GetParamStr(N);
  291. SetParamStr(FN,val);
  292. }
  293. else
  294. {
  295. double val = pM->GetParam(N);
  296. SetParam(FN,val);
  297. }
  298. CommentParam(FN, pM->GetParamComment(N));
  299. }/* transfer next param */
  300. }/* Transfer params */
  301. void TransferParamsToChild(CvVSModule* pM, char* prefix = NULL)
  302. {
  303. char tmp[1024];
  304. int i;
  305. for(i=0;;++i)
  306. {
  307. char* N = pM->GetParamName(i);
  308. if(N == NULL) break;
  309. if(prefix)
  310. {
  311. strcpy(tmp,prefix);
  312. strcat(tmp,"_");
  313. strcat(tmp,N);
  314. }
  315. else
  316. {
  317. strcpy(tmp,N);
  318. }
  319. if(IsParam(tmp))
  320. {
  321. if(GetParamStr(tmp))
  322. pM->SetParamStr(N,GetParamStr(tmp));
  323. else
  324. pM->SetParam(N,GetParam(tmp));
  325. }
  326. }/* transfer next param */
  327. pM->ParamUpdate();
  328. }/* Transfer params */
  329. virtual void ParamUpdate(){};
  330. char* GetTypeName()
  331. {
  332. return m_pModuleTypeName;
  333. }
  334. int IsModuleTypeName(char* name)
  335. {
  336. return m_pModuleTypeName?(cv_stricmp(m_pModuleTypeName,name)==0):0;
  337. }
  338. char* GetModuleName()
  339. {
  340. return m_pModuleName;
  341. }
  342. int IsModuleName(char* name)
  343. {
  344. return m_pModuleName?(cv_stricmp(m_pModuleName,name)==0):0;
  345. }
  346. void SetNickName(char* pStr)
  347. {
  348. if(m_pNickName)
  349. free(m_pNickName);
  350. m_pNickName = NULL;
  351. if(pStr)
  352. m_pNickName = strdup(pStr);
  353. }
  354. char* GetNickName()
  355. {
  356. return m_pNickName ? m_pNickName : (char *)"unknown";
  357. }
  358. virtual void SaveState(CvFileStorage*){};
  359. virtual void LoadState(CvFileStorage*, CvFileNode*){};
  360. virtual void Release() = 0;
  361. };/* CvVMModule */
  362. void inline cvWriteStruct(CvFileStorage* fs, char* name, void* addr, char* desc, int num=1)
  363. {
  364. cvStartWriteStruct(fs,name,CV_NODE_SEQ|CV_NODE_FLOW);
  365. cvWriteRawData(fs,addr,num,desc);
  366. cvEndWriteStruct(fs);
  367. }
  368. void inline cvReadStructByName(CvFileStorage* fs, CvFileNode* node, char* name, void* addr, char* desc)
  369. {
  370. CvFileNode* pSeqNode = cvGetFileNodeByName(fs, node, name);
  371. if(pSeqNode==NULL)
  372. {
  373. printf("WARNING!!! Can't read structure %s\n",name);
  374. }
  375. else
  376. {
  377. if(CV_NODE_IS_SEQ(pSeqNode->tag))
  378. {
  379. cvReadRawData( fs, pSeqNode, addr, desc );
  380. }
  381. else
  382. {
  383. printf("WARNING!!! Structure %s is not sequence and can not be read\n",name);
  384. }
  385. }
  386. }
  387. /* FOREGROUND DETECTOR INTERFACE */
  388. class CV_EXPORTS CvFGDetector: public CvVSModule
  389. {
  390. public:
  391. virtual IplImage* GetMask() = 0;
  392. /* process current image */
  393. virtual void Process(IplImage* pImg) = 0;
  394. /* release foreground detector */
  395. virtual void Release() = 0;
  396. };
  397. inline void cvReleaseFGDetector(CvFGDetector** ppT )
  398. {
  399. ppT[0]->Release();
  400. ppT[0] = 0;
  401. }
  402. /* FOREGROUND DETECTOR INTERFACE */
  403. CV_EXPORTS CvFGDetector* cvCreateFGDetectorBase(int type, void *param);
  404. /* BLOB STRUCTURE*/
  405. struct CvBlob
  406. {
  407. float x,y; /* blob position */
  408. float w,h; /* blob sizes */
  409. int ID; /* blbo ID */
  410. };
  411. inline CvBlob cvBlob(float x,float y, float w, float h)
  412. {
  413. CvBlob B = {x,y,w,h,0};
  414. return B;
  415. }
  416. #define CV_BLOB_MINW 5
  417. #define CV_BLOB_MINH 5
  418. #define CV_BLOB_ID(pB) (((CvBlob*)(pB))->ID)
  419. #define CV_BLOB_CENTER(pB) cvPoint2D32f(((CvBlob*)(pB))->x,((CvBlob*)(pB))->y)
  420. #define CV_BLOB_X(pB) (((CvBlob*)(pB))->x)
  421. #define CV_BLOB_Y(pB) (((CvBlob*)(pB))->y)
  422. #define CV_BLOB_WX(pB) (((CvBlob*)(pB))->w)
  423. #define CV_BLOB_WY(pB) (((CvBlob*)(pB))->h)
  424. #define CV_BLOB_RX(pB) (0.5f*CV_BLOB_WX(pB))
  425. #define CV_BLOB_RY(pB) (0.5f*CV_BLOB_WY(pB))
  426. #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)))
  427. /* END BLOB STRUCTURE*/
  428. /* simple BLOBLIST */
  429. class CV_EXPORTS CvBlobSeq
  430. {
  431. public:
  432. CvBlobSeq(int BlobSize = sizeof(CvBlob))
  433. {
  434. m_pMem = cvCreateMemStorage();
  435. m_pSeq = cvCreateSeq(0,sizeof(CvSeq),BlobSize,m_pMem);
  436. strcpy(m_pElemFormat,"ffffi");
  437. }
  438. virtual ~CvBlobSeq()
  439. {
  440. cvReleaseMemStorage(&m_pMem);
  441. };
  442. virtual CvBlob* GetBlob(int BlobIndex)
  443. {
  444. return (CvBlob*)cvGetSeqElem(m_pSeq,BlobIndex);
  445. };
  446. virtual CvBlob* GetBlobByID(int BlobID)
  447. {
  448. int i;
  449. for(i=0;i<m_pSeq->total;++i)
  450. if(BlobID == CV_BLOB_ID(GetBlob(i)))
  451. return GetBlob(i);
  452. return NULL;
  453. };
  454. virtual void DelBlob(int BlobIndex)
  455. {
  456. cvSeqRemove(m_pSeq,BlobIndex);
  457. };
  458. virtual void DelBlobByID(int BlobID)
  459. {
  460. int i;
  461. for(i=0;i<m_pSeq->total;++i)
  462. {
  463. if(BlobID == CV_BLOB_ID(GetBlob(i)))
  464. {
  465. DelBlob(i);
  466. return;
  467. }
  468. }
  469. };
  470. virtual void Clear()
  471. {
  472. cvClearSeq(m_pSeq);
  473. };
  474. virtual void AddBlob(CvBlob* pB)
  475. {
  476. cvSeqPush(m_pSeq,pB);
  477. };
  478. virtual int GetBlobNum()
  479. {
  480. return m_pSeq->total;
  481. };
  482. virtual void Write(CvFileStorage* fs, char* name)
  483. {
  484. char* attr[] = {"dt",m_pElemFormat,NULL};
  485. if(fs)
  486. {
  487. cvWrite(fs,name,m_pSeq,cvAttrList((const char**)attr,NULL));
  488. }
  489. }
  490. virtual void Load(CvFileStorage* fs, CvFileNode* node)
  491. {
  492. if(fs==NULL) return;
  493. CvSeq* pSeq = (CvSeq*)cvRead(fs, node);
  494. if(pSeq)
  495. {
  496. int i;
  497. cvClearSeq(m_pSeq);
  498. for(i=0;i<pSeq->total;++i)
  499. {
  500. void* pB = cvGetSeqElem( pSeq, i );
  501. cvSeqPush( m_pSeq, pB );
  502. }
  503. }
  504. }
  505. void AddFormat(char* str){strcat(m_pElemFormat,str);}
  506. protected:
  507. CvMemStorage* m_pMem;
  508. CvSeq* m_pSeq;
  509. char m_pElemFormat[1024];
  510. };
  511. /* simple BLOBLIST */
  512. /* simple TRACKLIST */
  513. struct CvBlobTrack
  514. {
  515. int TrackID;
  516. int StartFrame;
  517. CvBlobSeq* pBlobSeq;
  518. };
  519. class CV_EXPORTS CvBlobTrackSeq
  520. {
  521. public:
  522. CvBlobTrackSeq(int TrackSize = sizeof(CvBlobTrack))
  523. {
  524. m_pMem = cvCreateMemStorage();
  525. m_pSeq = cvCreateSeq(0,sizeof(CvSeq),TrackSize,m_pMem);
  526. }
  527. virtual ~CvBlobTrackSeq()
  528. {
  529. Clear();
  530. cvReleaseMemStorage(&m_pMem);
  531. };
  532. virtual CvBlobTrack* GetBlobTrack(int TrackIndex)
  533. {
  534. return (CvBlobTrack*)cvGetSeqElem(m_pSeq,TrackIndex);
  535. };
  536. virtual CvBlobTrack* GetBlobTrackByID(int TrackID)
  537. {
  538. int i;
  539. for(i=0;i<m_pSeq->total;++i)
  540. {
  541. CvBlobTrack* pP = GetBlobTrack(i);
  542. if(pP && pP->TrackID == TrackID)
  543. return pP;
  544. }
  545. return NULL;
  546. };
  547. virtual void DelBlobTrack(int TrackIndex)
  548. {
  549. CvBlobTrack* pP = GetBlobTrack(TrackIndex);
  550. if(pP && pP->pBlobSeq) delete pP->pBlobSeq;
  551. cvSeqRemove(m_pSeq,TrackIndex);
  552. };
  553. virtual void DelBlobTrackByID(int TrackID)
  554. {
  555. int i;
  556. for(i=0;i<m_pSeq->total;++i)
  557. {
  558. CvBlobTrack* pP = GetBlobTrack(i);
  559. if(TrackID == pP->TrackID)
  560. {
  561. DelBlobTrack(i);
  562. return;
  563. }
  564. }
  565. };
  566. virtual void Clear()
  567. {
  568. int i;
  569. for(i=GetBlobTrackNum();i>0;i--)
  570. {
  571. DelBlobTrack(i-1);
  572. }
  573. cvClearSeq(m_pSeq);
  574. };
  575. virtual void AddBlobTrack(int TrackID, int StartFrame = 0)
  576. {
  577. CvBlobTrack N;
  578. N.TrackID = TrackID;
  579. N.StartFrame = StartFrame;
  580. N.pBlobSeq = new CvBlobSeq;
  581. cvSeqPush(m_pSeq,&N);
  582. };
  583. virtual int GetBlobTrackNum()
  584. {
  585. return m_pSeq->total;
  586. };
  587. protected:
  588. CvMemStorage* m_pMem;
  589. CvSeq* m_pSeq;
  590. };
  591. /* simple TRACKLIST */
  592. /* BLOB DETECTOR INTERFACE */
  593. class CV_EXPORTS CvBlobDetector: public CvVSModule
  594. {
  595. public:
  596. /* try to detect new blob entrance based on foreground mask */
  597. /* pFGMask - image of foreground mask */
  598. /* pNewBlob - pointer to CvBlob structure which will bew filled if new blob entrance detected */
  599. /* pOldBlobList - pointer to blob list which already exist on image */
  600. virtual int DetectNewBlob(IplImage* pImg, IplImage* pImgFG, CvBlobSeq* pNewBlobList, CvBlobSeq* pOldBlobList) = 0;
  601. /* release blob detector */
  602. virtual void Release()=0;
  603. };
  604. /* release any blob detector*/
  605. inline void cvReleaseBlobDetector(CvBlobDetector** ppBD)
  606. {
  607. ppBD[0]->Release();
  608. ppBD[0] = NULL;
  609. }
  610. /* END BLOB DETECTOR INTERFACE */
  611. /* declaration of constructors of implemented modules */
  612. CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorSimple();
  613. CV_EXPORTS CvBlobDetector* cvCreateBlobDetectorCC();
  614. struct CV_EXPORTS CvDetectedBlob : public CvBlob
  615. {
  616. float response;
  617. };
  618. CV_INLINE CvDetectedBlob cvDetectedBlob( float x, float y, float w, float h, int ID = 0, float response = 0.0F )
  619. {
  620. CvDetectedBlob b;
  621. b.x = x; b.y = y; b.w = w; b.h = h; b.ID = ID; b.response = response;
  622. return b;
  623. }
  624. class CV_EXPORTS CvObjectDetector
  625. {
  626. public:
  627. CvObjectDetector( const char* /*detector_file_name*/ = 0 ) {};
  628. ~CvObjectDetector() {};
  629. /*
  630. * Releases the current detector and loads new detector from file
  631. * (if detector_file_name is not 0)
  632. * Returns true on success
  633. */
  634. bool Load( const char* /*detector_file_name*/ = 0 ) { return false; }
  635. /* Returns min detector window size */
  636. CvSize GetMinWindowSize() const { return cvSize(0,0); }
  637. /* Returns max border */
  638. int GetMaxBorderSize() const { return 0; }
  639. /*
  640. * Detects the objects on the image and pushes the detected
  641. * blobs into <detected_blob_seq> which must be the sequence of <CvDetectedBlob>s
  642. */
  643. void Detect( const CvArr* /*img*/, /* out */ CvBlobSeq* /*detected_blob_seq*/ = 0 ) {};
  644. protected:
  645. class CvObjectDetectorImpl* impl;
  646. };
  647. CV_INLINE CvRect cvRectIntersection( const CvRect r1, const CvRect r2 )
  648. {
  649. CvRect r = cvRect( MAX(r1.x, r2.x), MAX(r1.y, r2.y), 0, 0 );
  650. r.width = MIN(r1.x + r1.width, r2.x + r2.width) - r.x;
  651. r.height = MIN(r1.y + r1.height, r2.y + r2.height) - r.y;
  652. return r;
  653. }
  654. /*
  655. * CvImageDrawer
  656. *
  657. * Draws on an image the specified ROIs from the source image and
  658. * given blobs as ellipses or rectangles
  659. */
  660. struct CvDrawShape
  661. {
  662. enum {RECT, ELLIPSE} shape;
  663. CvScalar color;
  664. };
  665. /*extern const CvDrawShape icv_shape[] =
  666. {
  667. { CvDrawShape::ELLIPSE, CV_RGB(255,0,0) },
  668. { CvDrawShape::ELLIPSE, CV_RGB(0,255,0) },
  669. { CvDrawShape::ELLIPSE, CV_RGB(0,0,255) },
  670. { CvDrawShape::ELLIPSE, CV_RGB(255,255,0) },
  671. { CvDrawShape::ELLIPSE, CV_RGB(0,255,255) },
  672. { CvDrawShape::ELLIPSE, CV_RGB(255,0,255) }
  673. };*/
  674. class CV_EXPORTS CvImageDrawer
  675. {
  676. public:
  677. CvImageDrawer() : m_image(0) {}
  678. ~CvImageDrawer() { cvReleaseImage( &m_image ); }
  679. void SetShapes( const CvDrawShape* shapes, int num );
  680. /* <blob_seq> must be the sequence of <CvDetectedBlob>s */
  681. IplImage* Draw( const CvArr* src, CvBlobSeq* blob_seq = 0, const CvSeq* roi_seq = 0 );
  682. IplImage* GetImage() { return m_image; }
  683. protected:
  684. //static const int MAX_SHAPES = sizeof(icv_shape) / sizeof(icv_shape[0]);;
  685. IplImage* m_image;
  686. CvDrawShape m_shape[16];
  687. };
  688. /* Trajectory generation module */
  689. class CV_EXPORTS CvBlobTrackGen: public CvVSModule
  690. {
  691. public:
  692. virtual void SetFileName(char* pFileName) = 0;
  693. virtual void AddBlob(CvBlob* pBlob) = 0;
  694. virtual void Process(IplImage* pImg = NULL, IplImage* pFG = NULL) = 0;
  695. virtual void Release() = 0;
  696. };
  697. inline void cvReleaseBlobTrackGen(CvBlobTrackGen** pBTGen)
  698. {
  699. if(*pBTGen)(*pBTGen)->Release();
  700. *pBTGen = 0;
  701. }
  702. /* declaration of constructors of implemented modules */
  703. CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGen1();
  704. CV_EXPORTS CvBlobTrackGen* cvCreateModuleBlobTrackGenYML();
  705. /* BLOB TRACKER INTERFACE */
  706. class CV_EXPORTS CvBlobTracker: public CvVSModule
  707. {
  708. public:
  709. CvBlobTracker(){SetTypeName("BlobTracker");};
  710. /* Add new blob to track it and assign to this blob personal ID */
  711. /* pBlob - pinter to structure with blob parameters (ID is ignored)*/
  712. /* pImg - current image */
  713. /* pImgFG - current foreground mask */
  714. /* return pointer to new added blob */
  715. virtual CvBlob* AddBlob(CvBlob* pBlob, IplImage* pImg, IplImage* pImgFG = NULL ) = 0;
  716. /* return number of currently tracked blobs */
  717. virtual int GetBlobNum() = 0;
  718. /* return pointer to specified by index blob */
  719. virtual CvBlob* GetBlob(int BlobIndex) = 0;
  720. /* delete blob by its index */
  721. virtual void DelBlob(int BlobIndex) = 0;
  722. /* process current image and track all existed blobs */
  723. virtual void Process(IplImage* pImg, IplImage* pImgFG = NULL) = 0;
  724. /* release blob tracker */
  725. virtual void Release() = 0;
  726. /* Process on blob (for multi hypothesis tracing) */
  727. virtual void ProcessBlob(int BlobIndex, CvBlob* pBlob, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
  728. {
  729. CvBlob* pB;
  730. int ID = 0;
  731. assert(pBlob);
  732. //pBlob->ID;
  733. pB = GetBlob(BlobIndex);
  734. if(pB)
  735. pBlob[0] = pB[0];
  736. pBlob->ID = ID;
  737. };
  738. /* get confidence/wieght/probability (0-1) for blob */
  739. virtual double GetConfidence(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL)
  740. {
  741. return 1;
  742. };
  743. virtual double GetConfidenceList(CvBlobSeq* pBlobList, IplImage* pImg, IplImage* pImgFG = NULL)
  744. {
  745. int b,bN = pBlobList->GetBlobNum();
  746. double W = 1;
  747. for(b=0;b<bN;++b)
  748. {
  749. CvBlob* pB = pBlobList->GetBlob(b);
  750. int BI = GetBlobIndexByID(pB->ID);
  751. W *= GetConfidence(BI,pB,pImg,pImgFG);
  752. }
  753. return W;
  754. };
  755. virtual void UpdateBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
  756. /* update all blob models */
  757. virtual void Update(IplImage* pImg, IplImage* pImgFG = NULL)
  758. {
  759. int i;
  760. for(i=GetBlobNum();i>0;i--)
  761. {
  762. CvBlob* pB=GetBlob(i-1);
  763. UpdateBlob(i-1, pB, pImg, pImgFG);
  764. }
  765. };
  766. /* return pinter to blob by its unique ID */
  767. virtual int GetBlobIndexByID(int BlobID)
  768. {
  769. int i;
  770. for(i=GetBlobNum();i>0;i--)
  771. {
  772. CvBlob* pB=GetBlob(i-1);
  773. if(CV_BLOB_ID(pB) == BlobID) return i-1;
  774. }
  775. return -1;
  776. };
  777. /* return pinter to blob by its unique ID */
  778. virtual CvBlob* GetBlobByID(int BlobID){return GetBlob(GetBlobIndexByID(BlobID));};
  779. /* delete blob by its ID */
  780. virtual void DelBlobByID(int BlobID){DelBlob(GetBlobIndexByID(BlobID));};
  781. /* Set new parameters for specified (by index) blob */
  782. virtual void SetBlob(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
  783. /* Set new parameters for specified (by ID) blob */
  784. virtual void SetBlobByID(int BlobID, CvBlob* pBlob)
  785. {
  786. SetBlob(GetBlobIndexByID(BlobID),pBlob);
  787. };
  788. /* =============== MULTI HYPOTHESIS INTERFACE ================== */
  789. /* return number of position hyposetis of currently tracked blob */
  790. virtual int GetBlobHypNum(int /*BlobIdx*/){return 1;};
  791. /* return pointer to specified blob hypothesis by index blob */
  792. virtual CvBlob* GetBlobHyp(int BlobIndex, int /*hypothesis*/){return GetBlob(BlobIndex);};
  793. /* Set new parameters for specified (by index) blob hyp (can be called several times for each hyp )*/
  794. virtual void SetBlobHyp(int /*BlobIndex*/, CvBlob* /*pBlob*/){};
  795. };
  796. inline void cvReleaseBlobTracker(CvBlobTracker**ppT )
  797. {
  798. ppT[0]->Release();
  799. ppT[0] = 0;
  800. }
  801. /* BLOB TRACKER INTERFACE */
  802. /*BLOB TRACKER ONE INTERFACE */
  803. class CV_EXPORTS CvBlobTrackerOne:public CvVSModule
  804. {
  805. public:
  806. virtual void Init(CvBlob* pBlobInit, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
  807. virtual CvBlob* Process(CvBlob* pBlobPrev, IplImage* pImg, IplImage* pImgFG = NULL) = 0;
  808. virtual void Release() = 0;
  809. /*not required methods */
  810. virtual void SkipProcess(CvBlob* /*pBlobPrev*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
  811. virtual void Update(CvBlob* /*pBlob*/, IplImage* /*pImg*/, IplImage* /*pImgFG*/ = NULL){};
  812. virtual void SetCollision(int /*CollisionFlag*/){}; /* call in case of blob collision situation*/
  813. virtual double GetConfidence(CvBlob* /*pBlob*/, IplImage* /*pImg*/,
  814. IplImage* /*pImgFG*/ = NULL, IplImage* /*pImgUnusedReg*/ = NULL)
  815. {
  816. return 1;
  817. };
  818. };
  819. inline void cvReleaseBlobTrackerOne(CvBlobTrackerOne **ppT )
  820. {
  821. ppT[0]->Release();
  822. ppT[0] = 0;
  823. }
  824. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerList(CvBlobTrackerOne* (*create)());
  825. /*BLOB TRACKER ONE INTERFACE */
  826. /* declaration of constructors of implemented modules */
  827. /* some declaration for specific MeanShift tracker */
  828. #define PROFILE_EPANECHNIKOV 0
  829. #define PROFILE_DOG 1
  830. struct CvBlobTrackerParamMS
  831. {
  832. int noOfSigBits;
  833. int appearance_profile;
  834. int meanshift_profile;
  835. float sigma;
  836. };
  837. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1(CvBlobTrackerParamMS* param);
  838. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS2(CvBlobTrackerParamMS* param);
  839. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS1ByList();
  840. /* some declaration for specific Liklyhood tracker */
  841. struct CvBlobTrackerParamLH
  842. {
  843. int HistType; /* see Prob.h */
  844. int ScaleAfter;
  845. };
  846. /* no scale optimization */
  847. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHR(CvBlobTrackerParamLH* /*param*/ = NULL);
  848. /* scale optimization */
  849. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerLHRS(CvBlobTrackerParamLH* /*param*/ = NULL);
  850. /* simple blob tracker based on connected component tracking */
  851. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCC();
  852. /* connected component tracking and MSPF resolver for collision */
  853. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerCCMSPF();
  854. /* blob tracker that integrate MS and CC */
  855. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFG();
  856. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSFGS();
  857. /* MS without CC */
  858. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMS();
  859. /* particle filtering using bahata... coefficient */
  860. CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerMSPF();
  861. /* =========== tracker integrators trackers =============*/
  862. /* integrator based on Partical Filtering method */
  863. //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPF();
  864. /* rule based integrator */
  865. //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIRB();
  866. /* integrator based on data fusion used particle filtering */
  867. //CV_EXPORTS CvBlobTracker* cvCreateBlobTrackerIPFDF();
  868. /* Trajectory postprocessing module */
  869. class CV_EXPORTS CvBlobTrackPostProc: public CvVSModule
  870. {
  871. public:
  872. virtual void AddBlob(CvBlob* pBlob) = 0;
  873. virtual void Process() = 0;
  874. virtual int GetBlobNum() = 0;
  875. virtual CvBlob* GetBlob(int index) = 0;
  876. virtual void Release() = 0;
  877. /* additional functionality */
  878. virtual CvBlob* GetBlobByID(int BlobID)
  879. {
  880. int i;
  881. for(i=GetBlobNum();i>0;i--)
  882. {
  883. CvBlob* pB=GetBlob(i-1);
  884. if(pB->ID==BlobID) return pB;
  885. }
  886. return NULL;
  887. };
  888. };
  889. inline void cvReleaseBlobTrackPostProc(CvBlobTrackPostProc** pBTPP)
  890. {
  891. if(pBTPP == NULL) return;
  892. if(*pBTPP)(*pBTPP)->Release();
  893. *pBTPP = 0;
  894. }
  895. /* Trajectory generation module */
  896. class CV_EXPORTS CvBlobTrackPostProcOne: public CvVSModule
  897. {
  898. public:
  899. virtual CvBlob* Process(CvBlob* pBlob) = 0;
  900. virtual void Release() = 0;
  901. };
  902. /* create blob traking post processing module based on simle module */
  903. CV_EXPORTS CvBlobTrackPostProc* cvCreateBlobTrackPostProcList(CvBlobTrackPostProcOne* (*create)());
  904. /* declaration of constructors of implemented modules */
  905. CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcKalman();
  906. CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverRect();
  907. CV_EXPORTS CvBlobTrackPostProc* cvCreateModuleBlobTrackPostProcTimeAverExp();
  908. /* PREDICTORS */
  909. /* blob PREDICTOR */
  910. class CvBlobTrackPredictor: public CvVSModule
  911. {
  912. public:
  913. virtual CvBlob* Predict() = 0;
  914. virtual void Update(CvBlob* pBlob) = 0;
  915. virtual void Release() = 0;
  916. };
  917. CV_EXPORTS CvBlobTrackPredictor* cvCreateModuleBlobTrackPredictKalman();
  918. /* Trajectory analyser module */
  919. class CV_EXPORTS CvBlobTrackAnalysis: public CvVSModule
  920. {
  921. public:
  922. virtual void AddBlob(CvBlob* pBlob) = 0;
  923. virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
  924. virtual float GetState(int BlobID) = 0;
  925. /* return 0 if trajectory is normal
  926. return >0 if trajectory abnormal */
  927. virtual char* GetStateDesc(int /*BlobID*/){return NULL;};
  928. virtual void SetFileName(char* /*DataBaseName*/){};
  929. virtual void Release() = 0;
  930. };
  931. inline void cvReleaseBlobTrackAnalysis(CvBlobTrackAnalysis** pBTPP)
  932. {
  933. if(pBTPP == NULL) return;
  934. if(*pBTPP)(*pBTPP)->Release();
  935. *pBTPP = 0;
  936. }
  937. /* feature vector generation module */
  938. class CV_EXPORTS CvBlobTrackFVGen : public CvVSModule
  939. {
  940. public:
  941. virtual void AddBlob(CvBlob* pBlob) = 0;
  942. virtual void Process(IplImage* pImg, IplImage* pFG) = 0;
  943. virtual void Release() = 0;
  944. virtual int GetFVSize() = 0;
  945. virtual int GetFVNum() = 0;
  946. virtual float* GetFV(int index, int* pFVID) = 0; /* pointer to FV, if return 0 then FV does not created */
  947. virtual float* GetFVVar(){return NULL;}; /* returned pointer to array of variation of values of FV, if return 0 then FVVar is not exist */
  948. virtual float* GetFVMin() = 0; /* returned pointer to array of minimal values of FV, if return 0 then FVrange is not exist */
  949. virtual float* GetFVMax() = 0; /* returned pointer to array of maximal values of FV, if return 0 then FVrange is not exist */
  950. };
  951. /* Trajectory Analyser module */
  952. class CV_EXPORTS CvBlobTrackAnalysisOne
  953. {
  954. public:
  955. virtual ~CvBlobTrackAnalysisOne() {};
  956. virtual int Process(CvBlob* pBlob, IplImage* pImg, IplImage* pFG) = 0;
  957. /* return 0 if trajectory is normal
  958. return >0 if trajectory abnormal */
  959. virtual void Release() = 0;
  960. };
  961. /* create blob traking post processing module based on simle module */
  962. CV_EXPORTS CvBlobTrackAnalysis* cvCreateBlobTrackAnalysisList(CvBlobTrackAnalysisOne* (*create)());
  963. /* declaration of constructors of implemented modules */
  964. /* based on histogramm analysis of 2D FV (x,y)*/
  965. CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistP();
  966. /* based on histogramm analysis of 4D FV (x,y,vx,vy)*/
  967. CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPV();
  968. /* based on histogramm analysis of 5D FV (x,y,vx,vy,state)*/
  969. CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistPVS();
  970. /* based on histogramm analysis of 4D FV (startpos,stoppos)*/
  971. CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisHistSS();
  972. /* based on SVM classifier analysis of 2D FV (x,y)*/
  973. //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMP();
  974. /* based on SVM classifier analysis of 4D FV (x,y,vx,vy)*/
  975. //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPV();
  976. /* based on SVM classifier analysis of 5D FV (x,y,vx,vy,state)*/
  977. //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMPVS();
  978. /* based on SVM classifier analysis of 4D FV (startpos,stoppos)*/
  979. //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisSVMSS();
  980. /* track analysis based on distance between tracks */
  981. CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisTrackDist();
  982. /* analizer based on reation Road and height map*/
  983. //CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysis3DRoadMap();
  984. /* analizer that make OR desicion using set of analizers */
  985. CV_EXPORTS CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR();
  986. /* estimator of human height */
  987. class CV_EXPORTS CvBlobTrackAnalysisHeight: public CvBlobTrackAnalysis
  988. {
  989. public:
  990. virtual double GetHeight(CvBlob* pB) = 0;
  991. };
  992. //CV_EXPORTS CvBlobTrackAnalysisHeight* cvCreateModuleBlobTrackAnalysisHeightScale();
  993. /* AUTO BLOB TRACKER INTERFACE - pipeline of 3 modules */
  994. class CV_EXPORTS CvBlobTrackerAuto: public CvVSModule
  995. {
  996. public:
  997. virtual void Process(IplImage* pImg, IplImage* pMask = NULL) = 0;
  998. virtual CvBlob* GetBlob(int index) = 0;
  999. virtual CvBlob* GetBlobByID(int ID) = 0;
  1000. virtual int GetBlobNum() = 0;
  1001. virtual IplImage* GetFGMask(){return NULL;};
  1002. virtual float GetState(int BlobID) = 0;
  1003. virtual char* GetStateDesc(int BlobID) = 0;
  1004. /* return 0 if trajectory is normal
  1005. return >0 if trajectory abnormal */
  1006. virtual void Release() = 0;
  1007. };
  1008. inline void cvReleaseBlobTrackerAuto(CvBlobTrackerAuto** ppT)
  1009. {
  1010. ppT[0]->Release();
  1011. ppT[0] = 0;
  1012. }
  1013. /* END AUTO BLOB TRACKER INTERFACE */
  1014. /* creation function and data for specific BlobTRackerAuto modules */
  1015. /* parameters of blobtracker auto ver1 */
  1016. struct CvBlobTrackerAutoParam1
  1017. {
  1018. int FGTrainFrames; /* number of frames are needed for FG detector to train */
  1019. CvFGDetector* pFG; /* FGDetector module, if this filed is NULL the Process FG mask is used */
  1020. CvBlobDetector* pBD; /* existed blob detector module
  1021. if this filed is NULL default blobdetector module will be created */
  1022. CvBlobTracker* pBT; /* existed blob tracking module
  1023. if this filed is NULL default blobtracker module will be created */
  1024. CvBlobTrackGen* pBTGen; /* existed blob trajectory generator,
  1025. if this filed is NULL no any generator is used */
  1026. CvBlobTrackPostProc* pBTPP; /* existed blob trajectory postprocessing module
  1027. if this filed is NULL no any postprocessing is used */
  1028. int UsePPData;
  1029. CvBlobTrackAnalysis* pBTA; /* existed blob trajectory analysis module */
  1030. /* if this filed is NULL no any analysis is made */
  1031. };
  1032. /* create blob tracker auto ver1 */
  1033. CV_EXPORTS CvBlobTrackerAuto* cvCreateBlobTrackerAuto1(CvBlobTrackerAutoParam1* param = NULL);
  1034. /* simple loader for many auto trackers by its type */
  1035. inline CvBlobTrackerAuto* cvCreateBlobTrackerAuto(int type, void* param)
  1036. {
  1037. if(type == 0) return cvCreateBlobTrackerAuto1((CvBlobTrackerAutoParam1*)param);
  1038. return 0;
  1039. }
  1040. struct CvTracksTimePos
  1041. {
  1042. int len1,len2;
  1043. int beg1,beg2;
  1044. int end1,end2;
  1045. int comLen; //common length for two tracks
  1046. int shift1,shift2;
  1047. };
  1048. /*CV_EXPORTS int cvCompareTracks( CvBlobTrackSeq *groundTruth,
  1049. CvBlobTrackSeq *result,
  1050. FILE *file);*/
  1051. /* Create functions */
  1052. CV_EXPORTS void cvCreateTracks_One(CvBlobTrackSeq *TS);
  1053. CV_EXPORTS void cvCreateTracks_Same(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2);
  1054. CV_EXPORTS void cvCreateTracks_AreaErr(CvBlobTrackSeq *TS1, CvBlobTrackSeq *TS2, int addW, int addH);
  1055. /* HIST API */
  1056. class CV_EXPORTS CvProb
  1057. {
  1058. public:
  1059. virtual ~CvProb() {};
  1060. /* calculate probability value */
  1061. virtual double Value(int* /*comp*/, int /*x*/ = 0, int /*y*/ = 0){return -1;};
  1062. /* update histograpp Pnew = (1-W)*Pold + W*Padd*/
  1063. /* W weight of new added prob */
  1064. /* comps - matrix of new fetature vectors used to update prob */
  1065. virtual void AddFeature(float W, int* comps, int x =0, int y = 0) = 0;
  1066. virtual void Scale(float factor = 0, int x = -1, int y = -1) = 0;
  1067. virtual void Release() = 0;
  1068. };
  1069. inline void cvReleaseProb(CvProb** ppProb){ppProb[0]->Release();ppProb[0]=NULL;}
  1070. /* HIST API */
  1071. /* some Prob */
  1072. CV_EXPORTS CvProb* cvCreateProbS(int dim, CvSize size, int sample_num);
  1073. CV_EXPORTS CvProb* cvCreateProbMG(int dim, CvSize size, int sample_num);
  1074. CV_EXPORTS CvProb* cvCreateProbMG2(int dim, CvSize size, int sample_num);
  1075. CV_EXPORTS CvProb* cvCreateProbHist(int dim, CvSize size);
  1076. #define CV_BT_HIST_TYPE_S 0
  1077. #define CV_BT_HIST_TYPE_MG 1
  1078. #define CV_BT_HIST_TYPE_MG2 2
  1079. #define CV_BT_HIST_TYPE_H 3
  1080. inline CvProb* cvCreateProb(int type, int dim, CvSize size = cvSize(1,1), void* /*param*/ = NULL)
  1081. {
  1082. if(type == CV_BT_HIST_TYPE_S) return cvCreateProbS(dim, size, -1);
  1083. if(type == CV_BT_HIST_TYPE_MG) return cvCreateProbMG(dim, size, -1);
  1084. if(type == CV_BT_HIST_TYPE_MG2) return cvCreateProbMG2(dim, size, -1);
  1085. if(type == CV_BT_HIST_TYPE_H) return cvCreateProbHist(dim, size);
  1086. return NULL;
  1087. }
  1088. /* noise types defenition */
  1089. #define CV_NOISE_NONE 0
  1090. #define CV_NOISE_GAUSSIAN 1
  1091. #define CV_NOISE_UNIFORM 2
  1092. #define CV_NOISE_SPECKLE 3
  1093. #define CV_NOISE_SALT_AND_PEPPER 4
  1094. /* Add some noise to image */
  1095. /* pImg - (input) image without noise */
  1096. /* pImg - (output) image with noise */
  1097. /* noise_type - type of added noise */
  1098. /* CV_NOISE_GAUSSIAN - pImg += n , n - is gaussian noise with Ampl standart deviation */
  1099. /* CV_NOISE_UNIFORM - pImg += n , n - is uniform noise with Ampl standart deviation */
  1100. /* CV_NOISE_SPECKLE - pImg += n*pImg , n - is gaussian noise with Ampl standart deviation */
  1101. /* CV_NOISE_SALT_AND_PAPPER - pImg = pImg with blacked and whited pixels,
  1102. Ampl is density of brocken pixels (0-there are not broken pixels, 1 - all pixels are broken)*/
  1103. /* Ampl - "amplitude" of noise */
  1104. CV_EXPORTS void cvAddNoise(IplImage* pImg, int noise_type, double Ampl, CvRandState* rnd_state = NULL);
  1105. /*================== GENERATOR OF TEST VIDEO SEQUENCE ===================== */
  1106. typedef void CvTestSeq;
  1107. /* pConfigfile - name of file (yml or xml) with description of test sequence */
  1108. /* videos - array of names of test videos described in "pConfigfile" file */
  1109. /* numvideos - size of "videos" array */
  1110. CV_EXPORTS CvTestSeq* cvCreateTestSeq(char* pConfigfile, char** videos, int numvideo, float Scale = 1, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
  1111. CV_EXPORTS void cvReleaseTestSeq(CvTestSeq** ppTestSeq);
  1112. /* generete next frame from test video seq and return pointer to it */
  1113. CV_EXPORTS IplImage* cvTestSeqQueryFrame(CvTestSeq* pTestSeq);
  1114. /* return pointer to current foreground mask */
  1115. CV_EXPORTS IplImage* cvTestSeqGetFGMask(CvTestSeq* pTestSeq);
  1116. /* return pointer to current image */
  1117. CV_EXPORTS IplImage* cvTestSeqGetImage(CvTestSeq* pTestSeq);
  1118. /* return frame size of result test video */
  1119. CV_EXPORTS CvSize cvTestSeqGetImageSize(CvTestSeq* pTestSeq);
  1120. /* return number of frames result test video */
  1121. CV_EXPORTS int cvTestSeqFrameNum(CvTestSeq* pTestSeq);
  1122. /* return number of existed objects
  1123. this is general number of any objects.
  1124. for example number of trajectories may be equal or less than returned value*/
  1125. CV_EXPORTS int cvTestSeqGetObjectNum(CvTestSeq* pTestSeq);
  1126. /* return 0 if there is not position for current defined on current frame */
  1127. /* return 1 if there is object position and pPos was filled */
  1128. CV_EXPORTS int cvTestSeqGetObjectPos(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pPos);
  1129. CV_EXPORTS int cvTestSeqGetObjectSize(CvTestSeq* pTestSeq, int ObjIndex, CvPoint2D32f* pSize);
  1130. /* add noise to finile image */
  1131. CV_EXPORTS void cvTestSeqAddNoise(CvTestSeq* pTestSeq, int noise_type = CV_NOISE_NONE, double noise_ampl = 0);
  1132. /* add Intensity variation */
  1133. CV_EXPORTS void cvTestSeqAddIntensityVariation(CvTestSeq* pTestSeq, float DI_per_frame, float MinI, float MaxI);
  1134. CV_EXPORTS void cvTestSeqSetFrame(CvTestSeq* pTestSeq, int n);
  1135. #endif
  1136. /* End of file. */