public static void main(String[] args)
{
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat src = Imgcodecs.imread("F:websbook_com_1589226.jpg");
Mat dst = src.clone();
Imgproc.cvtColor(src, dst, Imgproc.COLOR_BGR2GRAY);
Mat circles = new Mat();
Imgproc.HoughCircles(dst, circles, Imgproc.HOUGH_GRADIENT, 1, 100, 440, 50, 0, 345);
// Imgproc.HoughCircles(dst, circles, Imgproc.HOUGH_GRADIENT, 1, 100,
// 440, 50, 0, 0);
for (int i = 0; i < circles.cols(); i++)
{
double[] vCircle = circles.get(0, i);
Point center = new Point(vCircle[0], vCircle[1]);
int radius = (int) Math.round(vCircle[2]);
// circle center
Imgproc.circle(src, center, 3, new Scalar(0, 255, 0), -1, 8, 0);
// circle outline
Imgproc.circle(src, center, radius, new Scalar(0, 0, 255), 3, 8, 0);
}
Imgcodecs.imwrite("F:dst2.jpg", src);
}
源图像:
输出图像:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章: