如何使用Java在OpenCV中绘制一个填充的圆形?

Java OpenCV库的org.opencv.imgproc包中包含一个名为Imgproc的类。这个类提供了一个名为circle()的方法,使用它可以绘制一个 在图像上绘制圆圈。该方法提供以下参数:

  • 表示要绘制圆圈的图像的Mat对象。

  • 表示圆圈中心的Point对象。

  • 表示圆圈半径的整数变量。

  • 表示圆圈颜色(BGR)的Scalar对象。

  • 表示圆圈的厚度的整数(默认为1)。

如果将线型参数设置为Imgproc.FILLED,该方法将生成/绘制一个填充的圆圈。

示例

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(); } }登录后复制