我看了几页有关在python中使用opencv优化圆检测的页面。所有这些似乎都特定于给定图片的个别情况。cv2.HoughCircles的每个参数有哪些起点?由于我不确定建议的值是多少,因此我尝试了遍历范围,但这并没有产生任何有希望的结果。为什么我无法检测到此图像中的任何圆圈?
import cv2
import numpy as np
image = cv2.imread('IMG_stack.png')
output = image.copy()
height, width = image.shape[:2]
maxWidth = int(width/10)
minWidth = int(width/20)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 20,param1=50,param2=50,minRadius=minWidth,maxRadius=maxWidth)
if circles is not None:
# convert the (x, y) coordinates and radius of the circles to integers
circlesRound = np.round(circles[0, :]).astype("int")
# loop over the (x, y) coordinates and radius of the circles
for (x, y, r) in circlesRound:
cv2.circle(output, (x, y), r, (0, 255, 0), …Run Code Online (Sandbox Code Playgroud)