A small tutorial on integrating Eclipse, Qt and OpenCV

Created by Alin Brindusescu on 2011-01-23 13:21:40

A small tutorial on how configure Eclipse, Qt Library, Qt Integration plugin for Eclipse and the OpenCV library for developing image processing applications.
The tutorial can be use for any other external library. I have wrote this tutorial because I didn't knew how to add the OpenCV library path to a Qt Gui Project generated with the Qt Integration plugin for Eclipse and I spend some time finding out how to do this.

Some time ago I start to develop a small application using the Qt and OpenCV. Because sometime I'm not feeling comfortable with the vi editor I chose to use Eclipse with the CDT and Qt integration plugins. I will present all the steps that necessary for compiling such an application with more details of how to add the include and library's paths of the OpenCV. I found this a bit difficult and not documented anywhere and I had to spend two days trying to get the code compiled.

  • If you run an Microsoft Windoze machine you have to install first the MinGW tool set. Not my favorite OS and if you pay for that OS you should pay for help also :D.
    In the Linux environment you should have a look that the development tools are installed.
    You can find a lot of details about this procedure (for both Linux and windows) on the internet so I will not go into details here.
  • Download and install Eclipse with CDT plugin
  • Download and install the Qt library. If you have an Linux OS usually the Qt library is installed and you have to verify if you have at least version 4.1.0 for the Qt library, if you have an older version you have to install a newer version of the Qt library. I will not go too much in details here because this information can be found on the Trolltech website.
  • Download and install the Qt Eclipse integration plugin. The windows installer will do all the necessary things for you, in the Linux environment you have to unpack the content of the archive in the eclipse plugin directory with the usual
    tar zxvf
    command.
  • Download and install the OpenCV library.
    In the microsoft windoze environment the installer will do all the job for you and probably it will install the OpenCV in C:\\Program Files\\OpenCV.
    In the Linux environment you have to compile the OpenCV library by your own, let's say you downloaded the
    opencv-1.0.0.tar.gz
    and you are in the directory where you downloaded the OpenCV. Here are the steps needed to get the OpenCV installed:
    # tar zxvf opencv-1.0.0.tar.gz
    # cd opencv-1.0.0
    # ./configure --prefix=/usr/local
    # make
    # sudo make install
    
    After executing this steps (for the 1.0.0 version) the OpenCV headers files can be found here:
    /usr/local/include/opencv
    and the OpenCV librarys here:
    /usr/local/lib
    .
  • Now everything is on place and we can start creating an Qt Gui Application. The steps are similar for windoze and Linux with the only difference of the include and lib paths.
    Let's start creating one Qt Gui Project:



    In the first window of the Create Qt Gui Project we have to give a name for the project and select the path where the project will be created:



    After clicking Next we can change the filenames and select the type of the user interface (QDialog, QMainWindow and QWidget), in my example I chose QDialog to create a dialog based application.



    Clicking Next again the wizard will let us chose some other Qt modules to be included in the project.



    After clicking Finish and compiling the application, the result of the run will be a dialog like in the following picture:



    Now let's start configuring the generated project in order to be able to integrate the OpenCV support. Because the Makefiles of the project are generated automatically we can not add the include path and the library path by manually editing the Makefiles. For this reason we have to modify the .pro file of the created project.
    By double clicking on the .pro file (marked on blue on the following image) the project editor window will open, there we can chose to add more variable to the project (2) and if the Advanced Mode is selected we can give any name for the variable (3), if is not selected we can chose only from some standard defined variable names.


    To add the include path for the OpenCV include files we define first a new variable:



    With the Advanced More unselected (1) we can chose the variable name, "Include Path", from already defined list (2)



    To add the path to the variable we have to click on New button (1) from the Edit Include Path frame:



    Now we have to add the libdir and libs flags (how this should be done in the windows environment I'm not very sure).
    We make sure that the Advance Mode is selected, we create a New Variable (1) and we give the name LIBS to this variable (2) selecting the Append as Assignment Operator.



    We have to add the following content to the variable(2),
    -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux




    After all this steps are done now the project is ready to be compiled with OpenCV support and you can add all the include and functions of the OpenCV library to your source code.
    In the same way we can include any external library to a Qt Gui Project, by replacing the OpenCV with the library we need.


Comments: work in progress!

Search

Ads