Zuerst, wie Miki darauf hinwies, dass HughCircles direkt auf die Graustufen angewendet werden sollte, hat es einen internen Canny Edge Detektor.
Zweitens sollten die Parameter von HughCircles auf Ihren speziellen Bildtyp abgestimmt sein. Es gibt keine einzige Einstellung für alle Formeln.
Basierend auf Ihren Code für mich auf einige erzeugten Kreise gearbeitet:
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat img = Highgui.imread("circle-in.jpg", Highgui.CV_LOAD_IMAGE_ANYCOLOR);
Mat gray = new Mat();
Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.blur(gray, gray, new Size(3, 3));
Mat circles = new Mat();
double minDist = 60;
// higher threshold of Canny Edge detector, lower threshold is twice smaller
double p1UpperThreshold = 200;
// the smaller it is, the more false circles may be detected
double p2AccumulatorThreshold = 20;
int minRadius = 30;
int maxRadius = 0;
// use gray image, not edge detected
Imgproc.HoughCircles(gray, circles, Imgproc.CV_HOUGH_GRADIENT, 1, minDist, p1UpperThreshold, p2AccumulatorThreshold, minRadius, maxRadius);
// draw the detected circles
Mat detected = img.clone();
for (int x = 0; x < circles.cols(); x++) {
double[] c1xyr = circles.get(0, x);
Point xy = new Point(Math.round(c1xyr[0]), Math.round(c1xyr[1]));
int radius = (int) Math.round(c1xyr[2]);
Core.circle(detected, xy, radius, new Scalar(0, 0, 255), 3);
}
Highgui.imwrite("circle-out.jpg", detected);
}
Eingabebild mit Kreisen:
Erkannt Kreise sind rot gefärbt:
Hinweis Wie in dem Ausgabebild wurde der weiße Kreis auf der linken Seite nicht erkannt, der sehr nahe an Weiß war. Es wird sein, wenn Sie p1UpperThreshold=20
festlegen.
Können Sie das Quellbild und das an HoughCircle übergebene Bild posten? Auch die Zwischenbilder wenn möglich. – barny
Houghcircles sollten auf dem grauen Bild und nicht auf dem Kantenbild verwendet werden – Miki