Update: These
instructions are also applicable for 2.4+ version of opencv and
javacv.I was looking for image processing library for Java. My
search stopped at JavaCV. JavaCV provides wrappers for OpenCV. so you can directly use
OpenCV functions in Java. JavaCV also provides hardware
accelerated full screen Image display with CanvasFrame and
GLCanvasFrame.
JavaCV
provides jar files which can be used with OpenCV
installation. Following steps can be followed to setup JavaCV with Eclipse on Windows 7.
1.Install Java Development Kit (JDK) from
the link below. Make sure to install 32bit or 64 bit as per your
processor.
http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u32-downloads-1594644.html
2. Install Microsoft Visual C++ redistributable
package
For 32 bit:
http://www.microsoft.com/download/en/details.aspx?id=5555For
64 bit:
http://www.microsoft.com/download/en/details.aspx?id=14632
3. Download OpenCV super-pack from Sourceforge and
extract it in you C:\Opencv
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/
4. Set OpenCV .dll in systems path so that
JavaCV can access it.
Go to Control Panel > System Security > System
> Advanced System Settings > Environment Variables
In
System
variable select
path and click on
Edit. Now add following
address in Variable address. I have extracted opencv package in C:\ directory.
If you have installed at different location please update address accordingly.
For OpenCV 2.4.2 and earlier version For 32
bit:
C:\opencv\build\x86\vc10\bin;C:\opencv\build\common\tbb\ia32\vc10\For
64
bit:
C:\opencv\build\x64\vc10\bin;C:\opencv\build\common\tbb\intel64\vc10\
For OpenCV 2.4.3 and later version For 32
bit:
C:\opencv\build\x86\vc10\binFor 64
bit:
C:\opencv\build\x64\vc10\binOnce this is
done, the most important step is to
Restart Windows.
5. Download JavaCV- bin from link below and extract
it.
http://code.google.com/p/javacv/downloads/list
6. Create New Java Project 'demo' in Eclipse.
Once created, go to Project > Properties >
Java Build Path > Libraries > Add External JARs .Go to your JavaCV
Extracted folder and add all jar files. It should look like the pic
below
7. Now create demo.java in src folder of the
project.
Paste following code and run the project.Put your image in project
folder. In my case it is
'img1.png'<div>import static com.googlecode.javacv.cpp.opencv_core.*;<p>import static com.googlecode.javacv.cpp.opencv_highgui.*;</p><p>import com.googlecode.javacv.CanvasFrame;</p><p>public class demo {</p><p> public static void main(String[] args) {</p><p> //Load image img1 as IplImage</p><p> final IplImage image = cvLoadImage("img1.png");</p><p> //create canvas frame named 'Demo'</p><p> final CanvasFrame canvas = new CanvasFrame("Demo");</p><p> //Show image in canvas frame</p><p> canvas.showImage(image);</p><p> //This will close canvas frame on exit</p><p> canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); </p><p> } </p><p>}</p></div>
view
raw demo.java
hosted with ❤ by GitHub
Result will look like this