boundingrect java_OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、re...

9010d2c94e178493ea5cbf27cf355826.png

3 cv2.minEnclosingCircle

作用:使用迭代算法( iterative algorithm)查找包含2D点集的最小区域的圆(Finds a circle of the minimum area enclosing a 2D point set)。

cv2.minEnclosingCircle(points) -> center, radius

参数:

points - 2D点矢量(vector of 2D points)

返回值:

center - 圆心  (x, y)

radius - 半径  r

如:((426.0, 415.5), 321.7628173828125)

代码示例:

# calculate center and radius of minimum enclosing circle

# 会返回一个二元组,

# 第一个元素为圆心的坐标组成的元组,第二个元素为圆的半径值。

(x, y), radius = cv2.minEnclosingCircle(c)

# 转为整数 cast to integers

center =(int(x), int(y))

radius = int(radius)

# 绘圆 draw the circle

img = cv2.circle(img, center, radius, (0, 255, 0), 2)

或者

cen, rad = cv2.minEnclosingCircle(c)

cen =tuple(np.int0(cen))

rad = np.int32(rad)

img = cv2.circle(img, cen, rad, (0, 255, 0), 2)

运行

f317096ba0bfc4f36e5100cee1125fcd.png

注意:

cv2.circle() 函数使用时,圆

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值