Using OpenCV Java with Eclipse(转)

简介:   转自:http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html     Using OpenCV Java with Eclipse   Since version 2.

 

 

转自:http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html

 

 

Using OpenCV Java with Eclipse

 

Since version 2.4.4 OpenCV supports Java. In this tutorial I will explain how to setup development environment for using OpenCV Java with Eclipse inWindows, so you can enjoy the benefits of garbage collected, very refactorable (rename variable, extract method and whatnot) modern language that enables you to write code with less effort and make less mistakes. Here we go.

Configuring Eclipse

First, obtain a fresh release of OpenCV from download page and extract it under a simple location like C:\OpenCV-2.4.6\. I am using version 2.4.6, but the steps are more or less the same for other versions.

Now, we will define OpenCV as a user library in Eclipse, so we can reuse the configuration for any project. Launch Eclipse and selectWindow –> Preferences from the menu.

Eclipse preferences

Navigate under Java –> Build Path –> User Libraries and clickNew....

Creating a new library

Enter a name, e.g. OpenCV-2.4.6, for your new library.

Naming the new library

Now select your new user library and click Add External JARs....

Adding external jar

Browse through C:\OpenCV-2.4.6\build\java\ and selectopencv-246.jar. After adding the jar, extend theopencv-246.jar and select Native library location and pressEdit....

Selecting native library location 1

Select External Folder... and browse to select the folderC:\OpenCV-2.4.6\build\java\x64. If you have a 32-bit system you need to select thex86 folder instead of x64.

Selecting native library location 2

Your user library configuration should look like this:

Selecting native library location 2

Testing the configuration on a new Java project

Now start creating a new Java project.

Creating new Java project

On the Java Settings step, under Libraries tab, select Add Library... and select OpenCV-2.4.6, then click Finish.

Adding user defined library 1 Adding user defined library 2

Libraries should look like this:

Adding user defined library

Now you have created and configured a new Java project it is time to test it. Create a new java file. Here is a starter code for your convenience:

  1. import org.opencv.core.Core;
  2. import org.opencv.core.CvType;
  3. import org.opencv.core.Mat;
  4. public class Hello
  5. {
  6. public static void main( String[] args )
  7. {
  8. System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
  9. Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
  10. System.out.println( "mat = " + mat.dump() );
  11. }
  12. }
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

public class Hello
{
   public static void main( String[] args )
   {
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
      System.out.println( "mat = " + mat.dump() );
   }
}

When you run the code you should see 3x3 identity matrix as output.

Adding user defined library

That is it, whenever you start a new project just add the OpenCV user library that you have defined to your project and you are good to go. Enjoy your powerful, less painful development environment :)

转自:http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html

 

相关文章
|
6月前
|
Java Android开发
在Eclipse环境下调试Java程序
在Eclipse环境下调试Java程序
75 1
|
5月前
|
机器学习/深度学习 Java 开发工具
【移花接木】OpenCV4.8 For Java 深度学习 实时人脸检测
【移花接木】OpenCV4.8 For Java 深度学习 实时人脸检测
100 0
|
3月前
|
Java 网络安全 开发工具
新手入门Java。如何下载Eclipse、写出最基本的“Hello word”以及如何连接github并且上传项目。
新手入门Java。如何下载Eclipse、写出最基本的“Hello word”以及如何连接github并且上传项目。
56 0
|
4月前
|
存储 Oracle Java
Java面试题:描述如何使用Eclipse或IntelliJ IDEA进行Java开发?
Java面试题:描述如何使用Eclipse或IntelliJ IDEA进行Java开发?
47 0
|
4月前
|
关系型数据库 MySQL 数据库连接
解决在eclipse2021中,用mysql-connector-java-8.0.18.jar不兼容,导致无法访问数据库问题
解决在eclipse2021中,用mysql-connector-java-8.0.18.jar不兼容,导致无法访问数据库问题
105 0
|
5月前
|
IDE Java 开发工具
06. 【Java教程】Java 集成开发环境 - Eclipse
06. 【Java教程】Java 集成开发环境 - Eclipse
93 1
|
6月前
|
数据采集 Java 数据挖掘
最新Python+OpenCV+dlib汽车驾驶员疲劳驾驶检测!,2024年最新网易云java面试
最新Python+OpenCV+dlib汽车驾驶员疲劳驾驶检测!,2024年最新网易云java面试
最新Python+OpenCV+dlib汽车驾驶员疲劳驾驶检测!,2024年最新网易云java面试
|
6月前
|
Java Android开发
【Java开发指南 | 第十八篇】Eclipse安装教程
【Java开发指南 | 第十八篇】Eclipse安装教程
57 2
|
5月前
|
Java 开发工具 计算机视觉
Java使用OpenCV3.2实现视频读取与播放
Java使用OpenCV3.2实现视频读取与播放
63 0
|
6月前
|
Java 关系型数据库 应用服务中间件
JAVA Web项目开发eclipse工具包配置(第一天)
JAVA Web项目开发eclipse工具包配置(第一天)

推荐镜像

更多
下一篇
无影云桌面