1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #include "precomp.hpp"
44 typedef struct DefBlobTrack
54 static void SaveTrack(DefBlobTrack* pTrack, char* pFileName, int norm = 0)
55 { /* Save blob track: */
58 CvBlobSeq* pS = pTrack->pSeq;
59 CvBlob* pB0 = pS?pS->GetBlob(0):NULL;
61 if(pFileName == NULL) return;
62 if(pTrack == NULL) return;
64 out = fopen(pFileName,"at");
67 printf("Warning! Cannot open %s file for track output\n", pFileName);
71 fprintf(out,"%d",pTrack->FrameBegin);
73 if(pS) for(j=0; j<pS->GetBlobNum(); ++j)
75 CvBlob* pB = pS->GetBlob(j);
77 fprintf(out,", %.1f, %.1f", CV_BLOB_X(pB),CV_BLOB_Y(pB));
80 fprintf(out,", %.2f",CV_BLOB_WX(pB)/(norm?CV_BLOB_WX(pB0):1));
83 fprintf(out,", %.2f",CV_BLOB_WY(pB)/(norm?CV_BLOB_WY(pB0):1));
88 } /* Save blob track. */
90 class CvBlobTrackGen1:public CvBlobTrackGen
94 CvBlobTrackGen1(int BlobSizeNorm = 0):m_TrackList(sizeof(DefBlobTrack))
96 m_BlobSizeNorm = BlobSizeNorm;
100 SetModuleName("Gen1");
106 for(i=m_TrackList.GetBlobNum();i>0;--i)
108 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i-1);
111 SaveTrack(pTrack, m_pFileName, m_BlobSizeNorm);
114 /* Delete sequence: */
119 } /* Check next track. */
122 void SetFileName(char* pFileName){m_pFileName = pFileName;}
124 void AddBlob(CvBlob* pBlob)
126 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlobByID(CV_BLOB_ID(pBlob));
129 { /* Add new track: */
131 Track.blob = pBlob[0];
132 Track.FrameBegin = m_Frame;
133 Track.pSeq = new CvBlobSeq;
135 m_TrackList.AddBlob((CvBlob*)&Track);
136 pTrack = (DefBlobTrack*)m_TrackList.GetBlobByID(CV_BLOB_ID(pBlob));
137 } /* Add new track. */
140 pTrack->FrameLast = m_Frame;
141 assert(pTrack->pSeq);
142 pTrack->pSeq->AddBlob(pBlob);
145 void Process(IplImage* /*pImg*/ = NULL, IplImage* /*pFG*/ = NULL)
149 for(i=m_TrackList.GetBlobNum(); i>0; --i)
151 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i-1);
153 if(pTrack->FrameLast < m_Frame && !pTrack->Saved)
155 SaveTrack(pTrack, m_pFileName, m_BlobSizeNorm);
157 { /* delete sequence */
160 m_TrackList.DelBlob(i-1);
163 } /* Check next track. */
175 CvBlobSeq m_TrackList;
177 }; /* class CvBlobTrackGen1 */
180 CvBlobTrackGen* cvCreateModuleBlobTrackGen1()
182 return (CvBlobTrackGen*) new CvBlobTrackGen1(0);