| 31 | // ---------------------------------------------------------------------------------------- |
| 32 | |
| 33 | void create_new_dataset ( |
| 34 | const command_line_parser& parser |
| 35 | ) |
| 36 | { |
| 37 | using namespace dlib::image_dataset_metadata; |
| 38 | |
| 39 | const std::string filename = parser.option("c").argument(); |
| 40 | // make sure the file exists so we can use the get_parent_directory() command to |
| 41 | // figure out it's parent directory. |
| 42 | make_empty_file(filename); |
| 43 | const std::string parent_dir = get_parent_directory(file(filename)); |
| 44 | |
| 45 | unsigned long depth = 0; |
| 46 | if (parser.option("r")) |
| 47 | depth = 30; |
| 48 | |
| 49 | dataset meta; |
| 50 | meta.name = "imglab dataset"; |
| 51 | meta.comment = "Created by imglab tool."; |
| 52 | for (unsigned long i = 0; i < parser.number_of_arguments(); ++i) |
| 53 | { |
| 54 | try |
| 55 | { |
| 56 | const string temp = strip_path(file(parser[i]), parent_dir); |
| 57 | meta.images.push_back(image(temp)); |
| 58 | } |
| 59 | catch (dlib::file::file_not_found&) |
| 60 | { |
| 61 | // then parser[i] should be a directory |
| 62 | |
| 63 | std::vector<file> files = get_files_in_directory_tree(parser[i], |
| 64 | match_endings(".png .PNG .jpeg .JPEG .jpg .JPG .bmp .BMP .dng .DNG .gif .GIF .jxl .JXL .webp .WEBP"), |
| 65 | depth); |
| 66 | sort(files.begin(), files.end()); |
| 67 | |
| 68 | for (unsigned long j = 0; j < files.size(); ++j) |
| 69 | { |
| 70 | meta.images.push_back(image(strip_path(files[j], parent_dir))); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | save_image_dataset_metadata(meta, filename); |
| 76 | } |
| 77 | |
| 78 | // ---------------------------------------------------------------------------------------- |
| 79 |
no test coverage detected