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
12 // Copyright (C) 2000, Intel Corporation, all rights reserved.
13 // Third party copyrights are property of their respective owners.
15 // Redistribution and use in source and binary forms, with or without modification,
16 // are permitted provided that the following conditions are met:
18 // * Redistribution's of source code must retain the above copyright notice,
19 // this list of conditions and the following disclaimer.
21 // * Redistribution's in binary form must reproduce the above copyright notice,
22 // this list of conditions and the following disclaimer in the documentation
23 // and/or other materials provided with the distribution.
25 // * The name of Intel Corporation may not be used to endorse or promote products
26 // derived from this software without specific prior written permission.
28 // This software is provided by the copyright holders and contributors "as is" and
29 // any express or implied warranties, including, but not limited to, the implied
30 // warranties of merchantability and fitness for a particular purpose are disclaimed.
31 // In no event shall the Intel Corporation or contributors be liable for any direct,
32 // indirect, incidental, special, exemplary, or consequential damages
33 // (including, but not limited to, procurement of substitute goods or services;
34 // loss of use, data, or profits; or business interruption) however caused
35 // and on any theory of liability, whether in contract, strict liability,
36 // or tort (including negligence or otherwise) arising in any way out of
37 // the use of this software, even if advised of the possibility of such damage.
43 typedef struct DefBlobTrack
52 class CvBlobTrackGenYML:public CvBlobTrackGen
57 CvBlobSeq m_TrackList;
62 int ObjNum = m_TrackList.GetBlobNum();
64 char video_name[1024];
65 char* struct_name = NULL;
66 CvFileStorage* storage = cvOpenFileStorage(m_pFileName,NULL,CV_STORAGE_WRITE_TEXT);
70 printf("WARNING!!! Cannot open %s file for trajectory output.", m_pFileName);
73 for(i=0; i<1024 && m_pFileName[i]!='.' && m_pFileName[i]!=0; ++i) video_name[i]=m_pFileName[i];
78 if(video_name[i-1] == '\\') break;
79 if(video_name[i-1] == '/') break;
80 if(video_name[i-1] == ':') break;
82 struct_name = video_name + i;
84 cvStartWriteStruct(storage, struct_name, CV_NODE_SEQ);
86 for(i=0; i<ObjNum; ++i)
89 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i);
90 if(pTrack==NULL) continue;
91 sprintf(obj_name,"%s_obj%d",struct_name,i);
92 cvStartWriteStruct(storage, NULL, CV_NODE_MAP);
93 cvWriteInt(storage, "FrameBegin", pTrack->FrameBegin);
94 cvWriteString(storage, "VideoObj", obj_name);
95 cvEndWriteStruct( storage );
98 cvEndWriteStruct( storage );
100 for(i=0;i<ObjNum;++i)
103 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i);
104 CvBlobSeq* pSeq = pTrack->pSeq;
105 sprintf(obj_name,"%s_obj%d",struct_name,i);
106 cvStartWriteStruct(storage, obj_name, CV_NODE_MAP);
108 { /* Write position: */
111 cvStartWriteStruct(storage, "Pos", CV_NODE_SEQ|CV_NODE_FLOW);
112 for(j=0;j<pSeq->GetBlobNum();++j)
114 CvBlob* pB = pSeq->GetBlob(j);
115 p.x = pB->x/(m_Size.width-1);
116 p.y = pB->y/(m_Size.height-1);
117 cvWriteRawData(storage, &p, 1 ,"ff");
119 cvEndWriteStruct( storage );
125 cvStartWriteStruct(storage, "Size", CV_NODE_SEQ|CV_NODE_FLOW);
127 for(j=0; j<pSeq->GetBlobNum(); ++j)
129 CvBlob* pB = pSeq->GetBlob(j);
130 p.x = pB->w/(m_Size.width-1);
131 p.y = pB->h/(m_Size.height-1);
132 cvWriteRawData(storage, &p, 1 ,"ff");
134 cvEndWriteStruct( storage );
136 cvEndWriteStruct( storage );
138 cvReleaseFileStorage(&storage);
143 CvBlobTrackGenYML():m_TrackList(sizeof(DefBlobTrack))
147 m_Size = cvSize(2,2);
155 for(i=m_TrackList.GetBlobNum(); i>0; --i)
157 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i-1);
158 /* Delete sequence: */
161 } /* Check next track. */
165 void SetFileName(char* pFileName){m_pFileName = pFileName;};
166 void AddBlob(CvBlob* pBlob)
168 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlobByID(CV_BLOB_ID(pBlob));
171 { /* Add new track: */
173 Track.blob = pBlob[0];
174 Track.FrameBegin = m_Frame;
175 Track.pSeq = new CvBlobSeq;
177 m_TrackList.AddBlob((CvBlob*)&Track);
178 pTrack = (DefBlobTrack*)m_TrackList.GetBlobByID(CV_BLOB_ID(pBlob));
179 } /* Add new track. */
182 pTrack->FrameLast = m_Frame;
183 assert(pTrack->pSeq);
184 pTrack->pSeq->AddBlob(pBlob);
186 void Process(IplImage* pImg = NULL, IplImage* /*pFG*/ = NULL)
189 m_Size = cvSize(pImg->width,pImg->height);
191 for(i=m_TrackList.GetBlobNum(); i>0; --i)
193 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i-1);
195 if(pTrack->FrameLast < m_Frame && !pTrack->Saved)
200 } /* Check next track. */
209 }; /* class CvBlobTrackGenYML */
212 CvBlobTrackGen* cvCreateModuleBlobTrackGenYML()
214 return (CvBlobTrackGen*) new CvBlobTrackGenYML;