![](/img/trans.png)
[英]How to find the circle in the given images using opencv python (hough circles )?
[英]How to manipulate hough circles to detect all circles in the given image using python?
import numpy as np
import cv2
import matplotlib.pyplot as plt
import copy
image = cv2.imread('C:/Users/Deepak Padhi/Desktop/download.png')
#cv2.imshow('Filtered_original',image)
image = cv2.GaussianBlur(image,(5,5),0)
orig_image = np.copy(image)
gray= image[:,:,1]
output=gray.copy()
##cv2.imshow("gray", gray)
##cv2.waitKey(0)
circles=cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 3, 4.0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(output,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(output,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',output)
这是我用来尝试检测给定图像中所有圆圈的代码:圆圈图像
我应该使用哪个参数以及如何操作来检测较小和较大的圆圈? 我已经根据两个圆圈尝试了 minRadius 和 maxRadius 的可能值,但它不起作用,所以我让它重置为默认值。
感觉就像 canny 边缘检测器实际上是使用默认参数(100,100)检测较小的圆圈,作为附加的 canny 检测
我拿了给定图像的绿色平面:原始图像
我建议您先阅读文档。
如果您只是更改作为 Canny 边缘检测器阈值的param1和param2 ,则cv2.HoughCircles可以正常工作。
这里的代码:
import cv2
import numpy as np
image = cv2.imread('circles.png')
image = cv2.GaussianBlur(image, (5, 5), 0)
orig_image = np.copy(image)
gray = image[:, :, 1]
output = gray.copy()
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=50, param2=20,
minRadius=0, maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(output, (i[0], i[1]), i[2], (0, 255, 0), 2)
# draw the center of the circle
cv2.circle(output, (i[0], i[1]), 2, (0, 0, 255), 3)
cv2.imwrite('detected circles.png', output)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.