Ich möchte einen Kreis aus einem gegebenen Bild erkennen. Aber es funktioniert einfach nicht so, wie ich es möchte. Ich habe einen Kreiserkennungsalgorithmus implementiert, der auf einigen Bildern mit einem Kreis arbeitet, aber nicht auf dem einen, den ich möchte. Ich habe mit den Parametern gezwängt, konnte es aber nicht zum Laufen bringen.Kreis nicht gefunden
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)
Sie mich vielleicht falsch verstanden. Ich benutze OpenCV 3.0. Das Paket 'cv2.cv' wurde nur in' cv2' verschoben. Ich kann das Bild auch perfekt erkennen, aber versuche den gleichen Code mit dem Bild unten. Es funktioniert nicht :) – Sylnois
Ich habe meine Antwort bearbeitet, um das Bild abzudecken, in dem Sie den Kreis finden wollten. –