У меня есть это изображение:
![enter image description here](https://i.stack.imgur.com/tA4Fc.jpg)
И я хочу обнаружить все круги в нем, я использую этот учебник.
Вот код:
import argparse
import cv2 as cv
import numpy as np
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Path to the image")
args = vars(ap.parse_args())
# load the image, clone it for output, and then convert it to grayscale
image = cv.imread(args["image"])
output = image.copy()
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
# detect circles in the image
circles = cv.HoughCircles(gray,cv.HOUGH_GRADIENT, 1.2, 75)
# ensure at least some circles were found
if circles is not None:
# convert the (x, y) coordinates and radius of the circles to integers
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
cv.circle(output, (x, y), r, (0, 255, 0), 4)
cv.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
cv.imshow("output", np.hstack([image, output]))
cv.waitKey(0)
Вот выходное изображение после запуска кода:
![enter image description here](https://i.stack.imgur.com/9H9xu.png)
Результат странный, почему это так?
Как я могу обнаружить все круги в нем? Какие параметры мне следует изменить, чтобы добиться этого?
После использования:
circles = cv.HoughCircles(gray,cv.HOUGH_GRADIENT, 1.5, 75)
Я получил это:
![enter image description here](https://i.stack.imgur.com/HE4uq.png)