-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aug.py
50 lines (41 loc) · 1.4 KB
/
Aug.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import cv2
import imutils
directoryClassOneTrain = 'train/class 1'
directoryClassTwoTrain = 'train/class 2'
directoryClassThreeTrain = 'train/class 3'
directoryClassOneValid = 'valid/class 1'
directoryClassTwoValid = 'valid/class 2'
directoryClassThreeValid = 'valid/class 3'
def rotate90(directory, count):
i = 0
for filename in os.listdir(directory):
imagePath = os.path.join(directory,filename)
image = cv2.imread(imagePath)
rotated = imutils.rotate(image, 90)
newPath = imagePath[:-4]+'-rotate90'+'.jpg'
cv2.imwrite("{}".format(newPath), rotated)
# cv2.imshow("{}".format(newPath), rotated)
# cv2.waitKey(0)
i+=1
if i == count:
break
def rotate180(directory, count):
i = 0
for filename in os.listdir(directory):
imagePath = os.path.join(directory,filename)
image = cv2.imread(imagePath)
rotated = imutils.rotate(image, 90)
newPath = imagePath[:-4]+'-rotate180'+'.jpg'
# cv2.imshow("{}".format(newPath), rotated)
cv2.imwrite("{}".format(newPath), rotated)
# cv2.waitKey(0)
i+=1
if i == count:
break
rotate90(directoryClassOneTrain, 21)
rotate90(directoryClassThreeTrain, 27)
rotate90(directoryClassOneValid, 7)
rotate90(directoryClassThreeValid, 11)
rotate180(directoryClassThreeTrain, 8)
rotate180(directoryClassThreeValid, 4)