OpenCV 绘制椭圆代码示例
以下是使用 OpenCV 绘制椭圆的代码示例:
import cv2
import numpy as np
# 创建一个黑色的图像
image = np.zeros((512, 512, 3), np.uint8)
# 定义椭圆的中心坐标和轴长
center_coordinates = (256, 256)
axes_length = (100, 200)
# 定义椭圆的旋转角度
angle = 45
# 定义椭圆的起始角度和结束角度
start_angle = 0
end_angle = 360
# 定义椭圆的颜色和线条粗细
color = (0, 255, 0)
thickness = 2
# 使用cv2.ellipse函数绘制椭圆
image = cv2.ellipse(image, center_coordinates, axes_length, angle, start_angle, end_angle, color, thickness)
# 显示图像
cv2.imshow('Ellipse', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
这段代码创建了一个黑色的图像,然后使用cv2.ellipse函数绘制了一个椭圆。center_coordinates定义了椭圆的中心坐标,axes_length定义了椭圆的长轴和短轴的长度,angle定义了椭圆的旋转角度,start_angle和end_angle定义了椭圆的起始角度和结束角度。color定义了椭圆的颜色,thickness定义了椭圆线条的粗细。
最后,使用cv2.imshow函数显示绘制好的椭圆图像,并使用cv2.waitKey和cv2.destroyAllWindows函数等待用户关闭窗口。
原文地址: https://www.cveoy.top/t/topic/fo6R 著作权归作者所有。请勿转载和采集!