opencv3_java 图像的阈值图像生成Threshold Imgproc.threshold

来源:互联网 发布:amd 知乎 编辑:程序博客网 时间:2024/05/18 12:37

图像的阈值图像生成Threshold Imgproc.threshold


package opencv_java_demo;import org.opencv.core.*;import org.opencv.imgcodecs.*;import org.opencv.imgproc.Imgproc;public class Threshold {public static void main(String[] args) {try{System.loadLibrary(Core.NATIVE_LIBRARY_NAME);Mat src=Imgcodecs.imread("./images/lenna.jpg",Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);//读取图像到矩阵中,取灰度图像if(src.empty()){throw new Exception("no file");}Imgcodecs.imwrite("./images/in.jpg", src);//输出灰度图像值Mat dst=new Mat();//定义新矩阵Imgproc.threshold(src, dst, 100.0, 200.0, Imgproc.THRESH_BINARY_INV);Imgcodecs.imwrite("./images/threshold_THRESH_BINARY_INV.jpg", src);Imgproc.threshold(src, dst, 100.0, 200.0, Imgproc.THRESH_TRUNC);Imgcodecs.imwrite("./images/threshold_THRESH_TRUNC.jpg", src);Imgproc.threshold(src, dst, 100.0, 200.0, Imgproc.THRESH_BINARY);Imgcodecs.imwrite("./images/threshold_THRESH_BINARY.jpg", src);Imgproc.threshold(src, dst, 100.0, 200.0, Imgproc.THRESH_TOZERO);Imgcodecs.imwrite("./images/threshold_THRESH_TOZERO.jpg", src);Imgproc.threshold(src, dst, 100.0, 200.0, Imgproc.THRESH_TOZERO_INV);Imgcodecs.imwrite("./images/threshold_THRESH_TOZERO_INV.jpg", src);}catch(Exception e){System.out.println("例外:" + e);}}}









阅读全文
0 0
原创粉丝点击