Commit 11e03822 authored by Davis King's avatar Davis King

Added --rmtrunc, made --rmdiff mark a box as ignored rather than

totally removing it, and also made --stats print the number of non-ignored
boxes.
parent d6cd6a2a
...@@ -171,6 +171,7 @@ void print_all_label_stats ( ...@@ -171,6 +171,7 @@ void print_all_label_stats (
std::map<std::string, running_stats<double> > area_stats, aspect_ratio; std::map<std::string, running_stats<double> > area_stats, aspect_ratio;
std::map<std::string, int> image_hits; std::map<std::string, int> image_hits;
std::set<std::string> labels; std::set<std::string> labels;
unsigned long num_unignored_boxes = 0;
for (unsigned long i = 0; i < data.images.size(); ++i) for (unsigned long i = 0; i < data.images.size(); ++i)
{ {
std::set<std::string> temp; std::set<std::string> temp;
...@@ -182,6 +183,9 @@ void print_all_label_stats ( ...@@ -182,6 +183,9 @@ void print_all_label_stats (
area_stats[data.images[i].boxes[j].label].add(data.images[i].boxes[j].rect.area()); area_stats[data.images[i].boxes[j].label].add(data.images[i].boxes[j].rect.area());
aspect_ratio[data.images[i].boxes[j].label].add(data.images[i].boxes[j].rect.width()/ aspect_ratio[data.images[i].boxes[j].label].add(data.images[i].boxes[j].rect.width()/
(double)data.images[i].boxes[j].rect.height()); (double)data.images[i].boxes[j].rect.height());
if (!data.images[i].boxes[j].ignore)
++num_unignored_boxes;
} }
// count the number of images for each label // count the number of images for each label
...@@ -190,7 +194,8 @@ void print_all_label_stats ( ...@@ -190,7 +194,8 @@ void print_all_label_stats (
} }
cout << "Number of images: "<< data.images.size() << endl; cout << "Number of images: "<< data.images.size() << endl;
cout << "Number of different labels: "<< labels.size() << endl << endl; cout << "Number of different labels: "<< labels.size() << endl;
cout << "Number of non-ignored boxes: " << num_unignored_boxes << endl << endl;
for (std::set<std::string>::iterator i = labels.begin(); i != labels.end(); ++i) for (std::set<std::string>::iterator i = labels.begin(); i != labels.end(); ++i)
{ {
...@@ -463,7 +468,8 @@ int main(int argc, char** argv) ...@@ -463,7 +468,8 @@ int main(int argc, char** argv)
parser.add_option("rename", "Rename all labels of <arg1> to <arg2>.",2); parser.add_option("rename", "Rename all labels of <arg1> to <arg2>.",2);
parser.add_option("parts","The display will allow image parts to be labeled. The set of allowable parts " parser.add_option("parts","The display will allow image parts to be labeled. The set of allowable parts "
"is defined by <arg> which should be a space separated list of parts.",1); "is defined by <arg> which should be a space separated list of parts.",1);
parser.add_option("rmdiff","Remove boxes marked as difficult."); parser.add_option("rmdiff","Set the ignored flag to true for boxes marked as difficult.");
parser.add_option("rmtrunc","Set the ignored flag to true for boxes that are partially outside the image.");
parser.add_option("shuffle","Randomly shuffle the order of the images listed in file <arg>."); parser.add_option("shuffle","Randomly shuffle the order of the images listed in file <arg>.");
parser.add_option("seed", "When using --shuffle, set the random seed to the string <arg>.",1); parser.add_option("seed", "When using --shuffle, set the random seed to the string <arg>.",1);
parser.add_option("split", "Split the contents of an XML file into two separate files. One containing the " parser.add_option("split", "Split the contents of an XML file into two separate files. One containing the "
...@@ -483,7 +489,7 @@ int main(int argc, char** argv) ...@@ -483,7 +489,7 @@ int main(int argc, char** argv)
parser.parse(argc, argv); parser.parse(argc, argv);
const char* singles[] = {"h","c","r","l","convert","parts","rmdiff","seed", "shuffle", "split", "add", const char* singles[] = {"h","c","r","l","convert","parts","rmdiff", "rmtrunc","seed", "shuffle", "split", "add",
"flip", "rotate", "tile", "size", "cluster"}; "flip", "rotate", "tile", "size", "cluster"};
parser.check_one_time_options(singles); parser.check_one_time_options(singles);
const char* c_sub_ops[] = {"r", "convert"}; const char* c_sub_ops[] = {"r", "convert"};
...@@ -493,6 +499,7 @@ int main(int argc, char** argv) ...@@ -493,6 +499,7 @@ int main(int argc, char** argv)
parser.check_sub_options(size_parent_ops, "size"); parser.check_sub_options(size_parent_ops, "size");
parser.check_incompatible_options("c", "l"); parser.check_incompatible_options("c", "l");
parser.check_incompatible_options("c", "rmdiff"); parser.check_incompatible_options("c", "rmdiff");
parser.check_incompatible_options("c", "rmtrunc");
parser.check_incompatible_options("c", "add"); parser.check_incompatible_options("c", "add");
parser.check_incompatible_options("c", "flip"); parser.check_incompatible_options("c", "flip");
parser.check_incompatible_options("c", "rotate"); parser.check_incompatible_options("c", "rotate");
...@@ -520,6 +527,7 @@ int main(int argc, char** argv) ...@@ -520,6 +527,7 @@ int main(int argc, char** argv)
parser.check_incompatible_options("convert", "parts"); parser.check_incompatible_options("convert", "parts");
parser.check_incompatible_options("convert", "cluster"); parser.check_incompatible_options("convert", "cluster");
parser.check_incompatible_options("rmdiff", "rename"); parser.check_incompatible_options("rmdiff", "rename");
parser.check_incompatible_options("rmtrunc", "rename");
const char* convert_args[] = {"pascal-xml","pascal-v1","idl"}; const char* convert_args[] = {"pascal-xml","pascal-v1","idl"};
parser.check_option_arg_range("convert", convert_args); parser.check_option_arg_range("convert", convert_args);
parser.check_option_arg_range("cluster", 2, 999); parser.check_option_arg_range("cluster", 2, 999);
...@@ -601,13 +609,39 @@ int main(int argc, char** argv) ...@@ -601,13 +609,39 @@ int main(int argc, char** argv)
load_image_dataset_metadata(data, parser[0]); load_image_dataset_metadata(data, parser[0]);
for (unsigned long i = 0; i < data.images.size(); ++i) for (unsigned long i = 0; i < data.images.size(); ++i)
{ {
std::vector<dlib::image_dataset_metadata::box> boxes;
for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j) for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j)
{ {
if (!data.images[i].boxes[j].difficult) if (data.images[i].boxes[j].difficult)
boxes.push_back(data.images[i].boxes[j]); data.images[i].boxes[j].ignore = true;
}
}
save_image_dataset_metadata(data, parser[0]);
return EXIT_SUCCESS;
}
if (parser.option("rmtrunc"))
{
if (parser.number_of_arguments() != 1)
{
cerr << "The --rmtrunc option requires you to give one XML file on the command line." << endl;
return EXIT_FAILURE;
}
dlib::image_dataset_metadata::dataset data;
load_image_dataset_metadata(data, parser[0]);
{
locally_change_current_dir chdir(get_parent_directory(file(parser[0])));
for (unsigned long i = 0; i < data.images.size(); ++i)
{
array2d<unsigned char> img;
load_image(img, data.images[i].filename);
const rectangle area = get_rect(img);
for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j)
{
if (!area.contains(data.images[i].boxes[j].rect))
data.images[i].boxes[j].ignore = true;
}
} }
data.images[i].boxes = boxes;
} }
save_image_dataset_metadata(data, parser[0]); save_image_dataset_metadata(data, parser[0]);
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment