本篇内容介绍了“cv2.ellipse()怎么使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
OpenCV-Python是旨在解决计算机视觉问题的Python绑定库。cv2.ellipse()
方法用于在任何图像上绘制椭圆。
cv2.ellipse(image, centerCoordinates, axesLength, angle, startAngle, endAngle, color [, thickness[, lineType[, shift]]])
参数:
image:它是要在其上绘制椭圆的图像。
centerCoordinates:它是椭圆的中心坐标。坐标表示为两个值的元组,即(X坐标值,Y坐标值)。
axesLength:它包含两个变量的元组,分别包含椭圆的长轴和短轴(长轴长度,短轴长度)。
angle:椭圆旋转角度,以度为单位。
startAngle:椭圆弧的起始角度,以度为单位。
endAngle:椭圆弧的终止角度,以度为单位。
color:它是要绘制的形状边界线的颜色。对于BGR,我们通过一个元组。例如:(255,0,0)为蓝色。
thickness:是形状边界线的粗细像素。厚度-1像素将用指定的颜色填充形状。
lineType:这是一个可选参数,它给出了椭圆边界的类型。
shift:这是一个可选参数。它表示中心坐标中的小数位数和轴的值。
返回值:它返回一个图像。
用于以下所有示例的图像:
示例1:
# Python program to explain cv2.ellipse() method
# importing cv2
import cv2
# path
path = r'C:\Users\Rajnish\Desktop\geeksforgeeks\geeks.png'
# Reading an image in default mode
image = cv2.imread(path)
# Window name in which image is displayed
window_name = 'Image'
center_coordinates = (120, 100)
axesLength = (100, 50)
angle = 0
startAngle = 0
endAngle = 360
# Red color in BGR
color = (0, 0, 255)
# Line thickness of 5 px
thickness = 5
# Using cv2.ellipse() method
# Draw a ellipse with red line borders of thickness of 5 px
image = cv2.ellipse(image, center_coordinates, axesLength,
angle, startAngle, endAngle, color, thickness)
# Displaying the image
cv2.imshow(window_name, image)
输出:
示例2:
使用-1 px的厚度和30度的旋转。
# Python program to explain cv2.ellipse() method
# importing cv2
import cv2
# path
path = r'C:\Users\Rajnish\Desktop\geeksforgeeks\geeks.png'
# Reading an image in default mode
image = cv2.imread(path)
# Window name in which image is displayed
window_name = 'Image'
center_coordinates = (120, 100)
axesLength = (100, 50)
angle = 30
startAngle = 0
endAngle = 360
# Blue color in BGR
color = (255, 0, 0)
# Line thickness of -1 px
thickness = -1
# Using cv2.ellipse() method
# Draw a ellipse with blue line borders of thickness of -1 px
image = cv2.ellipse(image, center_coordinates, axesLength, angle,
startAngle, endAngle, color, thickness)
# Displaying the image
cv2.imshow(window_name, image)
输出:
“cv2.ellipse()怎么使用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/4870686/blog/4956966