Commit 5ee8293e authored by Bernat Gabor's avatar Bernat Gabor

Mixed up the linux_eclipse.rst file in the previous commit. Correcting it.

parent 762bc0f8
.. _Linux_Eclipse_Usage: .. _Linux_Eclipse_Usage:
Using OpenCV with Eclipse (plugin CDT) Using OpenCV with Eclipse (plugin CDT)
**************************************** ****************************************
.. note:: .. note::
For me at least, this works, is simple and quick. Suggestions are welcome For me at least, this works, is simple and quick. Suggestions are welcome
Prerequisites Prerequisites
=============== ===============
1. Having installed `Eclipse <http://www.eclipse.org/>`_ in your workstation (only the CDT plugin for C/C++ is needed). You can follow the following steps: 1. Having installed `Eclipse <http://www.eclipse.org/>`_ in your workstation (only the CDT plugin for C/C++ is needed). You can follow the following steps:
* Go to the Eclipse site * Go to the Eclipse site
* Download `Eclipse IDE for C/C++ Developers <http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/heliossr2>`_ . Choose the link according to your workstation. * Download `Eclipse IDE for C/C++ Developers <http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/heliossr2>`_ . Choose the link according to your workstation.
#. Having installed OpenCV. If not yet, go :ref:`here <Linux-Installation>`. #. Having installed OpenCV. If not yet, go :ref:`here <Linux-Installation>`.
Making a project Making a project
================= =================
1. Start Eclipse. Just run the executable that comes in the folder. 1. Start Eclipse. Just run the executable that comes in the folder.
#. Go to **File -> New -> C/C++ Project** #. Go to **File -> New -> C/C++ Project**
.. image:: images/a0.png .. image:: images/a0.png
:height: 400px :height: 400px
:alt: Eclipse Tutorial Screenshot 0 :alt: Eclipse Tutorial Screenshot 0
:align: center :align: center
#. Choose a name for your project (i.e. DisplayImage). An **Empty Project** should be okay for this example. #. Choose a name for your project (i.e. DisplayImage). An **Empty Project** should be okay for this example.
.. image:: images/a1.png .. image:: images/a1.png
:height: 400px :height: 400px
:alt: Eclipse Tutorial Screenshot 1 :alt: Eclipse Tutorial Screenshot 1
:align: center :align: center
#. Leave everything else by default. Press **Finish**. #. Leave everything else by default. Press **Finish**.
.. image:: images/a2.png .. image:: images/a2.png
:height: 400px :height: 400px
:alt: Eclipse Tutorial Screenshot 2 :alt: Eclipse Tutorial Screenshot 2
:align: center :align: center
#. Your project (in this case DisplayImage) should appear in the **Project Navigator** (usually at the left side of your window). #. Your project (in this case DisplayImage) should appear in the **Project Navigator** (usually at the left side of your window).
.. image:: images/a3.png .. image:: images/a3.png
:height: 400px :height: 400px
:alt: Eclipse Tutorial Screenshot 3 :alt: Eclipse Tutorial Screenshot 3
:align: center :align: center
#. Now, let's add a source file using OpenCV: #. Now, let's add a source file using OpenCV:
* Right click on **DisplayImage** (in the Navigator). **New -> Folder** . * Right click on **DisplayImage** (in the Navigator). **New -> Folder** .
.. image:: images/a4.png .. image:: images/a4.png
:height: 400px :height: 400px
:alt: Eclipse Tutorial Screenshot 4 :alt: Eclipse Tutorial Screenshot 4
:align: center :align: center
* Name your folder **src** and then hit **Finish** * Name your folder **src** and then hit **Finish**
.. image:: images/a5.png .. image:: images/a5.png
:height: 400px :height: 400px
:alt: Eclipse Tutorial Screenshot 5 :alt: Eclipse Tutorial Screenshot 5
:align: center :align: center
* Right click on your newly created **src** folder. Choose **New source file**: * Right click on your newly created **src** folder. Choose **New source file**:
.. image:: images/a6.png .. image:: images/a6.png
:height: 400px :height: 400px
:alt: Eclipse Tutorial Screenshot 6 :alt: Eclipse Tutorial Screenshot 6
:align: center :align: center
* Call it **DisplayImage.cpp**. Hit **Finish** * Call it **DisplayImage.cpp**. Hit **Finish**
.. image:: images/a7.png .. image:: images/a7.png
:height: 400px :height: 400px
:alt: Eclipse Tutorial Screenshot 7 :alt: Eclipse Tutorial Screenshot 7
:align: center :align: center
#. So, now you have a project with a empty .cpp file. Let's fill it with some sample code (in other words, copy and paste the snippet below): #. So, now you have a project with a empty .cpp file. Let's fill it with some sample code (in other words, copy and paste the snippet below):
.. code-block:: cpp .. code-block:: cpp
#include <cv.h> #include <cv.h>
#include <highgui.h> #include <highgui.h>
using namespace cv; using namespace cv;
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
Mat image; Mat image;
image = imread( argv[1], 1 ); image = imread( argv[1], 1 );
if( argc != 2 || !image.data ) if( argc != 2 || !image.data )
{ {
printf( "No image data \n" ); printf( "No image data \n" );
return -1; return -1;
} }
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE ); namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image ); imshow( "Display Image", image );
waitKey(0); waitKey(0);
return 0; return 0;
} }
#. We are only missing one final step: To tell OpenCV where the OpenCV headers and libraries are. For this, do the following: #. We are only missing one final step: To tell OpenCV where the OpenCV headers and libraries are. For this, do the following:
* * Go to **Project-->Properties**
Go to **Project-->Properties**
.. image:: images/a8.png
.. image:: images/a8.png :height: 400px
:height: 400px :alt: Eclipse Tutorial Screenshot 8
:alt: Eclipse Tutorial Screenshot 8 :align: center
:align: center
* In **C/C++ Build**, click on **Settings**. At the right, choose the **Tool Settings** Tab. Here we will enter the headers and libraries info:
*
In **C/C++ Build**, click on **Settings**. At the right, choose the **Tool Settings** Tab. Here we will enter the headers and libraries info: a. In **GCC C++ Compiler**, go to **Includes**. In **Include paths(-l)** you should include the path of the folder where opencv was installed. In our example, this is ``/usr/local/include/opencv``.
a. .. image:: images/a9.png
In **GCC C++ Compiler**, go to **Includes**. In **Include paths(-l)** you should include the path of the folder where opencv was installed. In our example, this is ``/usr/local/include/opencv``. :height: 400px
:alt: Eclipse Tutorial Screenshot 9
.. image:: images/a9.png :align: center
:height: 400px
:alt: Eclipse Tutorial Screenshot 9 .. note::
:align: center If you do not know where your opencv files are, open the **Terminal** and type:
.. note:: .. code-block:: bash
If you do not know where your opencv files are, open the **Terminal** and type:
pkg-config --cflags opencv
.. code-block:: bash
For instance, that command gave me this output:
pkg-config --cflags opencv
.. code-block:: bash
For instance, that command gave me this output:
-I/usr/local/include/opencv -I/usr/local/include
.. code-block:: bash
-I/usr/local/include/opencv -I/usr/local/include b. Now go to **GCC C++ Linker**,there you have to fill two spaces:
First in **Library search path (-L)** you have to write the path to where the opencv libraries reside, in my case the path is:
b. ::
Now go to **GCC C++ Linker**,there you have to fill two spaces:
/usr/local/lib
First in **Library search path (-L)** you have to write the path to where the opencv libraries reside, in my case the path is:
Then in **Libraries(-l)** add the OpenCV libraries that you may need. Usually just the 3 first on the list below are enough (for simple applications) . In my case, I am putting all of them since I plan to use the whole bunch:
::
/usr/local/lib opencv_core
opencv_imgproc
Then in **Libraries(-l)** add the OpenCV libraries that you may need. Usually just the 3 first on the list below are enough (for simple applications) . In my case, I am putting all of them since I plan to use the whole bunch: opencv_highgui
opencv_ml
* In **Libraries(-l)** add the OpenCV libraries that you may need. Usually just the 3 first on the list below are enough (for simple applications) . In my case, I am putting all of them since I plan to use the whole bunch: opencv_video
opencv_features2d
opencv_core opencv_calib3d
opencv_imgproc opencv_objdetect
opencv_highgui opencv_contrib
opencv_ml opencv_legacy
opencv_video opencv_flann
opencv_features2d
opencv_calib3d .. image:: images/a10.png
opencv_objdetect :height: 400px
opencv_contrib :alt: Eclipse Tutorial Screenshot 10
opencv_legacy :align: center
opencv_flann
If you don't know where your libraries are (or you are just psychotic and want to make sure the path is fine), type in **Terminal**:
* opencv_core .. code-block:: bash
* opencv_imgproc
* opencv_highgui pkg-config --libs opencv
* opencv_ml
* opencv_video
* opencv_features2d My output (in case you want to check) was:
* opencv_calib3d .. code-block:: bash
* opencv_objdetect -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
* opencv_contrib
* opencv_legacy Now you are done. Click **OK**
* opencv_flann
* Your project should be ready to be built. For this, go to **Project->Build all**
.. image:: images/Eclipse_Tutorial_Screenshot-10.png
:height: 400px .. image:: images/a11.png
:alt: Eclipse Tutorial Screenshot 10 :height: 400px
:align: center :alt: Eclipse Tutorial Screenshot 11
.. image:: images/a10.png :align: center
:height: 400px
:alt: Eclipse Tutorial Screenshot 10 In the Console you should get something like
:align: center
.. image:: images/a12.png
.. note:: :height: 200px
If you don't know where your libraries are (or you are just psychotic and want to make sure the path is fine), type in **Terminal**: :alt: Eclipse Tutorial Screenshot 12
:align: center
If you don't know where your libraries are (or you are just psychotic and want to make sure the path is fine), type in **Terminal**:
.. code-block:: bash If you check in your folder, there should be an executable there.
.. code-block:: bash Running the executable
========================
pkg-config --libs opencv
pkg-config --libs opencv So, now we have an executable ready to run. If we were to use the Terminal, we would probably do something like:
My output (in case you want to check) was: .. code-block:: bash
My output (in case you want to check) was:
cd <DisplayImage_directory>
.. code-block:: bash cd src
.. code-block:: bash ./DisplayImage ../images/HappyLittleFish.jpg
-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann Assuming that the image to use as the argument would be located in <DisplayImage_directory>/images/HappyLittleFish.jpg. We can still do this, but let's do it from Eclipse:
-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
Now you are done. Click **OK** #. Go to **Run->Run Configurations**
.. image:: images/a13.png
* Your project should be ready to be built. For this, go to **Project->Build all** :height: 300px
:alt: Eclipse Tutorial Screenshot 13
.. image:: images/Eclipse_Tutorial_Screenshot-11.png :align: center
.. image:: images/a11.png #. Under C/C++ Application you will see the name of your executable + Debug (if not, click over C/C++ Application a couple of times). Select the name (in this case **DisplayImage Debug**).
:height: 400px
:alt: Eclipse Tutorial Screenshot 11 #. Now, in the right side of the window, choose the **Arguments** Tab. Write the path of the image file we want to open (path relative to the workspace/DisplayImage folder). Let's use **HappyLittleFish.jpg**:
:align: center
.. image:: images/a14.png
In the Console you should get something like :height: 300px
:alt: Eclipse Tutorial Screenshot 14
.. image:: images/Eclipse_Tutorial_Screenshot-12.png :align: center
.. image:: images/a12.png
:height: 200px #. Click on the **Apply** button and then in Run. An OpenCV window should pop up with the fish image (or whatever you used).
:alt: Eclipse Tutorial Screenshot 12
:align: center .. image:: images/a15.png
:alt: Eclipse Tutorial Screenshot 15
If you check in your folder, there should be an executable there. :align: center
Running the executable
======================== #. Congratulations! You are ready to have fun with OpenCV using Eclipse.
\ No newline at end of file
So, now we have an executable ready to run. If we were to use the Terminal, we would probably do something like:
.. code-block:: bash
cd <DisplayImage_directory>
cd src
./DisplayImage ../images/HappyLittleFish.jpg
Assuming that the image to use as the argument would be located in <DisplayImage_directory>/images/HappyLittleFish.jpg. We can still do this, but let's do it from Eclipse:
#. Go to **Run->Run Configurations**
.. image:: images/Eclipse_Tutorial_Screenshot-13.png
.. image:: images/a13.png
:height: 300px
:alt: Eclipse Tutorial Screenshot 13
:align: center
#. Under C/C++ Application you will see the name of your executable + Debug (if not, click over C/C++ Application a couple of times). Select the name (in this case **DisplayImage Debug**).
#. Now, in the right side of the window, choose the **Arguments** Tab. Write the path of the image file we want to open (path relative to the workspace/DisplayImage folder). Let's use **HappyLittleFish.jpg**:
.. image:: images/Eclipse_Tutorial_Screenshot-14.png
.. image:: images/a14.png
:height: 300px
:alt: Eclipse Tutorial Screenshot 14
:align: center
#. Click on the **Apply** button and then in Run. An OpenCV window should pop up with the fish image (or whatever you used).
.. image:: images/Eclipse_Tutorial_Screenshot-15.png
.. image:: images/a15.png
:alt: Eclipse Tutorial Screenshot 15
:align: center
#. Congratulations! You are ready to have fun with OpenCV using Eclipse.
#. Congratulations! You are ready to have fun with OpenCV using Eclipse.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment