-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_augmention.py
32 lines (26 loc) · 929 Bytes
/
data_augmention.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
import random
import cv2
path = 'E:/opencv/image/'
# 旋转
def rotate(image, scale=0.9):
angle = random.randrange(-90, 90) # 随机角度
w = image.shape[1]
h = image.shape[0]
# rotate matrix
M = cv2.getRotationMatrix2D((w / 2, h / 2), angle, scale)
# rotate
image = cv2.warpAffine(image, M, (w, h))
return image
if __name__ == "__main__":
for i in range(1, 3):
cnt = 3 # 计数
for j in range(1, 23):
roi = cv2.imread(path + str(i) + '_' + str(j) + '.png')
for k in range(5):
img_rotation = rotate(roi) # 旋转
cv2.imwrite(path + str(i) + '_' + str(cnt) + '.png', img_rotation)
cnt += 1
img_flip = cv2.flip(img_rotation, 1) # 翻转
cv2.imwrite(path + str(i) + '_' + str(cnt) + '.png', img_flip)
cnt += 1
print(i, '_', j, '完成')