Fix bug when copying images when input_dir = output_dir (#2041)

* fixes bug input_dir == output_dir

* reformat
This commit is contained in:
Matias Turkulainen authored and GitHub committed 2023-06-07 10:22:10 -07:00
1 parent 43c399e71e
commit d4b04376ab
1 file changed
+7 -2
@@ -195,7 +195,9 @@ def copy_images_list(
# Remove original directory only if we provide a proper image folder path
if image_dir.is_dir() and len(image_paths):
shutil.rmtree(image_dir, ignore_errors=True)
# check that output directory is not the same as input directory
if image_dir != image_paths[0].parent:
shutil.rmtree(image_dir, ignore_errors=True)
image_dir.mkdir(exist_ok=True, parents=True)
copied_image_paths = []
@@ -205,7 +207,10 @@ def copy_images_list(
if verbose:
CONSOLE.log(f"Copying image {idx + 1} of {len(image_paths)}...")
copied_image_path = image_dir / f"frame_{idx + 1:05d}{image_path.suffix}"
shutil.copy(image_path, copied_image_path)
try:
shutil.copy(image_path, copied_image_path)
except shutil.SameFileError:
pass
copied_image_paths.append(copied_image_path)
if crop_border_pixels is not None: