如何使用 Java OpenCV 库在图像上绘制标记?
您可以使用 org.opencv.imgproc.Imgproc 类的 drawMarker() 方法在图像上绘制标记。此方法接受以下参数 −
img − 表示输入图像的 Mat 对象。
position − 类 Point 的一个对象,用于指定标记的位置。
color − 类 Scalar 的一个对象,用于指定标记的颜色。
markerType − 指定标记类型的一个整数常量。
size − 指定标记大小的一个整数值。
thickness − 指定标记粗细的一个整数值。
示例
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 DrawingMarkers {
public static void main(String args[]) throws Exception {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//Reading the contents of the image
String file ="D:\Images\elephant.jpg";
Mat src = Imgcodecs.imread(file);
//Preparing color and position of the marker
Scalar color = new Scalar(0, 0, 125);
Point point = new Point(150, 260);
//Drawing marker
Imgproc.drawMarker(src, point, color, Imgproc.MARKER_SQUARE, 150, 8, Imgproc.LINE_8);
HighGui.imshow("Drawing Markers", src);
HighGui.waitKey();
}
}输入图像

输出
在执行上述程序时会生成以下窗口 −

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