2013年6月30日星期日

JavaCV Installation and Using it in Eclipse

I always use C++ with OpenCV libs for coding the computer vision program, but I just find a nice library called JavaCV (wrapper classes used for openCV). It allows anyone to use OpenCV functions directly in desktop Java. Now I can write computer vision program with Java, great!

The links below is a basic guide to help anyone port their OpenCV code to JavaCV.
http://code.google.com/p/javacv/wiki/ConvertingOpenCV

Here I give a very short intro about how to set up JavaCV and use it.
A.
Download OpenCV-2.4.5.exe and javacv-0.5-bin.zip, from:
http://sourceforge.net/projects/opencvlibrary/files/
http://code.google.com/p/javacv/

B.
Install OpenCV-2.4.5
Extract javacv-0.5-bin.zip

C.
set the environment variables:
the user variables for you, such as:
CLASSPATH → D:\project\opencv\build\x86\vc10\lib;
PATH → D:\project\opencv\build\java\x86;D:\project\opencv\build\x86\vc10\bin

D.
Start Eclipse
create new java project →
click next →
1. add project to the build path
2. in Libraries tab → Add External JARs... → add javacv-bin\javacpp.jar, javacv-bin\javacpp.jar, javacv-bin\javacv-windows-x86.jar
3. in Order and Export tab → click all of these libraries we added
→ click finish
in the project → add a new class


E.
Copy the test code below, to run the test program, copy a img.jpg in the project folder:

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;


public class test {
    /**
     * @param args
     */
10     public static void main(String[] args) {
11         IplImage img = cvLoadImage("tmp.jpg");
12         
13         cvShowImage("test image", img);
14         cvWaitKey();
15         cvReleaseImage(img);
16     }
17 }
18

F.
in the menu → Project → Build All → Run the project

没有评论: