您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何使用Java OpenCV库向图像添加文本?

2024/3/8 12:59:40发布16次查看
您可以使用 org.opencv.imgproc.imgproc 类 的 puttext() 方法向图像添加文本。此方法在给定图像中呈现指定文本。它接受 -
一个用于存储源图像的空垫对象。
一个要指定的字符串对象所需的文本。
指定文本位置的 point 对象。
指定文本字体的整数常量.
比例因子乘以特定于字体的基本尺寸。
指定颜色的标量对象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库向图像添加文本?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product