OpenCV python 绘制椭圆形
import numpy as np
import cv2
def main():
# 1.创建白色背景图片
d = 400
img = np.ones((d, d, 3), np.uint8) * 255
# 2.设置椭圆中心点, 长短轴
center = (round(d/2), round(d/2))
size = (100, 200)
# 2.循环绘制椭圆
for i in range(0, 10):
# 随机角度,线宽
angle = np.random.randint(0, 361)
thickness = np.random.randint(1, 9)
# 随机颜色
color = np.random.randint(0, high=256, size=(3,)).tolist()
# 绘制椭圆
cv2.ellipse(img, center, size, angle, 0, 360, color, thickness)
# 3.显示结果
cv2.imshow("img", img)
cv2.waitKey()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
处理结果图片