| 531 | // ---------------------------------------------------------------------------------------- |
| 532 | |
| 533 | int tile_dataset(const command_line_parser& parser) |
| 534 | { |
| 535 | if (parser.number_of_arguments() != 1) |
| 536 | { |
| 537 | cerr << "The --tile option requires you to give one XML file on the command line." << endl; |
| 538 | return EXIT_FAILURE; |
| 539 | } |
| 540 | |
| 541 | string out_image = parser.option("tile").argument(); |
| 542 | string ext = right_substr(out_image,"."); |
| 543 | if (ext != "png" && ext != "jpg" |
| 544 | #if DLIB_JXL_SUPPORT |
| 545 | && ext != "jxl" |
| 546 | #endif |
| 547 | #if DLIB_WEBP_SUPPORT |
| 548 | && ext != "webp" |
| 549 | #endif |
| 550 | ) |
| 551 | { |
| 552 | cerr << "The output image file must have one of these extensions: .png, .jpg" << endl; |
| 553 | #if DLIB_JXL_SUPPORT |
| 554 | cerr << ", .jxl"; |
| 555 | #endif |
| 556 | #if DLIB_WEBP_SUPPORT |
| 557 | cerr << ", .webp"; |
| 558 | #endif |
| 559 | cerr << "."; |
| 560 | return EXIT_FAILURE; |
| 561 | } |
| 562 | |
| 563 | const unsigned long chip_size = get_option(parser, "size", 8000); |
| 564 | |
| 565 | dlib::image_dataset_metadata::dataset data; |
| 566 | load_image_dataset_metadata(data, parser[0]); |
| 567 | locally_change_current_dir chdir(get_parent_directory(file(parser[0]))); |
| 568 | dlib::array<array2d<rgb_pixel> > images; |
| 569 | console_progress_indicator pbar(data.images.size()); |
| 570 | for (unsigned long i = 0; i < data.images.size(); ++i) |
| 571 | { |
| 572 | // don't even bother loading images that don't have objects. |
| 573 | if (data.images[i].boxes.size() == 0) |
| 574 | continue; |
| 575 | |
| 576 | pbar.print_status(i); |
| 577 | array2d<rgb_pixel> img; |
| 578 | load_image(img, data.images[i].filename); |
| 579 | |
| 580 | // figure out what chips we want to take from this image |
| 581 | std::vector<chip_details> dets; |
| 582 | for (unsigned long j = 0; j < data.images[i].boxes.size(); ++j) |
| 583 | { |
| 584 | if (data.images[i].boxes[j].ignore) |
| 585 | continue; |
| 586 | |
| 587 | rectangle rect = data.images[i].boxes[j].rect; |
| 588 | dets.push_back(chip_details(rect, chip_size)); |
| 589 | } |
| 590 | // Now grab all those chips at once. |
no test coverage detected