Converts raw to jpg. This functions are not required for competitors but was developed to prepare the dataset for the competition.
dropbox_path = Path("/tf/airt/data/testing/raw")
actual = get_suffixes(dropbox_path)
expected = set([".jpg", ".xmp", ".tif", ".cr2", ".mov", ".info"])
assert actual == expected, f"{actual} != {expected}"
actual = get_rand_file_with_suff(dropbox_path, ".JpG")
display(actual)
assert isinstance(actual, Path)
assert actual.exists()
assert actual.is_file()
assert actual.suffix.lower() == ".jpg"
display(get_one_image_for_each_suffix(dropbox_path))
assert len(get_suffixes(dropbox_path, verbose=False)) == len(
get_one_image_for_each_suffix(dropbox_path)
)
expected_path = Path("../../data/testing/raw")
actual = create_sample_test_dir_if_needed()
assert expected_path.exists()
assert len(actual) > 0
actual
with TemporaryDirectory() as src_dir:
src_dir = Path(src_dir) / "raw"
copytree("../../data/testing/raw/", src_dir)
tif_path = [x for x in src_dir.glob("*.tif")][0]
new_tif = tif_path.parent / (tif_path.stem + "_copy" + tif_path.suffix)
print(f"NEW tif {new_tif}")
copy(tif_path, new_tif)
before_files = [x for x in src_dir.glob("*")]
jpg_before = [x for x in before_files if x.suffix.lower() == ".jpg"]
for image_path in src_dir.glob("*"):
dst, msg = convert_image_to_jpg_darktable(image_path, remove_src=True)
assert not dst or dst.exists()
print(msg)
after_files = [x for x in src_dir.glob("*")]
assert len(before_files) == len(after_files) + 2
display(sorted(before_files))
display(sorted(after_files))
jpg_after = [x for x in after_files if x.suffix.lower() == ".jpg"]
assert len(jpg_after) == len(jpg_before) + 2
for img_after in jpg_after:
if img_after.suffix.lower() == ".jpg":
print(img_after)
display(Image.open(img_after).resize((300, 200)))
with TemporaryDirectory() as src_dir:
src_dir = Path(src_dir) / "raw"
copytree("../../data/testing/raw/", src_dir)
copytree("../../data/testing/raw/", src_dir / "jedan")
copytree("../../data/testing/raw/", src_dir / "jedan" / "dva")
copytree("../../data/testing/raw/", src_dir / "tri")
copytree("../../data/testing/raw/", src_dir / "tri" / "cetiri")
files_before = list(src_dir.glob("**/*"))
# the main thing
convert_files_with_darktable(src_dir, remove_src=True)
files_after = list(src_dir.glob("**/*"))
assert (
len(files_before) == len(files_after) + 10
), f"len({files_before}) != len({files_after})"