MCPcopy Create free account
hub / github.com/davisking/dlib / rotate_dataset

Function rotate_dataset

tools/imglab/src/main.cpp:309–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307// ----------------------------------------------------------------------------------------
308
309void rotate_dataset(const command_line_parser& parser)
310{
311 image_dataset_metadata::dataset metadata;
312 const string datasource = parser[0];
313 load_image_dataset_metadata(metadata,datasource);
314
315 double angle = get_option(parser, "rotate", 0);
316
317 // Set the current directory to be the one that contains the
318 // metadata file. We do this because the file might contain
319 // file paths which are relative to this folder.
320 set_current_dir(get_parent_directory(file(datasource)));
321
322 const string file_prefix = "rotated_"+ cast_to_string(angle) + "_";
323 const string metadata_filename = get_parent_directory(file(datasource)).full_name() +
324 directory::get_separator() + file_prefix + file(datasource).name();
325
326
327 array2d<rgb_pixel> img, temp;
328 for (unsigned long i = 0; i < metadata.images.size(); ++i)
329 {
330 file f(metadata.images[i].filename);
331 string filename = get_parent_directory(f).full_name() + directory::get_separator() + file_prefix + to_png_name(f.name());
332
333 load_image(img, metadata.images[i].filename);
334 const point_transform_affine tran = rotate_image(img, temp, angle*pi/180);
335 metadata.images[i].width = temp.nc();
336 metadata.images[i].height = temp.nr();
337 if (parser.option("jpg"))
338 {
339 filename = to_jpg_name(filename);
340 save_jpeg(temp, filename,JPEG_QUALITY);
341 }
342#ifdef DLIB_JXL_SUPPORT
343 else if (parser.option("jxl"))
344 {
345 filename = to_jxl_name(filename);
346 const float jxl_quality = std::stof(parser.option("jxl").argument());
347 save_jxl(temp, filename, jxl_quality);
348 }
349#endif
350#ifdef DLIB_WEBP_SUPPORT
351 else if (parser.option("webp"))
352 {
353 filename = to_webp_name(filename);
354 const float webp_quality = std::stof(parser.option("webp").argument());
355 save_webp(temp, filename, webp_quality);
356 }
357#endif
358 else
359 {
360 save_png(temp, filename);
361 }
362
363 rectangle_transform rtran = tran;
364 for (unsigned long j = 0; j < metadata.images[i].boxes.size(); ++j)
365 {
366 metadata.images[i].boxes[j].rect = rtran(metadata.images[i].boxes[j].rect);

Callers 1

mainFunction · 0.85

Calls 15

get_optionFunction · 0.85
get_parent_directoryFunction · 0.85
cast_to_stringFunction · 0.85
to_png_nameFunction · 0.85
rotate_imageFunction · 0.85
to_jpg_nameFunction · 0.85
to_jxl_nameFunction · 0.85
save_jxlFunction · 0.85
to_webp_nameFunction · 0.85
save_webpFunction · 0.85
save_pngFunction · 0.85

Tested by

no test coverage detected