【opencv】Java+eclipse+opencv 环境搭建 helloword入门demo
文章为博主原创,纯属个人理解,如有错误欢迎指出。
如需转载,请注明出处。
引入jar包
引入配置文件
到此环境配置完成!!!
可能会出现的问题:
1. jdk版本不一致导致发生异常。如图
build path 修改版本后,即可。
入门代码01:
1 package com.lw.test; 2 import org.opencv.core.Core; 3 import org.opencv.core.CvType; 4 import org.opencv.core.Mat; 5 6 public class OpenCVTest { 7 public static void main(String[] args) { 8 System.out.println("Welcome to OpenCV " + Core.VERSION); 9 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 10 Mat m = Mat.eye(3, 3, CvType.CV_8UC1); 11 System.out.println("m = " + m.dump()); 12 } 13 }
入门代码02:
1 package com.lw.test; 2 3 import org.opencv.core.Core; 4 import org.opencv.core.Mat; 5 import org.opencv.imgproc.Imgproc; 6 import org.opencv.imgcodecs.Imgcodecs; 7 8 public class OpenCVTest { 9 public static void main(String[] args) { 10 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 11 Mat img = Imgcodecs.imread("G:\\opencv01.png"); 12 Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2GRAY); 13 Imgproc.adaptiveThreshold(img, img, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 25, 10); 14 Imgcodecs.imwrite("G:\\opencv01_new.png", img); 15 } 16 }
欢迎opencv的坑,哈哈哈