:::: MENU ::::

Using OpenCV 3.0.0 with Eclipse

Posted in October 19, 2014

In this article, we’re going to see how to use OpenCV with Eclipse. We’ll use their latest releases: OpenCV 3.0.0 alpha e Eclipse Luna for C/C++ Developers. We’ll pass from downloading Eclipse, by setting a project linked with OpenCV until the implementation of our program. Don’t forget to check out the video demonstration of this process at the end of this article.

-- Ubuntu 14.04 LTS 64 bits installed and updated;
-- OpenCV 3.0.0 alpha installed: How to install OpenCV 3.0.0 on Ubuntu

Let’s start!

Before we start, we’re going to need to download Eclipse. I use OpenCV with C++, then I’m going to download the specific release to C/C++ of Eclipse Luna: Eclipse IDE for C/C++ Developers.
Note: I didn’t add any image to exemplify each step, because there’s a video demonstration at the end. Watch the video: youtu.be/9ksMjQ2sBSQ!

Downloading and Installing Eclipse

  1. Go to Eclipse Downloads;
  2. In Package Solutions, search for Eclipse IDE for C/C++ Developers;
  3. Select Linux 32 or 64 bits; (in my case, Linux 64 bits);
  4. Unzip in any folder of your choice;
  5. Done!

You also can install Eclipse using sudo apt-get install eclipse-cdt

Creating a New C++ Project on Eclipse

  1. File » New » C++ Project;
  2. Give a name to your project in Project Name;
  3. Choose Executable » Empty Project in Project Type;
  4. Check Linux GCC in Toolchains and press Next;
  5. Uncheck Debug; (personal choice)
  6. Click on Finish;

Linking OpenCV to the newly created project

  1. Select the project and go to the menu Project » Properties (or press Alt+ENTER);
  2. We’re going to modify somethings on Tool Settings tab of C/C++ Build » Settings;
  3. In GCC C++ Compiler » Includes, add “/usr/local/include/opencv” in Include paths (-l). Discover the correct path by typing the following on the terminal: pkg-config --cflags opencv;
  4. Go to GCC C++ Linker » Libraries and add “/usr/local/lib” in Library search paths (-L). Discover the correct path by typing the following on the terminal:: pkg-config --libs opencv;
  5. Still in GCC C++ Linker » Libraries, add the libraries you’ll need in your project in Libraries (-l). We’re going to need 3 to our project (don’t forget to link opencv_imgcodecs, since imread() has moved to it in OpenCV 3):
    • opencv_core
    • opencv_imgcodecs
    • opencv_highgui
  6. Done!

Lets test it!

Can we build our programs using OpenCV in this project? Let’s test? Coming right up!

Creating and building our program

  1. Right-click on the project in Project Explorer and go to New » File;
  2. Give a name to the file, for instance: main.cpp and type (or copy and paste) the code snippet below. Don’t forget to save the file.
  3. Project » Build All (or Ctrl+B) to build;

Running the program

On the Terminal, go to the folder where you created the project(cd {workspace}/{project_name}/). Inside, you’re going to see our program (main.cpp) and the folder “Release/”. Access the folder Release and run our program.

./{project_name} {image}
E.g.: ./OpenCV ~/Images/lena.jpg

If your image has opened, congratulations! You just ran your first program using OpenCV with Eclipse.
Do you want to know how to run our program directly from Eclipse? Watch the video.

In case you have any question about how to execute any of the steps above, watch the video below demonstrating the whole process.

Do you still have questions? Has an error occurred?
Leave a comment or contact me.