def generate_im(char_ims, num_bg_images):
bg = generate_bg(num_bg_images)
plate, plate_mask, code = generate_plate(FONT_HEIGHT, char_ims)
M, out_of_bounds = make_affine_transform(
from_shape=plate.shape,
to_shape=bg.shape,
min_scale=0.8,
max_scale=0.9,
rotation_variation=0.3,
scale_variation=1.0,
translation_variation=1.0)
plate = cv2.warpAffine(plate, M, (bg.shape[1], bg.shape[0]))
plate_mask = cv2.warpAffine(plate_mask, M, (bg.shape[1], bg.shape[0]))
out = plate * plate_mask + bg * (1 - plate_mask)
out = cv2.resize(out, (OUTPUT_SHAPE[1], OUTPUT_SHAPE[0]))
out += numpy.random.normal(scale=0.05, size=out.shape)
out = numpy.clip(out, 0., 1.)
return out, code, not out_of_bounds
评论列表
文章目录