opencv3_java 图像上加水印TextOnImg Rect

图像上加水印TextOnImg Rect


package opencv_java_demo;

import org.opencv.core.*;
import org.opencv.imgcodecs.*;
import org.opencv.imgproc.*;

public class TextOnImg {

	public static void main(String[] args) {
		try{
			System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
			
			Mat src=Imgcodecs.imread("./images/lenna.jpg");
			//读取图像到矩阵中
			if(src.empty()){
				throw new Exception("no file");
			}
			
			Mat dst = src.clone();
			//复制矩阵进入dst
			Point p=new Point(50.0,src.rows()/2-50);
			//定义文本输入点
			Imgproc.putText(dst, "hello opencv3", p, Core.FONT_HERSHEY_SIMPLEX, 0.8, new Scalar(50,60,80),2);
			//在dst图像中写入hello opencv3,2为字体粗度
			Imgcodecs.imwrite("./images/textonimg.jpg", dst);
			//输出图像
		}catch(Exception e){
			System.out.println("例外:" + e);
		}

	}

}





你可能感兴趣的:(java,opencv3)