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);
69 printf("WARNING!!! Can not open %s file for trajectories writing",m_pFileName);
72 for(i=0;i<1024 && m_pFileName[i]!='.' && m_pFileName[i]!=0;++i)video_name[i]=m_pFileName[i];
76 if(video_name[i-1] == '\\') break;
77 if(video_name[i-1] == '/') break;
78 if(video_name[i-1] == ':') break;
80 struct_name = video_name + i;
82 cvStartWriteStruct(storage, struct_name, CV_NODE_SEQ);
86 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i);
87 if(pTrack==NULL) continue;
88 sprintf(obj_name,"%s_obj%d",struct_name,i);
89 cvStartWriteStruct(storage, NULL, CV_NODE_MAP);
90 cvWriteInt(storage, "FrameBegin", pTrack->FrameBegin);
91 cvWriteString(storage, "VideoObj", obj_name);
92 cvEndWriteStruct( storage );
95 cvEndWriteStruct( storage );
100 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i);
101 CvBlobSeq* pSeq = pTrack->pSeq;
102 sprintf(obj_name,"%s_obj%d",struct_name,i);
103 cvStartWriteStruct(storage, obj_name, CV_NODE_MAP);
108 cvStartWriteStruct(storage, "Pos", CV_NODE_SEQ|CV_NODE_FLOW);
109 for(j=0;j<pSeq->GetBlobNum();++j)
111 CvBlob* pB = pSeq->GetBlob(j);
112 p.x = pB->x/(m_Size.width-1);
113 p.y = pB->y/(m_Size.height-1);
114 cvWriteRawData(storage, &p, 1 ,"ff");
116 cvEndWriteStruct( storage );
122 cvStartWriteStruct(storage, "Size", CV_NODE_SEQ|CV_NODE_FLOW);
123 for(j=0;j<pSeq->GetBlobNum();++j)
125 CvBlob* pB = pSeq->GetBlob(j);
126 p.x = pB->w/(m_Size.width-1);
127 p.y = pB->h/(m_Size.height-1);
128 cvWriteRawData(storage, &p, 1 ,"ff");
130 cvEndWriteStruct( storage );
132 cvEndWriteStruct( storage );
134 cvReleaseFileStorage(&storage);
137 CvBlobTrackGenYML():m_TrackList(sizeof(DefBlobTrack))
141 m_Size = cvSize(2,2);
147 for(i=m_TrackList.GetBlobNum();i>0;--i)
149 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i-1);
150 /* delete sequence */
153 }/* check next track */
156 void SetFileName(char* pFileName){m_pFileName = pFileName;};
157 void AddBlob(CvBlob* pBlob)
159 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlobByID(CV_BLOB_ID(pBlob));
163 Track.blob = pBlob[0];
164 Track.FrameBegin = m_Frame;
165 Track.pSeq = new CvBlobSeq;
167 m_TrackList.AddBlob((CvBlob*)&Track);
168 pTrack = (DefBlobTrack*)m_TrackList.GetBlobByID(CV_BLOB_ID(pBlob));
172 pTrack->FrameLast = m_Frame;
173 assert(pTrack->pSeq);
174 pTrack->pSeq->AddBlob(pBlob);
176 void Process(IplImage* pImg = NULL, IplImage* /*pFG*/ = NULL)
179 m_Size = cvSize(pImg->width,pImg->height);
180 for(i=m_TrackList.GetBlobNum();i>0;--i)
182 DefBlobTrack* pTrack = (DefBlobTrack*)m_TrackList.GetBlob(i-1);
183 if(pTrack->FrameLast < m_Frame && !pTrack->Saved)
187 }/* check next track */
194 }; /* class CvBlobTrackGenYML */
197 CvBlobTrackGen* cvCreateModuleBlobTrackGenYML()
199 return (CvBlobTrackGen*) new CvBlobTrackGenYML;