您可以使用 org.opencv.imgproc.imgproc 类 的 puttext() 方法向图像添加文本。此方法在给定图像中呈现指定文本。它接受 -
一个用于存储源图像的空垫对象。
一个要指定的字符串对象所需的文本。
指定文本位置的 Point 对象。
指定文本字体的整数常量.
立即学习“Java免费学习笔记(深入)”;
比例因子乘以特定于字体的基本尺寸。
指定颜色的标量对象text。
指定文本颜色的整数值
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 AddingText { 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\shapes.jpg"; Mat src = Imgcodecs.imread(file); //Preparing the arguments String text = "JavaFX 2D shapes"; Point position = new Point(170, 280); Scalar color = new Scalar(0, 0, 255); int font = Imgproc.FONT_HERSHEY_SIMPLEX; int scale = 1; int thickness = 3; //Adding text to the image Imgproc.putText(src, text, position, font, scale, color, thickness); //Displaying the resultant Image HighGui.imshow("Contours operation", src); HighGui.waitKey(); } }
以上就是如何使用Java OpenCV库向图像添加文本?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号