def augmentDataset(in_folder='cropped', out_folder='augmented_dataset'):
"""
Data augmentation (horizontal mirror)
:param in_folder: (str)
:param out_folder: (str)
"""
images = [name for name in os.listdir(in_folder)]
for idx, name in enumerate(images):
r = name.split('.jpg')[0][-2:] # Retrieve the ROI name
cx, cy = map(int, name.split('_')[0].split('-'))
image_path = '{}/{}'.format(in_folder, images[idx])
image = cv2.imread(image_path)
height, width, n_channels = image.shape
horizontal_flip = cv2.flip(image, 1)
cv2.imwrite('{}/{}-{}_{}-{}.jpg'.format(out_folder, cx, cy, idx, r), image)
cv2.imwrite('{}/{}-{}_hori_{}-{}.jpg'.format(out_folder, width - cx, cy, idx, r), horizontal_flip)
评论列表
文章目录