We will get throw some of these steps again. And before that I would like to precise that I am using Linux Ubuntu 14.04 LTS 64bits.
Directory organization
Eclipse workspace for OpenCV is:
/home/${user}/EclipseIDE/OpenCV/workspace/training/
- EclipseIDE/ : will contain Eclipse IDE and workspace for each technology.
It is easy to imagine that tomorrow I would like to use Eclipse for IOT or for Java project and workspace. For that, EclipseIDE will be the main directory.
From here I could create OpenCV, Java, IOT etc... sub dir for each related technology
- EclipseIDE/OpenCV/ : is the location of the eclipse software, and workspace for OpenCV development.
If I want to develop in Java, then I will have EclipseIDE/Java/ folder, etc ...
EclipseIDE/OpenCV/eclipse/ : is the location of the eclipse IDE itself.
from here it is possible to run the following command, which will launch eclipse
~/EclipseIDE/OpenCV/eclipse/eclipse
Once Eclipse will be launched, for the first time I will consider setting a workspace. To do so, I will choose :
/home/${user}/EclipseIDE/OpenCV/workspace/training/
- EclipseIDE/OpenCV/workspace/ : is the parent folder of all workspaces related to OpenCV Development. But to allow multiples eclipse session to run from this folder it is important to create sub directory for each specialized project
- EclipseIDE/OpenCV/workspace/training/ : is the folder I am going to set as base workspace for all our projects related to the training.
If I want to work on a real project I will set another folder for that. I could set
EclipseIDE/OpenCV/workspace/project001/ as an eclipse workspace for the corresponding project001. But for the moment, below is what I will set the first time I launch eclipse for this training:
~/EclipseIDE/OpenCV/workspace/training/
Eclipse Configuration
From a terminal here are the commands to launch eclipse.
| elyham@elyham-GL553VD:~$ elyham@elyham-GL553VD:~$ cd EclipseIDE/ elyham@elyham-GL553VD:~/EclipseIDE$ cd OpenCV/ elyham@elyham-GL553VD:~/EclipseIDE/OpenCV$ elyham@elyham-GL553VD:~/EclipseIDE/OpenCV$ eclipse/eclipse Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0 |
Select the workspace for eclipse. For me it will be the training folder.
OpenCV training workspace for eclipse
Eclipse version
As this version of eclipse (Helios) is reserved only for OpenCV development, let's continue eclipse configuration. Instead of configuring Eclipse for each project, as we did in the first article, let's set what is common for OpenCV trough Eclipse. So without creating any project at all, let's set Eclipse OpenCV for our convenience.
The thing we will not be allowed to configure at this stage, will be set later once a project will be created.
Remember as we are doing this it means this eclipse version will serve only for OpenCV development.
Once Eclipse has started, in Windows menu choose preferences
Windows --> Preferences
Preferences selection from Windows menu
From the current open windows, in General section from the left panel,
General --> Editors --> Text editors
set show line numbers
Show line numbers
Once it is set click on Apply.
C/C++ --> Build -->Makefile Editor --> Settings
Makefile Editor Settings
Click on 'new' to configure. On the new opened windows, move till openCV include dir
OpenCV include dir
Now that it is opened just click on OK button
Makefile Editor Settings updated
As we can see on the image above, the Makefile Editor Settings has been updated. Click on 'Apply' button to apply the modification.
I haven't found yet a way to configure the C++ linker. For this, I will do it for each project. For each project I would like to add only the one I will really use.
Now I need to configure runtime environment.
To do so, I just need to specify specific setting with the following value
name - LD_LIBRARY_PATH
Value - $LD_LIBRARY_PATH:/usr/local/lib
If you haven't got problem since the first part of these pages, this section is optional.
C/C++ --> Build --> Environment
Setting Build environment
From the above image just click Add... It will show the dialog box to set up the new variable
Before setting the value
Once the box is opened, set the value as shown on the image below
After setting the value
After setting the value as on the image, click on OK button.
Setting Build environment complete
To validate this change click on 'Apply' button, then move to the last part which is purely optional
C/C++ --> Code Style
The code below is the way I like it. To have the result below I have choose the
"BSD/Allman
Code style settings
Once selected, I will click on 'Apply' then on 'OK' button.
Create Eclipse Project
File --> new --> C++ Project
Lets create our first project, some kind of hello world, which will consist here of reading am image.
Project creation
Project name: "01-DisplayImage"
Project type: 'Empty Project'
Click 'Finish'
Let's create 'src' and 'res' folder
To do so, I will select the project then,
either
right click --> new --> Source Folder
or
File --> new --> Source Folder
For 'res' let choose
File --> new --> Folder
Source dir creation
Below, is the result
Result
'src' directory stands for sources files
'res' directory for resources files like the image we want to read.
Create C++ file
right click on src --> new --> Source File
New Source File
The result is below
Result
Let's build our file.
Display Image source
Let compil our source.
Compile Error
As we can see on the image above, the compilation failed. This happens during linking step.
Let's correct this by configuring the linker.
To show the 'Properties for 01-DisplayImage' project, I will select the project first by
- either typing Alt+Enter
- or right clicking on the project name then on Properties.
At the entry screen expand C/C++ Build and then select Settings.
On settings view move to GCC C++ Linker then select Libraries, which will lead to the below screen.
Properties for 01-DisplayImage
On the above screen lets add first Library path, and then Library
Add directory path
On the above screen click on 'File System ...' to select the path where library are located.
opencv lib path
After clicking on 'OK' the selected path will appear on the box as shown on the picture below.
Path updated
Click on OK to validate that path for the linker
lib path updated
Now, lets add Libraries name : opencv_core
opencv_core
Lets add the other library: opencv_highgui, opencv_imgcodecs
add others libs
once thoses 3 libraries are referenced, the windows will look like the image below.
Lib path and libs name are referenced
By cliking on 'Apply' button then OK, let build again.
New compilation
As we have just seen, the application is ready to be tested.
The first time I did this, I wasn't able to run the application due to a missing shared library. To solve this, we have already set the environment.
To do so, please connect to the section above where the following is mentioned
name - LD_LIBRARY_PATH
Value - $LD_LIBRARY_PATH:/usr/local/lib
Now let's run our application
The application will run cause the value above are already set.
Missing Img file
Let's create our resource in res directory
img/elyham.png : this is our real png file
img/wrongImg.png : this is a text file save as an png file
Let's Configure the file from Eclipse
Click on Run --> Run Configurations...
once opened, set on Arguments tab the following value by copy-paste
./res/img/wrongImg.png
wrong Argument
By clicking on run, the result is as shown on the picture below.
Missing data in png file
Let's update the Argument parameter with the good one as we can see on the picture below
By clicking on Run we have got a different result
Now we are ready to play a video or the built-in webcam of you laptop

































Aucun commentaire:
Enregistrer un commentaire