美文网首页python源码大全
Python代码库OpenCV之10圆检测circle dete

Python代码库OpenCV之10圆检测circle dete

作者: iCloudEnd | 来源:发表于2019-12-03 16:16 被阅读0次

blur后进行检测

检测原图

检测原图

代码

import cv2
import numpy as np

filename="D:\\pythondev\\dev\\opencv\\img\\circle.png"
image = cv2.imread(filename)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blur = cv2.medianBlur(gray, 5)
#circles = cv2.HoughCircles(gray, cv2_HOUGH_GRADIENT, 1, 10)

circles = cv2.HoughCircles(blur, cv2.HOUGH_GRADIENT, 1.5, 10)
circles = np.uint16(np.around(circles))

for i in circles[0,:]:
    # draw the outer circle
    cv2.circle(image,(i[0], i[1]), i[2], (255, 0, 0), 2)
    # draw the center of the circle
    cv2.circle(image, (i[0], i[1]), 2, (0, 255, 0), 5)

cv2.imshow('detected circles', image)
cv2.waitKey(0)
cv2.destroy All Windows()

运行效果

image.png

更多精彩代码请关注我的专栏

相关文章

网友评论

    本文标题:Python代码库OpenCV之10圆检测circle dete

    本文链接:https://www.haomeiwen.com/subject/qxacgctx.html