Skip to content

Instantly share code, notes, and snippets.

@azhurb
Last active January 29, 2018 08:17
Show Gist options
  • Save azhurb/75b4ed4ea8e36e9049fd4e42367b3570 to your computer and use it in GitHub Desktop.
Save azhurb/75b4ed4ea8e36e9049fd4e42367b3570 to your computer and use it in GitHub Desktop.
Images augmentation
import numpy as np
import cv2
def rotateImage(image, angle):
image_center = tuple(np.array(image.shape[1::-1]) / 2)
rot_mat = cv2.getRotationMatrix2D(image_center, angle, 1.0)
result = cv2.warpAffine(image, rot_mat, image.shape[1::-1], flags=cv2.INTER_LINEAR)
return result
import os
for top, dirs, files in os.walk('./'):
for nm in files:
file = os.path.join(top, nm)
print(file)
if file == __file__:
continue
img = cv2.imread(file, 1)
for deg in [90, 180, 270]:
cv2.imwrite(top + '/' + nm.replace('.png', '_' + str(deg) + '.png'), rotateImage(img, deg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment