Python - openCv 检测给出奇怪结果的圆

Python - openCv to detect circles giving strange results

我正在使用 https://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/#comment-480634 中解释的代码,并试图从根本上检测显示在该示例 instagram 页面(已附上)下半部分的小圆形个人资料图像(准确地说是 5)。我不明白的是为什么: 1. 5 个小圆圈中只有一个被代码捕获 2. 页面上怎么显示一个大圆圈,我觉得很荒谬。 这是我正在使用的代码:

# we create a copy of the original image so we can draw our detected circles 
# without destroying the original image.
image = cv2.imread("instagram_page.png")

# the cv2.HoughCircles function requires an 8-bit, single channel image, 
# so we’ll convert from the RGB color space to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#blurred = cv2.GaussianBlur(gray, (5, 5), 0)

# detect circles in the image. We pass in the image we want to detect circles as the first argument, 
# the circle detection method as the second argument (currently, the cv2.cv.HOUGH_GRADIENT method 
# is the only circle detection method supported by OpenCV and will likely be the only method for some time),
# an accumulator value of 1.5 as the third argument, and finally a minDist of 100 pixels.
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.7, minDist= 1, param1 = 300, param2 = 100, minRadius=3, maxRadius=150)

print("Circles len -> {}".format(len(circles)))


# ensure at least some circles were found
if circles is not None:    
    # convert the (x, y) coordinates and radius of the circles to integers
    # converting our circles from floating point (x, y) coordinates to integers, 
    # allowing us to draw them on our output image.
    circles = np.round(circles[0, :]).astype("int")

    # loop over the (x, y) coordinates and radius of the circles
    for (x, y, r) in circles:
        # draw the circle in the output image, then draw a rectangle
        # corresponding to the center of the circle
        orange = (39, 127, 255)
        cv2.circle(output, (x, y), r, orange, 4)
        cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)


img_name = "Output"
cv2.namedWindow(img_name,cv2.WINDOW_NORMAL)
cv2.resizeWindow(img_name, 800,800)
cv2.imshow(img_name, output)
cv2.waitKey(0)    
cv2.destroyAllWindows()

我使用 minDist = 1 来确保可能捕捉到那些封闭的圆圈。有没有人看到我的参数完全错误?

我尝试使用参数并设法检测到所有圆圈(Ubuntu 16.04 LTS x64,Python 3.7,numpy==1.15.1python-opencv==3.4.3):

circles = cv2.HoughCircles(
    gray,
    cv2.HOUGH_GRADIENT,
    1.7,
    minDist=100,
    param1=48,
    param2=100,
    minRadius=2,
    maxRadius=100
)