@@ -59,12 +59,7 @@ Adapted by: Puttemans Steven - April 2016 - Vectorize the process to enable bett
59
59
60
60
#include < fstream>
61
61
#include < iostream>
62
-
63
- #if defined(_WIN32)
64
- #include < direct.h>
65
- #else
66
- #include < sys/stat.h>
67
- #endif
62
+ #include < map>
68
63
69
64
using namespace std ;
70
65
using namespace cv ;
@@ -249,34 +244,20 @@ int main( int argc, const char** argv )
249
244
int resizeFactor = parser.get <int >(" resizeFactor" );
250
245
int const maxWindowHeight = parser.get <int >(" maxWindowHeight" ) > 0 ? parser.get <int >(" maxWindowHeight" ) : -1 ;
251
246
252
- // Check if the folder actually exists
253
- // If -1 is returned then the folder actually exists, and thus you can continue
254
- // In all other cases there was a folder creation and thus the folder did not exist
255
- #if defined(_WIN32)
256
- if (_mkdir (image_folder.c_str ()) != -1 ){
257
- // Generate an error message
258
- cerr << " The image folder given does not exist. Please check again!" << endl;
259
- // Remove the created folder again, to ensure a second run with same code fails again
260
- _rmdir (image_folder.c_str ());
261
- return 0 ;
262
- }
263
- #else
264
- if (mkdir (image_folder.c_str (), 0777 ) != -1 ){
265
- // Generate an error message
266
- cerr << " The image folder given does not exist. Please check again!" << endl;
267
- // Remove the created folder again, to ensure a second run with same code fails again
268
- remove (image_folder.c_str ());
269
- return 0 ;
270
- }
271
- #endif
272
-
273
247
// Start by processing the data
274
248
// Return the image filenames inside the image folder
275
- vector< vector<Rect> > annotations;
249
+ map< String, vector<Rect> > annotations;
276
250
vector<String> filenames;
277
251
String folder (image_folder);
278
252
glob (folder, filenames);
279
253
254
+ // Add key tips on how to use the software when running it
255
+ cout << " * mark rectangles with the left mouse button," << endl;
256
+ cout << " * press 'c' to accept a selection," << endl;
257
+ cout << " * press 'd' to delete the latest selection," << endl;
258
+ cout << " * press 'n' to proceed with next image," << endl;
259
+ cout << " * press 'esc' to stop." << endl;
260
+
280
261
// Loop through each image stored in the images folder
281
262
// Create and temporarily store the annotations
282
263
// At the end write everything to the annotations file
@@ -306,7 +287,7 @@ int main( int argc, const char** argv )
306
287
current_annotations[j].height = current_annotations[j].height * resizeFactor;
307
288
}
308
289
}
309
- annotations. push_back ( current_annotations) ;
290
+ annotations[filenames[i]] = current_annotations;
310
291
311
292
// Check if the ESC key was hit, then exit earlier then expected
312
293
if (stop){
@@ -323,10 +304,11 @@ int main( int argc, const char** argv )
323
304
}
324
305
325
306
// Store the annotations, write to the output file
326
- for (int i = 0 ; i < (int )annotations.size (); i++){
327
- output << filenames[i] << " " << annotations[i].size ();
328
- for (int j=0 ; j < (int )annotations[i].size (); j++){
329
- Rect temp = annotations[i][j];
307
+ for (map<String, vector<Rect> >::iterator it = annotations.begin (); it != annotations.end (); it++){
308
+ vector<Rect> &anno = it->second ;
309
+ output << it->first << " " << anno.size ();
310
+ for (size_t j=0 ; j < anno.size (); j++){
311
+ Rect temp = anno[j];
330
312
output << " " << temp.x << " " << temp.y << " " << temp.width << " " << temp.height ;
331
313
}
332
314
output << endl;
0 commit comments