Java OpenCV-4.0.0 图像处理12 图像边缘处理

Java OpenCV-4.0.0 图像处理12 图像边缘处理

Java OpenCV-4.0.0 图像处理12 图像边缘处理 添加边沿

package com.xu.image;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

/**  
 * 
 * @Title: OpenCV.java   
 * @Package com.xu.opencv   
 * @Description: TODO   
 * @author: xuhyacinth     
 * @date: 2019年1月17日 下午7:54:15   
 * @version V-1.0 
 * @Copyright: 2019 xuhyacinth
 *
 */
public class OpenCV {

	static {
		//在使用OpenCV前必须加载Core.NATIVE_LIBRARY_NAME类,否则会报错
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	}

	public static void main(String[] args) {
		copyMakeBorder();
	}

	/**
	 * OpenCV-4.0.0 边沿处理(添加边沿)
	 */
	public static void copyMakeBorder() {
		Mat src= Imgcodecs.imread("C:\\Users\\Administrator\\Pictures\\0001.jpg");
		Mat dst=new Mat();
		int top=(int)(src.rows()*0.05);
		int bottom=(int)(src.rows()*0.05);
		int left=(int)(src.cols()*0.05);
		int right=(int)(src.cols()*0.05);
		Core.copyMakeBorder(src, dst, top, bottom, left, right, Core.BORDER_CONSTANT,new Scalar(0, 0, 255));
		//BORDER_CONSTANT = 0,
		//BORDER_REPLICATE = 1,
		//BORDER_REFLECT = 2,
		//BORDER_WRAP = 3,
		//BORDER_REFLECT_101 = 4,
		//BORDER_TRANSPARENT = 5,
		//BORDER_REFLECT101 = BORDER_REFLECT_101,
		//BORDER_DEFAULT = BORDER_REFLECT_101,
		//BORDER_ISOLATED = 16;
		Imgproc.resize(dst, dst, new Size(dst.cols()/2,dst.rows()/2));
		HighGui.imshow("边沿处理(添加边沿)", dst);
		HighGui.waitKey(0);
	}

}


Java OpenCV-4.0.0 图像处理12 图像边缘处理_第1张图片

你可能感兴趣的:(Java,图形图像,OpenCV,图像处理,图像边缘处理,Java,OpenCV,OpenCV-4.0.0,图像处理)