Home > Java > Java Tutorial > body text

How to draw filled ellipse in OpenCV using Java?

PHPz
Release: 2023-09-09 15:09:01
forward
534 people have browsed it

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.

Example

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();
   }
}
Copy after login

Output

After executing the above program, the following will be generated Window−

How to draw filled ellipse in OpenCV using Java?

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!