The org.opencv.imgproc package of the Java OpenCV library contains a class called Imgproc, which provides various methods for processing input images. It provides a set of methods for drawing geometric shapes on images.
This class provides a method called ellipse() with which you can draw an ellipse on the image, one of the variants of this method allows you to specify the line type as One of the parameters, including -
represents the position of the image's Mat object to draw the ellipse.
A RotatedRect object (The ellipse is drawn inscribed in the rectangle.)
A scalar Object, representing the color of the rectangle (BGR).
If you pass Imgproc.FILLED as argument, this method generates a filled Eclipse.
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.RotatedRect; import org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class DrawingFilledEllipse { 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 an ellipse RotatedRect box = new RotatedRect(new Point(300, 200), new Size(260, 180),180); Scalar color = new Scalar(64, 64, 64); int thickness = Imgproc.FILLED; Imgproc.ellipse(src, box, color, thickness); //Saving and displaying the image Imgcodecs.imwrite("arrowed_line.jpg", src); HighGui.imshow("Drawing an ellipse", src); HighGui.waitKey(); } }
After executing the above program, the following will be generated Window−
The above is the detailed content of How to draw filled ellipse in OpenCV using Java?. For more information, please follow other related articles on the PHP Chinese website!