@@ -46,186 +46,185 @@ using namespace std;
4646namespace cv
4747{
4848
49- namespace datasets
50- {
51-
52- class TRACK_votImpl : public TRACK_vot
53- {
54- public:
55- // Constructor
56- TRACK_votImpl ()
49+ namespace datasets
5750 {
5851
59- activeDatasetID = 1 ;
60- frameCounter = 0 ;
61- }
62- // Destructor
63- virtual ~TRACK_votImpl () {}
52+ class TRACK_votImpl : public TRACK_vot
53+ {
54+ public:
55+ // Constructor
56+ TRACK_votImpl ()
57+ {
6458
65- // Load Dataset
66- virtual void load (const string &path);
59+ activeDatasetID = 1 ;
60+ frameCounter = 0 ;
61+ }
62+ // Destructor
63+ virtual ~TRACK_votImpl () {}
6764
68- virtual int getDatasetsNum ();
65+ // Load Dataset
66+ virtual void load (const string &path);
6967
70- virtual int getDatasetLength ( int id );
68+ virtual int getDatasetsNum ( );
7169
72- virtual bool initDataset (int id);
70+ virtual int getDatasetLength (int id);
7371
74- virtual bool getNextFrame (Mat &frame );
72+ virtual bool initDataset ( int id );
7573
76- virtual vector <Point2d> getGT ( );
74+ virtual bool getNextFrame (Mat &frame );
7775
78- private:
79- void loadDataset (const string &path);
76+ virtual vector <Point2d> getGT ();
8077
81- string numberToString ( int number);
82- } ;
78+ private:
79+ void loadDataset ( const string &path) ;
8380
84- void TRACK_votImpl::load (const string &path)
85- {
86- loadDataset (path);
87- }
81+ string numberToString (int number);
82+ };
8883
89- string TRACK_votImpl::numberToString (int number)
90- {
91- string out;
92- char numberStr[9 ];
93- sprintf (numberStr, " %u" , number);
94- for (unsigned int i=0 ; i<8 -strlen (numberStr); ++i)
95- {
96- out += " 0" ;
97- }
98- out += numberStr;
99- return out;
100- }
101-
102- inline bool fileExists (const std::string& name)
103- {
104- struct stat buffer;
105- return (stat (name.c_str (), &buffer) == 0 );
106- }
84+ void TRACK_votImpl::load (const string &path)
85+ {
86+ loadDataset (path);
87+ }
10788
108- void TRACK_votImpl::loadDataset (const string &rootPath)
109- {
110- ifstream namesList (rootPath + " /list.txt" );
111- // ifstream lengthsList(rootPath + "/lengths.txt");
112- vector <int > datasetsLengths;
113- string datasetName;
89+ string TRACK_votImpl::numberToString (int number)
90+ {
91+ string out;
92+ char numberStr[9 ];
93+ sprintf (numberStr, " %u" , number);
94+ for (unsigned int i = 0 ; i < 8 - strlen (numberStr); ++i)
95+ {
96+ out += " 0" ;
97+ }
98+ out += numberStr;
99+ return out;
100+ }
114101
115- if (namesList.is_open ())
116- {
117- int currDatasetID = 0 ;
102+ inline bool fileExists (const std::string& name)
103+ {
104+ struct stat buffer;
105+ return (stat (name.c_str (), &buffer) == 0 );
106+ }
118107
119- // All datasets/folders loop
120- while (getline (namesList, datasetName))
108+ void TRACK_votImpl::loadDataset (const string &rootPath)
121109 {
122- currDatasetID++;
123- vector <Ptr<TRACK_votObj> > objects;
110+ ifstream namesList (rootPath + " /list.txt" );
111+ // ifstream lengthsList(rootPath + "/lengths.txt");
112+ vector <int > datasetsLengths;
113+ string datasetName;
124114
125- // All frames/images loop
126- Ptr<TRACK_votObj> currDataset (new TRACK_votObj);
115+ if (namesList.is_open ())
116+ {
117+ int currDatasetID = 0 ;
118+
119+ // All datasets/folders loop
120+ while (getline (namesList, datasetName))
121+ {
122+ currDatasetID++;
123+ vector <Ptr<TRACK_votObj> > objects;
124+
125+ // All frames/images loop
126+ Ptr<TRACK_votObj> currDataset (new TRACK_votObj);
127+
128+ // Open dataset's ground truth file
129+ ifstream gtList (rootPath + " /" + datasetName + " /groundtruth.txt" );
130+ if (!gtList.is_open ())
131+ cout << " Error to open groundtruth.txt!!!" ;
132+
133+ // Make a list of datasets lengths
134+ int currFrameID = 1 ;
135+ if (currDatasetID == 0 )
136+ cout << " VOT 2015 Dataset Initialization...\n " ;
137+
138+ do
139+ {
140+ currFrameID++;
141+ string fullPath = rootPath + " /" + datasetName + " /" + numberToString (currFrameID) + " .jpg" ;
142+ if (!fileExists (fullPath))
143+ break ;
144+
145+ // Make VOT Object
146+ Ptr<TRACK_votObj> currObj (new TRACK_votObj);
147+ currObj->imagePath = fullPath;
148+ currObj->id = currFrameID;
149+
150+ // Get Ground Truth data
151+ double x1 = 0 , y1 = 0 ,
152+ x2 = 0 , y2 = 0 ,
153+ x3 = 0 , y3 = 0 ,
154+ x4 = 0 , y4 = 0 ;
155+ string tmp;
156+ getline (gtList, tmp);
157+ sscanf (tmp.c_str (), " %lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf" , &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
158+ currObj->gtbb .push_back (Point2d (x1, y1));
159+ currObj->gtbb .push_back (Point2d (x2, y2));
160+ currObj->gtbb .push_back (Point2d (x3, y3));
161+ currObj->gtbb .push_back (Point2d (x4, y4));
162+
163+ // Add object to storage
164+ objects.push_back (currObj);
165+
166+ } while (true );
167+
168+ datasetsLengths.push_back (currFrameID - 1 );
169+ data.push_back (objects);
170+ }
171+ }
172+ else
173+ {
174+ cout << rootPath + " Couldn't find a *list.txt* in VOT 2015 folder!!!" ;
175+ }
127176
128- // Open dataset's ground truth file
129- ifstream gtList (rootPath + " /" + datasetName + " /groundtruth.txt" );
130- if (!gtList.is_open ())
131- cout << " Error to open groundtruth.txt!!!" ;
177+ namesList.close ();
178+ return ;
179+ }
132180
133- // Make a list of datasets lengths
134- int currFrameID = 1 ;
135- if (currDatasetID == 0 )
136- cout << " VOT 2015 Dataset Initialization... \n " ;
181+ int TRACK_votImpl::getDatasetsNum ()
182+ {
183+ return data. size ();
184+ }
137185
138- do
186+ int TRACK_votImpl::getDatasetLength (int id)
187+ {
188+ if (id > 0 && id <= (int )data.size ())
189+ return data[id - 1 ].size ();
190+ else
139191 {
140- currFrameID++;
141- string fullPath = rootPath + " /" + datasetName + " /" + numberToString (currFrameID) + " .jpg" ;
142- if (!fileExists (fullPath))
143- break ;
144-
145- // Make VOT Object
146- Ptr<TRACK_votObj> currObj (new TRACK_votObj);
147- currObj->imagePath = fullPath;
148- currObj->id = currFrameID;
149-
150- // Get Ground Truth data
151- double x1 = 0 , y1 = 0 ,
152- x2 = 0 , y2 = 0 ,
153- x3 = 0 , y3 = 0 ,
154- x4 = 0 , y4 = 0 ;
155- string tmp;
156- getline (gtList, tmp);
157- sscanf (tmp.c_str (), " %lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf" , &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
158- currObj->gtbb .push_back (Point2d (x1, y1));
159- currObj->gtbb .push_back (Point2d (x2, y2));
160- currObj->gtbb .push_back (Point2d (x3, y3));
161- currObj->gtbb .push_back (Point2d (x4, y4));
162-
163- // Add object to storage
164- objects.push_back (currObj);
165-
166- } while (true );
167-
168- datasetsLengths.push_back (currFrameID-1 );
169- data.push_back (objects);
192+ cout << " Dataset ID is out of range...\n " << " Allowed IDs are: 1~" << (int )data.size () << endl;
193+ return -1 ;
194+ }
170195 }
171- }
172- else
173- {
174- cout << rootPath + " Couldn't find a *list.txt* in VOT 2015 folder!!!" ;
175- }
176-
177- namesList.close ();
178- return ;
179- }
180196
181- int TRACK_votImpl::getDatasetsNum ()
182- {
183- return data.size ();
184- }
185-
186- int TRACK_votImpl::getDatasetLength (int id)
187- {
188- if (id > 0 && id <= (int )data.size ())
189- return data[id - 1 ].size ();
190- else
191- {
192- cout << " Dataset ID is out of range...\n " << " Allowed IDs are: 1~" << (int )data.size () << endl;
193- return -1 ;
194- }
195- }
196-
197- bool TRACK_votImpl::initDataset (int id)
198- {
199- if (id > 0 && id <= (int )data.size ())
200- {
201- activeDatasetID = id;
202- return true ;
203- }
204- else
205- {
206- cout << " Dataset ID is out of range...\n " << " Allowed IDs are: 1~" << (int )data.size () << endl;
207- return false ;
208- }
209- }
197+ bool TRACK_votImpl::initDataset (int id)
198+ {
199+ if (id > 0 && id <= (int )data.size ())
200+ {
201+ activeDatasetID = id;
202+ return true ;
203+ }
204+ else
205+ {
206+ cout << " Dataset ID is out of range...\n " << " Allowed IDs are: 1~" << (int )data.size () << endl;
207+ return false ;
208+ }
209+ }
210210
211- bool TRACK_votImpl::getNextFrame (Mat &frame)
212- {
213- frame = imread (data[activeDatasetID - 1 ][frameCounter]->imagePath );
214- frameCounter++;
215- return !frame.empty ();
216- }
211+ bool TRACK_votImpl::getNextFrame (Mat &frame)
212+ {
213+ frame = imread (data[activeDatasetID - 1 ][frameCounter]->imagePath );
214+ frameCounter++;
215+ return !frame.empty ();
216+ }
217217
218- Ptr<TRACK_vot> TRACK_vot::create ()
219- {
220- return Ptr<TRACK_votImpl>(new TRACK_votImpl);
221- }
218+ Ptr<TRACK_vot> TRACK_vot::create ()
219+ {
220+ return Ptr<TRACK_votImpl>(new TRACK_votImpl);
221+ }
222222
223- vector <Point2d> TRACK_votImpl::getGT ()
224- {
225- Ptr <TRACK_votObj> currObj = data[activeDatasetID - 1 ][frameCounter - 1 ];
226- return currObj->gtbb ;
227- }
223+ vector <Point2d> TRACK_votImpl::getGT ()
224+ {
225+ Ptr <TRACK_votObj> currObj = data[activeDatasetID - 1 ][frameCounter - 1 ];
226+ return currObj->gtbb ;
227+ }
228228
229+ }
229230}
230- }
231-
0 commit comments