MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / main

Function main

computer_vision/flip_augmentation.py:20–42  ·  view source on GitHub ↗

Get images list and annotations list from input dir. Update new images and annotations. Save images and annotations in output dir.

()

Source from the content-addressed store, hash-verified

18
19
20def main() -> None:
21 """
22 Get images list and annotations list from input dir.
23 Update new images and annotations.
24 Save images and annotations in output dir.
25 """
26 img_paths, annos = get_dataset(LABEL_DIR, IMAGE_DIR)
27 print("Processing...")
28 new_images, new_annos, paths = update_image_and_anno(img_paths, annos, FLIP_TYPE)
29
30 for index, image in enumerate(new_images):
31 # Get random string code: '7b7ad245cdff75241935e4dd860f3bad'
32 letter_code = random_chars(32)
33 file_name = paths[index].split(os.sep)[-1].rsplit(".", 1)[0]
34 file_root = f"{OUTPUT_DIR}/{file_name}_FLIP_{letter_code}"
35 cv2.imwrite(f"{file_root}.jpg", image, [cv2.IMWRITE_JPEG_QUALITY, 85])
36 print(f"Success {index + 1}/{len(new_images)} with {file_name}")
37 annos_list = []
38 for anno in new_annos[index]:
39 obj = f"{anno[0]} {anno[1]} {anno[2]} {anno[3]} {anno[4]}"
40 annos_list.append(obj)
41 with open(f"{file_root}.txt", "w") as outfile:
42 outfile.write("\n".join(line for line in annos_list))
43
44
45def get_dataset(label_dir: str, img_dir: str) -> tuple[list, list]:

Callers 1

Calls 5

splitMethod · 0.80
get_datasetFunction · 0.70
update_image_and_annoFunction · 0.70
random_charsFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected