The org.opencv.imgproc package of the Java OpenCV library contains a class called Imgproc. This class provides a method named circle(), which can be used to draw a Draw circles on the image. This method provides the following parameters:
Mat object representing the image of the circle to be drawn.
Represents the Point object at the center of the circle.
An integer variable representing the radius of the circle.
A Scalar object representing the circle color (BGR).
An integer representing the thickness of the circle (default is 1).
If the line type parameter is set to Imgproc.FILLED, this method will generate/draw a filled circle.
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class DrawingFilledCircle { public static void main(String args[]) { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading the source image in to a Mat object Mat src = Imgcodecs.imread("D:\images\blank.jpg"); //Drawing a Circle Point center = new Point(300, 200); int radius =100; Scalar color = new Scalar(64, 64, 64); int thickness = Imgproc.FILLED; Imgproc.circle (src, center, radius, color, thickness); //Saving and displaying the image Imgcodecs.imwrite("arrowed_line.jpg", src); HighGui.imshow("Drawing a circle", src); HighGui.waitKey(); } }
When executing the above program, it will be generated The following window −
The above is the detailed content of How to draw a filled circle in OpenCV using Java?. For more information, please follow other related articles on the PHP Chinese website!