-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataaugmentation.py
More file actions
executable file
·29 lines (22 loc) · 935 Bytes
/
dataaugmentation.py
File metadata and controls
executable file
·29 lines (22 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Data Augmentation
# http://docs.opencv.org/master/da/d6e/tutorial_py_geometric_transformations.html#gsc.tab=0
import cv2
import os
import sys
for filename in os.listdir('data/Train/'):
path = 'data/Train/'+filename
img = cv2.imread(path)
img = cv2.resize(img, (150,150), interpolation = cv2.INTER_LINEAR)
rows, cols, channels = img.shape
M = cv2.getRotationMatrix2D((cols/2,rows/2),90,1)
dst = cv2.warpAffine(img,M,(cols,rows))
cv2.imwrite('data/TrainExt/'+filename+'90.bmp',dst)
M = cv2.getRotationMatrix2D((cols/2,rows/2),180,1)
dst = cv2.warpAffine(img,M,(cols,rows))
cv2.imwrite('data/TrainExt/'+filename+'180.bmp',dst)
M = cv2.getRotationMatrix2D((cols/2,rows/2),270,1)
dst = cv2.warpAffine(img,M,(cols,rows))
cv2.imwrite('data/TrainExt/'+filename+'270.bmp',dst)
M = cv2.getRotationMatrix2D((cols/2,rows/2),0,1)
dst = cv2.warpAffine(img,M,(cols,rows))
cv2.imwrite('data/TrainExt/'+filename+'0.bmp',dst)