Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to draw a filled circle in OpenCV using Java?
The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. This class provides a method named circle(), using this you can draw a circle on an image. This method provides the following parameters −
A Mat object representing the image on which the circle is to be drawn.
A Point object representing the center of the circle.
An integer variable representing the radius of the circle.
A Scalar object representing the color of the circle(BGR).
An integer representing the thickness of the circle(default 1).
If you pass Imgproc.FILLEDas line type, this method generates/draws a filled circle.
Example
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();
}
}
Output
On executing, the above program generates the following window −

Advertisements