霍夫圆检测
边缘保留滤波——转灰度图——霍夫圆检测
# -*- coding: utf-8 -*-
"""
霍夫圆检测
边缘保留滤波————转灰度图————霍夫圆检测
@author: LNP
"""
import cv2 as cv
import numpy as np
def detect_circle_demo(image):
#hough圆检测对噪声敏感,必须滤波
blur=cv.pyrMeanShiftFiltering(image,10,100)
cv.imshow('blur',blur)
gray=cv.cvtColor(blur,cv.COLOR_BGR2GRAY)
circle=cv.HoughCircles(gray,cv.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)
circle=np.uint16(np.around(circle))
print(circle.shape)
for i in circle[0,:]:
cv.circle(image,(i[0],i[1]),i[2],(0,0,255),2)
cv.circle(image,(i[0],i[1]),2,(0,0,255),2)
cv.imshow('detect_circle_demo',image)
src=cv.imread("D:/Study/opencv/code/circle.png")
cv.imshow('src',src)
detect_circle_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()