我想從給定圖像中檢測到一個圓。但它只是不按我想要的方式工作。我實現了一個圓檢測算法,該算法可以在一些圖像上使用圓圈,但不是我想要的圖像。我調整了參數,但無法讓它工作。未找到圓圈
import cv2
import numpy as np
# load the image, clone it for output, and then convert it to grayscale
image = cv2.imread("damn-circle.png")
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# detect circles in the image
blur = cv2.GaussianBlur(gray,(5,5),0)
circles = cv2.HoughCircles(blur, cv2.HOUGH_GRADIENT, 2, 120)
cv2.imshow("output", np.hstack([blur]))
cv2.waitKey(0)
print 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
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
cv2.circle(output, (x, y), r, (0, 255, 0), 4)
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
# show the output image
cv2.imshow("output", np.hstack([output]))
cv2.waitKey(0)
你可能誤解了我。我正在使用OpenCV 3.0。包'cv2.cv'移動到'cv2'。我也可以很好地檢測出您可以使用的圖像,但請使用下面的圖像嘗試相同的代碼。它不工作:) – Sylnois
我編輯了我的答案,以覆蓋你想要找到圈子的圖像。 –