def _reorganize_undistorted_images(cameras_sorted, op):
    """Reorganize the undistorted images in the workspace."""

    log_report(
        "WARNING",
        "Writing (renamed) undistorted images to a single folder in the"
        " workspace!",
        op,
    )

    common_prefix = os.path.commonprefix(
        [
            cam.get_undistorted_absolute_fp()
            for cam in cameras_sorted
            if cam.has_undistorted_absolute_fp
        ]
    )
    # Remove trailing slash
    reorganized_dp = os.path.dirname(common_prefix)
    reorganized_undistorted_dp = reorganized_dp + "_restructured"

    log_report(
        "WARNING", f"Reorganized directory: {reorganized_undistorted_dp}", op
    )

    if not os.path.isdir(reorganized_undistorted_dp):
        os.mkdir(reorganized_undistorted_dp)

    for cam in cameras_sorted:
        reorganized_fn = _get_reorganized_file_name(cam, common_prefix)
        reorganized_fp = os.path.join(
            reorganized_undistorted_dp, reorganized_fn
        )
        shutil.copyfile(cam.get_undistorted_absolute_fp(), reorganized_fp)

    first_cam = cameras_sorted[0]
    first_fn = _get_reorganized_file_name(first_cam, common_prefix)
    log_report("WARNING", f"First file name: {first_fn}", op)

    return reorganized_undistorted_dp, first_fn
Reorganize the undistorted images in the workspace.
photogrammetry_importer/importers/camera_animation_utility.py