无Hough的循环检测

2024-04-28 19:56:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经使用圆Hough变换来检测图像中的圆,通过python中的代码,但是现在我想使用另一种方法来检测圆,除了圆Hough变换,还有其他方法检测圆吗


import cv2
import numpy as np

img = cv2.imread("Resources/coin0.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur= cv2.medianBlur(gray, 5)
# center


dp=1.1
minDis=10
param1=150
param2=40
minRadius=0
maxRadius=0

circles = cv2.HoughCircles(blur, cv2.HOUGH_GRADIENT, dp, minDis,
                        param1 =param1, param2 =param2, minRadius = minRadius, maxRadius = maxRadius)

circles = np.uint16(np.around(circles))
for i in circles[0, :]: ## Draw circle on the circles

 #  draw   the    outer  circle
 cv2.circle(img, (i[0], i[1]), i[2], (0, 255, 0),2)
 #  draw   the    center of the    circle
 cv2.circle(img, (i[0], i[1]), 2, (0, 0, 255),2)





cv2.imshow("Image",img)
cv2.waitKey(0)
cv2.destroyAllWindows()



enter image description here


Tags: the方法importimgnpcv2param1param2