一个用于存储源图像的空垫对象。
一个要指定的字符串对象所需的文本。
指定文本位置的 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库向图像添加文本?的详细内容。