Skip to content

Commit

Permalink
Added --rmtrunc, made --rmdiff mark a box as ignored rather than
Browse files Browse the repository at this point in the history
totally removing it, and also made --stats print the number of non-ignored
boxes.
  • Loading branch information
davisking committed Jul 5, 2015
1 parent d6cd6a2 commit 11e0382
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions tools/imglab/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void print_all_label_stats (
std::map<std::string, running_stats<double> > area_stats, aspect_ratio;
std::map<std::string, int> image_hits;
std::set<std::string> labels;
unsigned long num_unignored_boxes = 0;
for (unsigned long i = 0; i < data.images.size(); ++i)
{
std::set<std::string> temp;
Expand All @@ -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());
aspect_ratio[data.images[i].boxes[j].label].add(data.images[i].boxes[j].rect.width()/
(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
Expand All @@ -190,7 +194,8 @@ void print_all_label_stats (
}

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)
{
Expand Down Expand Up @@ -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("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);
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("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 "
Expand All @@ -483,7 +489,7 @@ int main(int argc, char** 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"};
parser.check_one_time_options(singles);
const char* c_sub_ops[] = {"r", "convert"};
Expand All @@ -493,6 +499,7 @@ int main(int argc, char** argv)
parser.check_sub_options(size_parent_ops, "size");
parser.check_incompatible_options("c", "l");
parser.check_incompatible_options("c", "rmdiff");
parser.check_incompatible_options("c", "rmtrunc");
parser.check_incompatible_options("c", "add");
parser.check_incompatible_options("c", "flip");
parser.check_incompatible_options("c", "rotate");
Expand Down Expand Up @@ -520,6 +527,7 @@ int main(int argc, char** argv)
parser.check_incompatible_options("convert", "parts");
parser.check_incompatible_options("convert", "cluster");
parser.check_incompatible_options("rmdiff", "rename");
parser.check_incompatible_options("rmtrunc", "rename");
const char* convert_args[] = {"pascal-xml","pascal-v1","idl"};
parser.check_option_arg_range("convert", convert_args);
parser.check_option_arg_range("cluster", 2, 999);
Expand Down Expand Up @@ -601,13 +609,39 @@ int main(int argc, char** argv)
load_image_dataset_metadata(data, parser[0]);
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)
{
if (!data.images[i].boxes[j].difficult)
boxes.push_back(data.images[i].boxes[j]);
if (data.images[i].boxes[j].difficult)
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]);
return EXIT_SUCCESS;
Expand Down

0 comments on commit 11e0382

Please sign in to comment.