From 46fa9a6bd4be75dd5af6c2295b8f940675327ee1 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Fri, 6 Jan 2017 11:19:47 +0100 Subject: [PATCH] fix some issues with skipping files and old redundant code --- apps/annotation/opencv_annotation.cpp | 48 +++++++++------------------ 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/apps/annotation/opencv_annotation.cpp b/apps/annotation/opencv_annotation.cpp index febe9fc95d07..5d1eedeccd53 100644 --- a/apps/annotation/opencv_annotation.cpp +++ b/apps/annotation/opencv_annotation.cpp @@ -59,12 +59,7 @@ Adapted by: Puttemans Steven - April 2016 - Vectorize the process to enable bett #include #include - -#if defined(_WIN32) - #include -#else - #include -#endif +#include using namespace std; using namespace cv; @@ -249,34 +244,20 @@ int main( int argc, const char** argv ) int resizeFactor = parser.get("resizeFactor"); int const maxWindowHeight = parser.get("maxWindowHeight") > 0 ? parser.get("maxWindowHeight") : -1; - // Check if the folder actually exists - // If -1 is returned then the folder actually exists, and thus you can continue - // In all other cases there was a folder creation and thus the folder did not exist - #if defined(_WIN32) - if(_mkdir(image_folder.c_str()) != -1){ - // Generate an error message - cerr << "The image folder given does not exist. Please check again!" << endl; - // Remove the created folder again, to ensure a second run with same code fails again - _rmdir(image_folder.c_str()); - return 0; - } - #else - if(mkdir(image_folder.c_str(), 0777) != -1){ - // Generate an error message - cerr << "The image folder given does not exist. Please check again!" << endl; - // Remove the created folder again, to ensure a second run with same code fails again - remove(image_folder.c_str()); - return 0; - } - #endif - // Start by processing the data // Return the image filenames inside the image folder - vector< vector > annotations; + map< String, vector > annotations; vector filenames; String folder(image_folder); glob(folder, filenames); + // Add key tips on how to use the software when running it + cout << "* mark rectangles with the left mouse button," << endl; + cout << "* press 'c' to accept a selection," << endl; + cout << "* press 'd' to delete the latest selection," << endl; + cout << "* press 'n' to proceed with next image," << endl; + cout << "* press 'esc' to stop." << endl; + // Loop through each image stored in the images folder // Create and temporarily store the annotations // At the end write everything to the annotations file @@ -306,7 +287,7 @@ int main( int argc, const char** argv ) current_annotations[j].height = current_annotations[j].height * resizeFactor; } } - annotations.push_back(current_annotations); + annotations[filenames[i]] = current_annotations; // Check if the ESC key was hit, then exit earlier then expected if(stop){ @@ -323,10 +304,11 @@ int main( int argc, const char** argv ) } // Store the annotations, write to the output file - for(int i = 0; i < (int)annotations.size(); i++){ - output << filenames[i] << " " << annotations[i].size(); - for(int j=0; j < (int)annotations[i].size(); j++){ - Rect temp = annotations[i][j]; + for(map >::iterator it = annotations.begin(); it != annotations.end(); it++){ + vector &anno = it->second; + output << it->first << " " << anno.size(); + for(size_t j=0; j < anno.size(); j++){ + Rect temp = anno[j]; output << " " << temp.x << " " << temp.y << " " << temp.width << " " << temp.height; } output << endl;