Using OpenCV in Eclipse under Linux

For OpenCV 2.4.6.1 …
Installing and using Eclipse under Linux is pretty much straight forward when using the windows tutorial for Eclipse and OpenCV build tutorial for Linux. Here is a fast run through both combined which should get you going in half an hour, depending on you internet connection and cpu power.

– First make sure you have Eclipse installed. This can be done easily from Ubuntu’s Software Center or through the Eclipse website.

– Install all required libraries to download and build OpenCV:
apt-get install cmake -f
apt-get install libgtk2.0-dev -f
apt-get install libdc1394-22 -f
apt-get install libjpeg-dev -f
apt-get install libpng-dev -f
apt-get install libtiff-dev -f
apt-get install libjasper-dev -f
apt-get install libavcodec-dev -f
apt-get install libavformat-dev -f
apt-get install libswscale-dev -f
apt-get install python-dev -f
apt-get install python-numpy -f
apt-get install git -f

– next, clone the OpenCV 2.4.6.1 files from the online repository:
mkdir opencv
cd opencv
git clone https://github.com/Itseez/opencv.git

– then, build OpenCV from source:
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ../opencv/

– after building has been completed, install:
make
sudo make install

– now lets configure Eclipse:
Now, open Eclipse and select Window -> Preferences from the menu.
Next, navigate to Java  -> Build Path -> User Libraries and click New …
Enter the library name: OpenCV-2.4.6.1
Then click Add External JARs…
and browse to the bin folder under the opencv release directory created above (for example /home/homeUser/opencv/release/bin)
Next extend the opencv-300.jar dropdown menu, navigate to Native library location and press Edit…
Now navigate to the lib folder under the opencv release directory created above (ex: /home/homeUser/opencv/release/lib)

– with Eclipse configured we can now test the library:
Create a new Java program.
During creation, when the wizard asks for Java Settings, choose the Libraries tab and select Add Library…
Select OpenCV-2.4.6.1 and finish the wizard.
Now create a new package and inside this package a new class called Hello
Enter following code:

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() );
   }
}

And run your code. You should see a 3 by 3 matrix output, more or less looking like this:

mat = [ 1, 0, 0;
0, 1, 0;
0, 0, 1]

Well done, enjoy the coding!
references:
http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html#java-eclipse
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#required-packages