먼저 Miki는 HughCircles를 그레이 스케일에 직접 적용해야한다고 지적했기 때문에 자체 Canny Edge 디텍터가 있습니다.
두 번째로 HughCircles의 매개 변수는 특정 유형의 이미지로 조정되어야합니다. 모든 수식에 맞는 하나의 설정이 없습니다. 원
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
Houghcircles는 가장자리 이미지가 아니라 회색 이미지에 사용해야합니다. – Miki