from PIL import Image, ImageDraw
import numpy as np
import imgaug as ia
from imgaug import augmenters as iaa
import os
AUG_NUM = 5
PATH = r'C:/pycharm_projects/get_label/sum_pan/train/img/'
SAVE_PATH = r'C:/pycharm_projects/get_label/data_arugement_train/'
os.makedirs(SAVE_PATH, exist_ok=True)
def get_LP_loc(path):
# 对标记数据进行处理,获取车牌四个点坐标的位置
with open(path, 'r') as f:
pos = f.readline().split(',')
x1 = int(float(pos[0]))
y1 = int(float(pos[1]))
x2 = int(float(pos[2]))
y2 = int(float(pos[3]))
x4 = int(float(pos[4]))
y4 = int(float(pos[5]))
x3 = int(float(pos[6]))
y3 = int(float(pos[7]))
return x1, y1, x2, y2, x3, y3, x4, y4
def data_augmentation(img_path):
# 数据增强函数
img_abs_path = os.path.join(PATH, img_path)
print(img_abs_path)
label_path = img_abs_path.replace('img', 'gt').replace('.jpg', '.txt')
print(label_path,'---------')
x1, y1, x2, y2, x3, y3, x4, y4 = get_LP_loc(label_path)
im = Image.open(img_abs_path)
image = np.array(im)
keypoints = ia.KeypointsOnImage([ia.Keypoint(x = x1, y = y1),
ia.Keypoint(x = x2, y = y2),