Using OpenCV Java with Eclipse(转)
2015-03-29 22:39
549 查看
转自:http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html
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:
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?
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 :)
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
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?
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() );
}
}
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
相关文章推荐
- 利用Eclipse使用Java OpenCV(Using OpenCV Java with Eclipse)
- 利用Eclipse使用Java OpenCV(Using OpenCV Java with Eclipse)
- Using OpenCV Java with Eclipse
- 利用Eclipse使用Java OpenCV(Using OpenCV Java with Eclipse)
- Using OpenCV Java with Eclipse
- Using OpenCV Java with Eclipse
- 利用Eclipse使用Java OpenCV(Using OpenCV Java with Eclipse)
- Using OpenCV with Eclipse (plugin CDT)
- using opencv with eclipse(plugin cdt)
- Top 10 Java Debugging Tips with Eclipse
- eclipse配置java之opencv
- Intro-Using Java with Oracle db(notes)
- Top 10 Java Debugging Tips with Eclipse
- Top 10 Java Debugging Tips with Eclipse(Eclipse调试Java的10个技巧) .
- Eclipse : Class file name must end with .class exception in Java Search
- Eclipse中安装Java Opencv
- Opencv在eclipse(Java)的配置方法
- 在Eclipse下配置基于Java的OpenCV开发环境[官网译本]
- Eclipse+Java+OpenCV246环境搭建和代码测试
- Eclipse+Java+OpenCV310环境搭建和代码测试