opencv圆环检测

import numpy as np
import cv2

img = cv2.imread("C:/Users/Asus/Desktop/yq.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
# circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 70, param1=100, param2=25, minRadius=10, maxRadius=50)
# circles = np.uint(np.around(circles))
# for c in circles[0]:
#     x, y, r = c;
edged = cv2.Canny(blurred, 75, 200)
contours, hierarchy = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
center, radius = cv2.minEnclosingCircle(contours[-1])
x = int(np.around(center[0]))
y = int(np.around(center[1]))
cv2.circle(img, (x, y), int(radius), (0, 0, 255), 2)
sp = img.shape
img_x = int(np.around(sp[0] / 2))
img_y = int(np.around(sp[1] / 2))
k = 10 / (2 * int(radius))
d_x = (x - img_x) * k
d_y = (y - img_y) * k
cv2.imshow("img", img)
cv2.waitKey()
cv2.destroyAllWindows()

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值