如何在python中使用openCV检测圆?

我想通过使用Haar级联来检测图片中的圆圈。我创建了一个级联xml。

import cv2
import numpy as np
img = cv2.imread("C://OpenCVcascade//resimler//coins.jpg")
circles_cascade = cv2.CascadeClassifier("C://Cascade//dairetanima.xml")

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
circles = circles_cascade.detectMultiScale(gray, 1.1, 1)

if circles is not None:
    circles = np.uint16(np.around(circles))
    for (x, y, w, h) in circles:
        center = (x + w // 2, y + h // 2)
        radius = (w + h) // 4
        cv2.circle(img, center, radius, (255, 0, 0), 2)

cv2.imshow('image', img)

cv2.waitKey()
cv2.destroyAllWindows()

My result: enter image description here

我已经知道,有不同的检测圆的方法。但是我正在尝试使用级联方法。因为在这部分之后,我将使用它进行实时检测。