| 198 | } |
| 199 | |
| 200 | void convert_pascal_xml( |
| 201 | const command_line_parser& parser |
| 202 | ) |
| 203 | { |
| 204 | cout << "Convert from PASCAL XML annotation format..." << endl; |
| 205 | |
| 206 | dlib::image_dataset_metadata::dataset dataset; |
| 207 | |
| 208 | std::string name; |
| 209 | dlib::image_dataset_metadata::image img; |
| 210 | |
| 211 | const std::string filename = parser.option("c").argument(); |
| 212 | // make sure the file exists so we can use the get_parent_directory() command to |
| 213 | // figure out it's parent directory. |
| 214 | make_empty_file(filename); |
| 215 | const std::string parent_dir = get_parent_directory(file(filename)).full_name(); |
| 216 | |
| 217 | for (unsigned long i = 0; i < parser.number_of_arguments(); ++i) |
| 218 | { |
| 219 | try |
| 220 | { |
| 221 | parse_annotation_file(parser[i], img, name); |
| 222 | const string root = get_parent_directory(get_parent_directory(file(parser[i]))).full_name(); |
| 223 | const string img_path = root + directory::get_separator() + "JPEGImages" + directory::get_separator(); |
| 224 | |
| 225 | dataset.name = name; |
| 226 | img.filename = strip_path(img_path + img.filename, parent_dir); |
| 227 | dataset.images.push_back(img); |
| 228 | |
| 229 | } |
| 230 | catch (exception& ) |
| 231 | { |
| 232 | cout << "Error while processing file " << parser[i] << endl << endl; |
| 233 | throw; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | save_image_dataset_metadata(dataset, filename); |
| 238 | } |
| 239 |
no test coverage detected