配置环境:MyEclipse2013+Jdk1.7(32位)+OpenCV 2.4.8+win8.1(64位)
OpenCV安装路径:d:\Users\opencv为例
1. 导入Jar包
在路径d:\Users\opencv\build\java下找到opencv-248.jar并导入至Java项目。
2. 配置dll路径
项目属性里导入的Jar包选择Native library location:(None),点击右侧Edit添加d:\Users\opencv/build/java/x86(32位的Jdk用x86路径)然后点击OK,配置完毕。
3. 示例程序
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to OpenCV " + Core.VERSION);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
}
时间: 2024-10-08 20:50:44