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