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.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.


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


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


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


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....


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.


Your user library configuration should look like this:

Testing the configuration on a new Java project

Now start creating a new Java project.


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


Libraries should look like this:


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:

[java] view plaincopyprint?

  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.


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 :)

Help and Feedback

You did not find what you were looking for?

  • Ask a question on the Q&A forum.
  • If you think something is missing or wrong in the documentation, please file abug report.

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

 

时间: 2024-09-15 19:53:47

Using OpenCV Java with Eclipse(转)的相关文章

基于Java的Eclipse plug-in: 语言文字解码必备

需求背景 :TVT 测试中语言文字解码 在 TVT(Translation Verification Testing 翻译验证)测 试时,我们需要不断地将翻译成各种语言的 PII(Programmed Integrated Information 程序集成信息)文件 更新到我们的资源文件中,用于我们测试.对于资源文件的管理,我们大部分时候都会用到 RTC.但就 RTC 本身,或者说 eclipse 平台本身并不提供一种途径显示这些翻译后的文字本来的样子(就是以本国文字的形 式来显示),大量的信息

java安装eclipse中的问题求教,希望可以帮到我

问题描述 java安装eclipse中的问题求教,希望可以帮到我 ****新手不会安装eclipse请教怎么安装eclipse,新手一个,真的不会,还好学java比较的书籍是什么,在学校过程中需注意什么 解决方案 1.eclipse是不需要安装的,只需要解压后双击eclipse.exe即可运行,eclipse和tomcat的绿色版类似,都必须要安装jdk环境,并且要配置环境变量,配置环境变量的方法就不多说了,网上一大堆,就不再这里给你说了:2.至于说学java那本书好,刚开始接触学习的时候,个人

java用eclipse打包成jar后如何不需要控制台窗口

问题描述 java用eclipse打包成jar后如何不需要控制台窗口 是一个有gui的jar项目,但我不想运行他时有个黑色窗口.另外,我向只要双击就能运行它,而不是要到命令行去开启 解决方案 Eclipse把Java工程打包成jar使用Eclipse把java文件打包成jar用eclipse将Java工程打包成jar包 解决方案二: 那可以把命令存为bat执行文件,双击bat就能达到你要的效果 解决方案三: 在cmd中直接输入"java -jar xxx.jar"就可以运行这个jar文

java在eclipse上能连接sql2012数据库,为什么打包成jar后就不行了?

问题描述 java在eclipse上能连接sql2012数据库,为什么打包成jar后就不行了? java在eclipse上能连接sql2012,用Fat jar打包成jar后就不行了.为什么?之前没下载过什么sqljdbc.jar.sqljdbc4.jar的驱动也能连接的呀.最后在网上下载了驱动一同打包后还是没能连接成功.classpath什么的也不会配置.求教!已附上错误提示图 解决方案 打包的时候选择方式问题,把引用的包也要打包,你是用eclipse打包的吗?有三个选项,你得好好看看 解决方

How to decompile class file in Java and Eclipse - Javap command example(转)

  Ability to decompile a Java class file is quite helpful for any Java developer who wants to look into the source of any open source or propriety library used in project. Though I always prefer to attach source in Eclipse of most common libraries li

基于Java的Eclipse plugin开发概述

但 RTC 本身,或者说 eclipse 平台本身并没有一种很方便的途径让我们清楚地辨别出这些资源文件中的内容,而大量的信息只能以 Unicode 方式显示:例如:\u7675.因此我们急需一个工具或插件(eclipse plugin)自动地进行解码,来解决我的问题.这样我们所看到的将不再是让人费解的 Unicode,而是解码后的文字显示.(在刚才的例子中,会显示为"癵").总之,这个工具无论是对于http://www.aliyun.com/zixun/aggregation/7155

JAVA EE Eclipse下配置Tomcat服务器

在进行Java web编程之前,必须要进行web服务器的配置,这里选择在Java EE(版本) Eclipse中进行服务器的配置.当然了,在安装Java EE Eclipse之前要先安装JDK,并且要在环境变量中配置好JDK的安装目录,在这里不再多说,如果不清楚,可以看前面写的一篇"在win7下面安装JDK(以32位系统为例)"的文章.这里就假设你已经安装好了JDK,并且已经配置好环境变量.      Java EE Eclipse可以去Eclipse公司的网页上去下载最新版本的,但是

Java开发 Eclipse使用技巧(转)

1.如何设置默认的代码目录为src,默认的输出目录为bin? window->Preferences->java->Buil Path中,右侧选择Folders就可以 2.如何为快速局部变量设置getX,setX属性?在代码里->右键->source->Generae Getters and Setters,然后在弹出的对话框里,把要加的属性前打勾 3.快速增加try-catch语句块光标放到出错行,然后ctrl+1,在下拉列表里选择 4.eclipse保存时自动编译,

java IDE Eclipse

图标欣赏: 官网下载即可,eclipse-java-kepler-SR1-win32-x86_64 只有150M. 中文注释字体过小,设置办法,Window|Preferences|General|Appearance|Colors and Fonts|basic"的Text Font.设为14就好.   调试: 调试时,栈里面的变量会自动出现在监视窗口中.对于基本数据类型,"Value"就是值,对于复杂数据类型,"Value"就是类型名,且下方的小窗口会