| 172 | // ---------------------------------------------------------------------------------------- |
| 173 | |
| 174 | int cluster_dataset( |
| 175 | const dlib::command_line_parser& parser |
| 176 | ) |
| 177 | { |
| 178 | // make sure the user entered an argument to this program |
| 179 | if (parser.number_of_arguments() != 1) |
| 180 | { |
| 181 | cerr << "The --cluster option requires you to give one XML file on the command line." << endl; |
| 182 | return EXIT_FAILURE; |
| 183 | } |
| 184 | |
| 185 | unsigned long num_clusters = get_option(parser, "cluster", 0); |
| 186 | const unsigned long chip_size = get_option(parser, "size", 8000); |
| 187 | |
| 188 | image_dataset_metadata::dataset data; |
| 189 | |
| 190 | image_dataset_metadata::load_image_dataset_metadata(data, parser[0]); |
| 191 | set_current_dir(get_parent_directory(file(parser[0]))); |
| 192 | |
| 193 | const double aspect_ratio = mean_aspect_ratio(data); |
| 194 | |
| 195 | dlib::array<array2d<rgb_pixel> > images; |
| 196 | std::vector<matrix<double,0,1> > feats; |
| 197 | console_progress_indicator pbar(data.images.size()); |
| 198 | // extract all the object chips and HOG features. |
| 199 | cout << "Loading image data..." << endl; |
| 200 | for (unsigned long i = 0; i < data.images.size(); ++i) |
| 201 | { |
| 202 | pbar.print_status(i); |
| 203 | if (!has_non_ignored_boxes(data.images[i])) |
| 204 | continue; |
| 205 | |
| 206 | array2d<rgb_pixel> img, chip; |
| 207 | load_image(img, data.images[i].filename); |
| 208 | |
| 209 | for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j) |
| 210 | { |
| 211 | if (data.images[i].boxes[j].ignore || data.images[i].boxes[j].rect.area() < 10) |
| 212 | continue; |
| 213 | drectangle rect = data.images[i].boxes[j].rect; |
| 214 | rect = set_aspect_ratio(rect, aspect_ratio); |
| 215 | extract_image_chip(img, chip_details(rect, chip_size), chip); |
| 216 | feats.push_back(extract_fhog_features(chip)); |
| 217 | images.push_back(chip); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if (feats.size() == 0) |
| 222 | { |
| 223 | cerr << "No non-ignored object boxes found in the XML dataset. You can't cluster an empty dataset." << endl; |
| 224 | return EXIT_FAILURE; |
| 225 | } |
| 226 | |
| 227 | cout << "\nClustering objects..." << endl; |
| 228 | std::vector<assignment> assignments; |
| 229 | if (num_clusters) { |
| 230 | assignments = angular_cluster(feats, num_clusters); |
| 231 | } else { |
no test coverage detected