From d8698fc3599c2ddc30cb66f0c6734eb5771c3f67 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Mon, 1 Aug 2016 15:19:07 +0200 Subject: [PATCH] allow for screen size related resizing --- apps/annotation/opencv_annotation.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/annotation/opencv_annotation.cpp b/apps/annotation/opencv_annotation.cpp index 1bd22a298c..febe9fc95d 100644 --- a/apps/annotation/opencv_annotation.cpp +++ b/apps/annotation/opencv_annotation.cpp @@ -229,6 +229,8 @@ int main( int argc, const char** argv ) "{ help h usage ? | | show this message }" "{ images i | | (required) path to image folder [example - /data/testimages/] }" "{ annotations a | | (required) path to annotations txt file [example - /data/annotations.txt] }" + "{ maxWindowHeight m | -1 | (optional) images larger in height than this value will be scaled down }" + "{ resizeFactor r | 2 | (optional) factor for scaling down [default = half the size] }" ); // Read in the input arguments if (parser.has("help")){ @@ -244,6 +246,9 @@ int main( int argc, const char** argv ) return -1; } + 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 @@ -278,6 +283,7 @@ int main( int argc, const char** argv ) for (size_t i = 0; i < filenames.size(); i++){ // Read in an image Mat current_image = imread(filenames[i]); + bool const resize_bool = (maxWindowHeight > 0) && (current_image.rows > maxWindowHeight); // Check if the image is actually read - avoid other files in the folder, because glob() takes them all // If not then simply skip this iteration @@ -285,8 +291,21 @@ int main( int argc, const char** argv ) continue; } + if(resize_bool){ + resize(current_image, current_image, Size(current_image.cols/resizeFactor, current_image.rows/resizeFactor)); + } + // Perform annotations & store the result inside the vectorized structure + // If the image was resized before, then resize the found annotations back to original dimensions vector current_annotations = get_annotations(current_image); + if(resize_bool){ + for(int j =0; j < (int)current_annotations.size(); j++){ + current_annotations[j].x = current_annotations[j].x * resizeFactor; + current_annotations[j].y = current_annotations[j].y * resizeFactor; + current_annotations[j].width = current_annotations[j].width * resizeFactor; + current_annotations[j].height = current_annotations[j].height * resizeFactor; + } + } annotations.push_back(current_annotations); // Check if the ESC key was hit, then exit earlier then expected