def draw_drac(img,image_path,save_dir):
'''
img: 2d numpy such as (512,512)
todo: draw drac 2d img randomly
'''
'''
img表示输入的图像
center表示椭圆圆心坐标
axes表示椭圆长轴和短轴的长度(为半轴长),输入参数时如此表示:(long,shor)
angle表示主轴(长轴)偏转角度
start_angle表示圆弧起始角度
end_angle表示圆弧终结角度
color表示线条颜色,为BGR形式,如蓝色为(255,0,0)
thickness为非负数时表示线条的粗细程度,否则表示椭圆被填充
lineType表示线条的类型,默认为LINE_8,可直接用8表示,另外还有LINE_4和LINE_AA
shift表示圆心坐标点和数轴的精度,默认为0
'''
rot_angle_degree = (-1 + 2*random.random()) * 180
angel_radio = random.randint(90, 270)
short_axes = random.randint(180, 240)
long_axes = random.randint(210, 240)
center = (256, 256)
axes = (long_axes, short_axes)
start_angle = angel_radio
end_angle = 360 - angel_radio
color = (255, 0, 0)
shift = 3
image_name = os.path.basename(os.path.dirname(image_path))
cv2.ellipse(img, center, axes, rot_angle_degree, start_angle, end_angle, color, shift)
cv2.imwrite(os.path.join(save_dir, image_name + '.png'), img)
Reference