JAVA在eclipse中配置Opencv

时间:2023-01-20 09:34:31

最近由于boss给安排了点硬件的活儿,所以一直没有写博客......

由于工程所需,我需要在eclipse中用JAVA调用Opencv进行图像处理

开始配置

1)下载、安装OpenCV2.4.10.0,我的安装目录是D:\opencv\opencv;第二个opencv里包含两个文件夹,如下图:

JAVA在eclipse中配置Opencv

2)配置

鼠标右击工程 -> 构建路径 -> 配置构建路径 -> 添加库,如下图:

JAVA在eclipse中配置Opencv

选择 “用户库” -> 下一步

JAVA在eclipse中配置Opencv

JAVA在eclipse中配置Opencv

JAVA在eclipse中配置Opencv

JAVA在eclipse中配置Opencv

JAVA在eclipse中配置Opencv

JAVA在eclipse中配置Opencv

JAVA在eclipse中配置Opencv

注意选择与你PC对应的版本,x86或x64

如果是x86,就选:D:\opencv\opencv\build\java\x86

如果是x64,就选:D:\opencv\opencv\build\java\x64

测试代码:

package com.lzw;
import org.opencv.core.*;
public class opencvTest{
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());
}
}

结果:

Welcome to OpenCV2.4.10.0
m = [1, 0, 0;
  0, 1, 0;
  0, 0, 1]