Opencv报错001:Can‘t parse ‘center‘. Sequence item with index 0 has a wrong type

问题描述:在利用opencv中霍夫圆检测方法来检测图像中圆形物体时,代码如下:

# 1 读取图像,并转换为灰度图
planets = cv.imread("./xingqiu.png")
gay_img = cv.cvtColor(planets, cv.COLOR_BGRA2GRAY)
# 2 进行中值模糊,去噪点
img = cv.medianBlur(gay_img, 7)
# 3 霍夫圆检测
circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 200, param1=100, param2=30, minRadius=0, maxRadius=100)
# 4 将检测结果绘制在图像上
for i in circles[0, :]:  # 遍历矩阵每一行的数据
    cv.circle(planets, (i[0], i[1]), i[2], (0, 255, 0), 2)
    cv.circle(planets, (i[0], i[1]), 2, (0, 0, 255), 3)

错误描述:

cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'circle'
> Overload resolution failed:
>  - Can't parse 'center'. Sequence item with index 0 has a wrong type
>  - Can't parse 'center'. Sequence item with index 0 has a wrong type

错误原因:cv.circle()函数中的圆心坐标不能是浮点数的类型, 要转换成整数才行,于是就使用int()强制类型转换,之后代码成功运行。如下所示:

cv.circle(planets, (int(i[0]), int(i[1])), int(i[2]), (0, 255, 0), 2)
cv.circle(planets, (int(i[0]), int(i[1])), 2, (0, 0, 255), 3)
  • 28
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值