Merge pull request #7020 from StevenPuttemans:add_scale_option

This commit is contained in:
Vadim Pisarevsky 2016-08-04 13:37:29 +00:00
commit 35d0a45df6

View File

@ -229,6 +229,8 @@ int main( int argc, const char** argv )
"{ help h usage ? | | show this message }" "{ help h usage ? | | show this message }"
"{ images i | | (required) path to image folder [example - /data/testimages/] }" "{ images i | | (required) path to image folder [example - /data/testimages/] }"
"{ annotations a | | (required) path to annotations txt file [example - /data/annotations.txt] }" "{ 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 // Read in the input arguments
if (parser.has("help")){ if (parser.has("help")){
@ -244,6 +246,9 @@ int main( int argc, const char** argv )
return -1; return -1;
} }
int resizeFactor = parser.get<int>("resizeFactor");
int const maxWindowHeight = parser.get<int>("maxWindowHeight") > 0 ? parser.get<int>("maxWindowHeight") : -1;
// Check if the folder actually exists // Check if the folder actually exists
// If -1 is returned then the folder actually exists, and thus you can continue // 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 // 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++){ for (size_t i = 0; i < filenames.size(); i++){
// Read in an image // Read in an image
Mat current_image = imread(filenames[i]); 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 // 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 // If not then simply skip this iteration
@ -285,8 +291,21 @@ int main( int argc, const char** argv )
continue; 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 // 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<Rect> current_annotations = get_annotations(current_image); vector<Rect> 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); annotations.push_back(current_annotations);
// Check if the ESC key was hit, then exit earlier then expected // Check if the ESC key was hit, then exit earlier then expected