| 36 | // ---------------------------------------------------------------------------------------- |
| 37 | |
| 38 | int main(int argc, char** argv) try |
| 39 | { |
| 40 | if (argc != 2) |
| 41 | { |
| 42 | cout << "You call this program like this: " << endl; |
| 43 | cout << "./dnn_instance_segmentation_train_ex /path/to/images" << endl; |
| 44 | cout << endl; |
| 45 | cout << "You will also need a trained '" << instance_segmentation_net_filename << "' file." << endl; |
| 46 | cout << "You can either train it yourself (see example program" << endl; |
| 47 | cout << "dnn_instance_segmentation_train_ex), or download a" << endl; |
| 48 | cout << "copy from here: http://dlib.net/files/" << instance_segmentation_net_filename << endl; |
| 49 | return 1; |
| 50 | } |
| 51 | |
| 52 | // Read the file containing the trained networks from the working directory. |
| 53 | det_anet_type det_net; |
| 54 | std::map<std::string, seg_bnet_type> seg_nets_by_class; |
| 55 | deserialize(instance_segmentation_net_filename) >> det_net >> seg_nets_by_class; |
| 56 | |
| 57 | // Show inference results in a window. |
| 58 | image_window win; |
| 59 | |
| 60 | matrix<rgb_pixel> input_image; |
| 61 | |
| 62 | // Find supported image files. |
| 63 | const std::vector<file> files = dlib::get_files_in_directory_tree(argv[1], |
| 64 | dlib::match_endings(".jpeg .jpg .png .webp")); |
| 65 | |
| 66 | dlib::rand rnd; |
| 67 | |
| 68 | cout << "Found " << files.size() << " images, processing..." << endl; |
| 69 | |
| 70 | for (const file& file : files) |
| 71 | { |
| 72 | // Load the input image. |
| 73 | load_image(input_image, file.full_name()); |
| 74 | |
| 75 | // Find instances in the input image |
| 76 | const auto instances = det_net(input_image); |
| 77 | |
| 78 | matrix<rgb_pixel> rgb_label_image; |
| 79 | matrix<float> label_image_confidence; |
| 80 | |
| 81 | matrix<rgb_pixel> input_chip; |
| 82 | |
| 83 | rgb_label_image.set_size(input_image.nr(), input_image.nc()); |
| 84 | rgb_label_image = rgb_pixel(0, 0, 0); |
| 85 | |
| 86 | label_image_confidence.set_size(input_image.nr(), input_image.nc()); |
| 87 | label_image_confidence = 0.0; |
| 88 | |
| 89 | bool found_something = false; |
| 90 | |
| 91 | for (const auto& instance : instances) |
| 92 | { |
| 93 | if (!found_something) |
| 94 | { |
| 95 | cout << "Found "; |
nothing calls this directly
no test coverage detected