当前位置:网站首页>【OpenCV 例程200篇】215. 基于多段线绘制近似椭圆
【OpenCV 例程200篇】215. 基于多段线绘制近似椭圆
2022-06-30 15:49:00 【小白YouCans】
【youcans 的 OpenCV 例程200篇】215. 基于多段线绘制近似椭圆
如果需要对椭圆渲染进行更多控制,或者绘制粗略的椭圆边界,可以使用 cv.ellipse2Poly 检索曲线,然后使用多段线进行渲染或使用fillPoly进行填充。
函数原型:
cv.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta[,]) → pts
参数说明:
- img:输入输出图像,允许单通道灰度图像或多通道彩色图像
- center:椭圆中心点的坐标,(x, y) 格式的元组
- axes:椭圆半轴长度,(hfirst, hsecond) 格式的元组-
- angle: 椭圆沿 x轴方向的旋转角度(角度制,顺时针方向)
- arcStart:椭圆弧的起始角度(角度制)
- endAngle:椭圆弧的终止角度(角度制)
- delta:与下一线段之间的角度,用于控制近似精度,角度越小越接近椭圆
- pts:输出向量,逼近椭圆弧的多段线顶点坐标的数组
# A4.6 基于多段线绘制近似椭圆
img = np.ones((400, 600, 3), np.uint8)*224
cx, cy = 100, 150
halfAxesLength = (70, 40)
angle, startAng, endAng = 30, 0, 360
delta = [10, 20, 30, 40]
for i in range(len(delta)):
color = (i*60, i*60, 255-i*60)
pts = cv.ellipse2Poly((cx+140*i, cy), halfAxesLength, angle, startAng, endAng, delta[i]) # (351,2)
points = np.array(pts)
cv.polylines(img, [points], True, color, thickness=1) # 绘制近似多边形
points[:,1] += 160
cv.fillPoly(img, [points], color) # 绘制填充近似多边形
text1 = "delta={}".format(delta[i])
text2 = "num={}".format(pts.shape)
cv.putText(img, text1, (140*i+25, 30), cv.FONT_HERSHEY_SIMPLEX, 0.5, 255)
cv.putText(img, text2, (140*i+25, 50), cv.FONT_HERSHEY_SIMPLEX, 0.5, 255)
print(pts.shape, points.shape)
plt.figure(figsize=(9, 6))
plt.title("Polygon approximated ellipse"), plt.axis('off')
plt.imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB))
plt.show()

【本节完】
版权声明:
[email protected] 原创作品,转载必须标注原文链接:(https://blog.csdn.net/youcans/article/details/125468099)
Copyright 2022 youcans, XUPT
Crated:2022-6-26
欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列,持续更新中
欢迎关注 『youcans 的 OpenCV学习课』 系列,持续更新中
210. 绘制直线也会有这么多坑?
211. 绘制垂直矩形
212. 绘制倾斜的矩形
213. 绘制圆形
214. 绘制椭圆的参数详解
215. 基于多段线绘制近似椭圆
边栏推荐
- In order to make remote work unaffected, I wrote an internal chat room | community essay
- 几个跨端开发神器
- After 15 years of working on 21 types of hardware, where is Google?
- Carry two load balancing notes and find them in the future
- JS ES5也可以创建常量?
- 删除有序数组中的重复项 II[双指针--多情况统一]
- Multi terminal collaboration of Huawei accounts to create a better internet life
- 数据挖掘知识点整理(期末复习版)
- Raft介绍
- Good partner for cloud skill improvement, senior brother cloud of Amazon officially opened today
猜你喜欢

荣盛生物冲刺科创板:拟募资12.5亿 年营收2.6亿

Home office discussion on the experience of remote assistance to quickly improve efficiency | community essay solicitation

安全帽佩戴检测算法研究

编译丨迅为STM32P157开发板编译U-Boot源码

“推广+搞笑剧情”,如何碰撞出爆款的火花?
![[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection](/img/c2/d6760826b81589781574aebff61f9a.png)
[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection

OpenCV中LineTypes各枚举值(LINE_4 、LINE_8 、LINE_AA )的含义

坚果云-在新电脑上同步移动硬盘的文件

Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
![Delete duplicates in an ordered array ii[double pointers -- unified in multiple cases]](/img/e2/cadfdbe476a86cb2d72c1ae0160a4a.png)
Delete duplicates in an ordered array ii[double pointers -- unified in multiple cases]
随机推荐
BC1.2 PD协议
列表变成向量 列表变向量 list vector
jspreadsheet/CE JExcel数据字段比给的字段(columns)多会导致空白列的问题解决方案
Mathematical modeling for war preparation 36 time series model 2
[Verilog basics] octal and hexadecimal representation of decimal negative numbers
Talk about telecommuting | community essay solicitation
Several cross end development artifacts
Jsr303 and common validator implementations
编译丨迅为STM32P157开发板编译U-Boot源码
数据库系统概论习题册
腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
2020 Blue Bridge Cup group B - move bricks - (greedy sorting +01 backpack)
[Verilog basics] summary of some concepts about clock signals (clock setup/hold, clock tree, clock skew, clock latency, clock transition..)
数据挖掘知识点整理(期末复习版)
Headhunter 50, 000, I'll go to VC
Installing jupyter notebook under Anaconda
Symantec electronic sprint technology innovation board: Tan Jian, the actual controller, is an American who plans to raise 620million yuan
On July 2, I invited you to TD Hero online conference
【牛客网刷题系列 之 Verilog快速入门】~ 位拆分与运算
Jspreadsheet/ce JExcel: more data fields than the given fields (columns) will lead to blank columns. Solution