| 130 | // ---------------------------------------------------------------------------------------- |
| 131 | |
| 132 | void bind_image_dataset_metadata(py::module &m_) |
| 133 | { |
| 134 | auto m = m_.def_submodule("image_dataset_metadata", "Routines and objects for working with dlib's image dataset metadata XML files."); |
| 135 | |
| 136 | auto datasetstr = [](const dataset& item) { return "dlib.dataset_dataset_metadata.dataset: images:" + to_string(item.images.size()) + ", " + item.name; }; |
| 137 | auto datasetrepr = [datasetstr](const dataset& item) { return "<"+datasetstr(item)+">"; }; |
| 138 | py::class_<dataset>(m, "dataset", |
| 139 | "This object represents a labeled set of images. In particular, it contains the filename for each image as well as annotated boxes.") |
| 140 | .def(py::init()) |
| 141 | .def("__str__", datasetstr) |
| 142 | .def("__repr__", datasetrepr) |
| 143 | .def_readwrite("images", &dataset::images) |
| 144 | .def_readwrite("comment", &dataset::comment) |
| 145 | .def_readwrite("name", &dataset::name); |
| 146 | |
| 147 | auto imagestr = [](const image& item) { return "dlib.image_dataset_metadata.image: boxes:"+to_string(item.boxes.size())+ ", " + item.filename; }; |
| 148 | auto imagerepr = [imagestr](const image& item) { return "<"+imagestr(item)+">"; }; |
| 149 | py::class_<image>(m, "image", "This object represents an annotated image.") |
| 150 | .def(py::init()) |
| 151 | .def_readwrite("filename", &image::filename) |
| 152 | .def("__str__", imagestr) |
| 153 | .def("__repr__", imagerepr) |
| 154 | .def_readwrite("boxes", &image::boxes); |
| 155 | |
| 156 | auto imagesstr = [imagerepr](const std::vector<image>& images) |
| 157 | { |
| 158 | std::ostringstream sout; |
| 159 | for (size_t i = 0; i < images.size(); ++i) |
| 160 | { |
| 161 | if (i == 0) |
| 162 | sout << "[" << imagerepr(images[i]) << ",\n"; |
| 163 | else if (i+1 == images.size()) |
| 164 | sout << " " << imagerepr(images[i]) << "]"; |
| 165 | else |
| 166 | sout << " " << imagerepr(images[i]) << ",\n"; |
| 167 | } |
| 168 | return sout.str(); |
| 169 | }; |
| 170 | py::bind_vector<std::vector<image>>(m, "images", "An array of dlib::image_dataset_metadata::image objects.") |
| 171 | .def("__str__", imagesstr) |
| 172 | .def("__repr__", imagesstr); |
| 173 | |
| 174 | auto partsstr = [](const std::map<std::string,point>& item) { |
| 175 | std::ostringstream sout; |
| 176 | sout << "{"; |
| 177 | for (const auto& v : item) |
| 178 | sout << "'" << v.first << "': " << v.second << ", "; |
| 179 | sout << "}"; |
| 180 | return sout.str(); |
| 181 | }; |
| 182 | auto partsrepr = [](const std::map<std::string,point>& item) { |
| 183 | std::ostringstream sout; |
| 184 | sout << "dlib.image_dataset_metadata.parts({\n"; |
| 185 | for (const auto& v : item) |
| 186 | sout << "'" << v.first << "': dlib.point" << v.second << ",\n"; |
| 187 | sout << "})"; |
| 188 | return sout.str(); |
| 189 | }; |