| 188 | // ---------------------------------------------------------------------------------------- |
| 189 | |
| 190 | void flip_dataset(const command_line_parser& parser) |
| 191 | { |
| 192 | image_dataset_metadata::dataset metadata, orig_metadata; |
| 193 | string datasource; |
| 194 | if (parser.option("flip")) |
| 195 | datasource = parser.option("flip").argument(); |
| 196 | else |
| 197 | datasource = parser.option("flip-basic").argument(); |
| 198 | load_image_dataset_metadata(metadata,datasource); |
| 199 | orig_metadata = metadata; |
| 200 | |
| 201 | const string metadata_filename = get_parent_directory(file(datasource)).full_name() + |
| 202 | directory::get_separator() + "flipped_" + file(datasource).name(); |
| 203 | |
| 204 | // Set the current directory to be the one that contains the |
| 205 | // metadata file. We do this because the file might contain |
| 206 | // file paths which are relative to this folder. |
| 207 | set_current_dir(get_parent_directory(file(datasource))); |
| 208 | |
| 209 | array2d<rgb_pixel> img, temp; |
| 210 | for (unsigned long i = 0; i < metadata.images.size(); ++i) |
| 211 | { |
| 212 | file f(metadata.images[i].filename); |
| 213 | string filename = get_parent_directory(f).full_name() + directory::get_separator() + "flipped_" + to_png_name(f.name()); |
| 214 | |
| 215 | load_image(img, metadata.images[i].filename); |
| 216 | flip_image_left_right(img, temp); |
| 217 | if (parser.option("jpg")) |
| 218 | { |
| 219 | filename = to_jpg_name(filename); |
| 220 | save_jpeg(temp, filename,JPEG_QUALITY); |
| 221 | } |
| 222 | #ifdef DLIB_JXL_SUPPORT |
| 223 | else if (parser.option("jxl")) |
| 224 | { |
| 225 | filename = to_jxl_name(filename); |
| 226 | const float jxl_quality = std::stof(parser.option("jxl").argument()); |
| 227 | save_webp(temp, filename, jxl_quality); |
| 228 | } |
| 229 | #endif |
| 230 | #ifdef DLIB_WEBP_SUPPORT |
| 231 | else if (parser.option("webp")) |
| 232 | { |
| 233 | filename = to_webp_name(filename); |
| 234 | const float webp_quality = std::stof(parser.option("webp").argument()); |
| 235 | save_webp(temp, filename, webp_quality); |
| 236 | } |
| 237 | #endif |
| 238 | else |
| 239 | { |
| 240 | save_png(temp, filename); |
| 241 | } |
| 242 | |
| 243 | for (unsigned long j = 0; j < metadata.images[i].boxes.size(); ++j) |
| 244 | { |
| 245 | metadata.images[i].boxes[j].rect = impl::flip_rect_left_right(metadata.images[i].boxes[j].rect, get_rect(img)); |
| 246 | |
| 247 | // flip all the object parts |
no test coverage detected