最初に、Mikiが指摘したように、HughCirclesはグレースケールに直接適用する必要がありますが、独自のCanny Edge検出器があります。
第2に、HughCirclesのパラメータは、特定の種類の画像に合わせて調整する必要があります。すべての数式に適合する1つの設定はありません。円と
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);
}
入力画像:

検出された円が赤く着色されている:

これはいくつかの生成の円の上に私のために働いたあなたのコードに基づいて
出力画像で左の白丸が白に非常に近いことが検出されなかった。 p1UpperThreshold=20
を設定すると表示されます。
出典
2017-12-05 20:00:01
1mi
HoughCircleに渡されるソースイメージとイメージを投稿できますか?可能であれば、中間画像も。 – barny
エッジ画像ではなく、灰色の画像上にハーフサークルを使用する必要があります – Miki