选择hough_gradient_alt的参数
我已经试图解决这些问题数小时,而在Stackoverflow上的类似问题也没有帮助我。
想象一下我有这个图像(实际上,它是一个更复杂的图像,但我现在会呆一个简单的例子):
我为hough_gradient
:
import cv2
import numpy as np
img = cv2.cvtColor(cv2.imread("example.png"), cv2.COLOR_BGR2GRAY)
img_blur = cv2.GaussianBlur(img, (9, 9), 1.5)
edges = cv2.Canny(img_blur, threshold1=50, threshold2=250)
circles = cv2.HoughCircles(
edges, cv2.HOUGH_GRADIENT, 1.5, 20,
minRadius=10, maxRadius=100, param1=100, param2=100
)
img_cp = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
cv2.circle(img_cp, (x, y), r, (0, 255, 0), 4)
这无问题起作用,并像我想要的那样检测内部圆圈:
我试图使用hough_gradient_alt
,因为OpenCV Repo声称它可以更好地工作。据我了解,大多数函数调用参数应该具有相同的含义,而不是param1
和param2
。
所以,我尝试
circles = cv2.HoughCircles(
edges, cv2.HOUGH_GRADIENT_ALT, 1.5, 20,
minRadius=10, maxRadius=100, param1=300, param2=0.9
:)
我什么也没得到。我尝试了许多不同的参数,但没有结果。我不仅不明白如何修复它,而且我不明白为什么它不起作用。任何帮助将不胜感激。
OPENCV版本4.5.5。
I am trying to solve this problems for hours already, and similar issues on StackOverflow did not help me.
Imagine I have this image (in reality it is a more complicated image but I'll stay with a simple example for now):
I do the following for the HOUGH_GRADIENT
:
import cv2
import numpy as np
img = cv2.cvtColor(cv2.imread("example.png"), cv2.COLOR_BGR2GRAY)
img_blur = cv2.GaussianBlur(img, (9, 9), 1.5)
edges = cv2.Canny(img_blur, threshold1=50, threshold2=250)
circles = cv2.HoughCircles(
edges, cv2.HOUGH_GRADIENT, 1.5, 20,
minRadius=10, maxRadius=100, param1=100, param2=100
)
img_cp = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
cv2.circle(img_cp, (x, y), r, (0, 255, 0), 4)
This works without any problems and detects the inner circles just as I want:
I was trying to use HOUGH_GRADIENT_ALT
instead as the OpenCV repo claims it to work better. From what I understand, most function call arguments should have the same meaning instead of param1
and param2
.
So, I try:
circles = cv2.HoughCircles(
edges, cv2.HOUGH_GRADIENT_ALT, 1.5, 20,
minRadius=10, maxRadius=100, param1=300, param2=0.9
)
And I get nothing. I have tried many different parameters but to no result. Not only I do not understand how to fix it but also I do not understand why it would not work. Any help would be very appreciated.
OpenCV version 4.5.5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决了问题。尝试以下尝试:编辑:我们无法使用此
cv2.hough_gradient_alt
输出:
编辑:我们可以
cv2.hough_gradint_alt
,并从@valeria中使用了使用。输出:
I solved problem. Try this: Edit: we cannot used this
cv2.HOUGH_GRADIENT_ALT
Output:
Edit: we can
cv2.HOUGH_GRADINT_ALT
And used snipped from @Valeria.Output:
hough_gradint_alt似乎被打破了。
我有一个略微变形的白色圆圈的图像,黑色背景约为420x420
我称此
houghcircles(被边框,圆,hough_gradient_alt
,1#dp。累积=图像大小并检测到“小”
,20#圆圈之间的识别主义者
,600#param1 =中心阈值,
,0.7#param2 = [erfectness
,M,362); #min,max,
如果我设置了M = 194,则有效。如果我设置了M = 193或更低,则无效。从文档中,我了解此功能也应该检测到我的圆,即使将其设置为0。
HOUGH_GRADINT_ALT seems to be broken.
I have an image of a slightly deformed white circle with radius 230 on a black background that is about 420x420
I call this
HoughCircles(bordered, circles,HOUGH_GRADIENT_ALT
, 1 # dp. accumsize=imagesize and detect also 'small'
, 20 # mindist between circles
, 600# param1 = threshold for center,
, 0.7 # param2=[erfectness
, M, 362); # min,max
If I set M=194 it works. If I set M=193 or lower it does not work. From the documentation I understand this function should detect my circle even if I set it to 0.