Using OpenCV in Eclipse under Linux

For OpenCV …
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 files from the online repository:
mkdir opencv
cd opencv
git clone

– then, build OpenCV from source:
mkdir release
cd release

– after building has been completed, install:
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-
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- 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!


One thought on “Using OpenCV in Eclipse under Linux

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s