Last active
January 29, 2018 08:17
-
-
Save azhurb/75b4ed4ea8e36e9049fd4e42367b3570 to your computer and use it in GitHub Desktop.
Images augmentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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