Skip to content

Commit f4fdd94

Browse files
committed
Merge pull request opencv#7976 from StevenPuttemans:fix_opencv_annotation_tool
2 parents 65598e4 + 46fa9a6 commit f4fdd94

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

apps/annotation/opencv_annotation.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ Adapted by: Puttemans Steven - April 2016 - Vectorize the process to enable bett
5959

6060
#include <fstream>
6161
#include <iostream>
62-
63-
#if defined(_WIN32)
64-
#include <direct.h>
65-
#else
66-
#include <sys/stat.h>
67-
#endif
62+
#include <map>
6863

6964
using namespace std;
7065
using namespace cv;
@@ -249,34 +244,20 @@ int main( int argc, const char** argv )
249244
int resizeFactor = parser.get<int>("resizeFactor");
250245
int const maxWindowHeight = parser.get<int>("maxWindowHeight") > 0 ? parser.get<int>("maxWindowHeight") : -1;
251246

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-
273247
// Start by processing the data
274248
// Return the image filenames inside the image folder
275-
vector< vector<Rect> > annotations;
249+
map< String, vector<Rect> > annotations;
276250
vector<String> filenames;
277251
String folder(image_folder);
278252
glob(folder, filenames);
279253

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+
280261
// Loop through each image stored in the images folder
281262
// Create and temporarily store the annotations
282263
// At the end write everything to the annotations file
@@ -306,7 +287,7 @@ int main( int argc, const char** argv )
306287
current_annotations[j].height = current_annotations[j].height * resizeFactor;
307288
}
308289
}
309-
annotations.push_back(current_annotations);
290+
annotations[filenames[i]] = current_annotations;
310291

311292
// Check if the ESC key was hit, then exit earlier then expected
312293
if(stop){
@@ -323,10 +304,11 @@ int main( int argc, const char** argv )
323304
}
324305

325306
// 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];
330312
output << " " << temp.x << " " << temp.y << " " << temp.width << " " << temp.height;
331313
}
332314
output << endl;

0 commit comments

Comments
 (0)