如何在 Java 中使用 OpenCV 绘制一个圆?
在 Java OpenCV 库的 org.opencv.imgproc 包中,有一个名为 Imgproc 的类。
需要调用此类的 circle() 方法,才能画一个圆。此方法接受以下参数:-
一个 Mat 对象,代表需要绘制圆的图像。
一个 Point 对象,代表圆心。
一个整数变量,代表圆的半径。
一个 Scalar 对象,代表圆的颜色(BGR)。
一个整数,代表圆的粗细(默认值 1)。
示例
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 DrawingCircle {
public static void main(String args[]) {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//Reading the source image in to a Mat object
String file ="D:\images\blank.jpg";
Mat src = Imgcodecs.imread(file);
//Drawing a Circle
Point center = new Point(300, 200);
int radius = 100;
Scalar color = new Scalar(64, 64, 64);
int thickness = 10;
Imgproc.circle (src, center, radius, color, thickness);
//Saving and displaying the image
Imgcodecs.imwrite("circle.jpg", src);
HighGui.imshow("Drawing a Circle", src);
HighGui.waitKey();
}
}输出
执行以上程序时,将生成以下窗口:-

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP