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

Function update_image_and_anno

computer_vision/flip_augmentation.py:78–111  ·  view source on GitHub ↗

- img_list : list of all images - anno_list : list of all annotations of specific image - flip_type : 0 is vertical, 1 is horizontal Return: - new_imgs_list : image after resize - new_annos_lists : list of

(
    img_list: list, anno_list: list, flip_type: int = 1
)

Source from the content-addressed store, hash-verified

76
77
78def update_image_and_anno(
79 img_list: list, anno_list: list, flip_type: int = 1
80) -> tuple[list, list, list]:
81 """
82 - img_list <type: list>: list of all images
83 - anno_list <type: list>: list of all annotations of specific image
84 - flip_type <type: int>: 0 is vertical, 1 is horizontal
85 Return:
86 - new_imgs_list <type: narray>: image after resize
87 - new_annos_lists <type: list>: list of new annotation after scale
88 - path_list <type: list>: list the name of image file
89 """
90 new_annos_lists = []
91 path_list = []
92 new_imgs_list = []
93 for idx in range(len(img_list)):
94 new_annos = []
95 path = img_list[idx]
96 path_list.append(path)
97 img_annos = anno_list[idx]
98 img = cv2.imread(path)
99 if flip_type == 1:
100 new_img = cv2.flip(img, flip_type)
101 for bbox in img_annos:
102 x_center_new = 1 - bbox[1]
103 new_annos.append([bbox[0], x_center_new, bbox[2], bbox[3], bbox[4]])
104 elif flip_type == 0:
105 new_img = cv2.flip(img, flip_type)
106 for bbox in img_annos:
107 y_center_new = 1 - bbox[2]
108 new_annos.append([bbox[0], bbox[1], y_center_new, bbox[3], bbox[4]])
109 new_annos_lists.append(new_annos)
110 new_imgs_list.append(new_img)
111 return new_imgs_list, new_annos_lists, path_list
112
113
114def random_chars(number_char: int = 32) -> str:

Callers 1

mainFunction · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected