Friday, November 13, 2015

Open CV installation in Eclipse Linux (Fedora20)

Important: make sure that the following packages have been installed
Checking List:
gtk+2.0
pkg-config 
cmake

Yum install gtk2
Yum install gtk2-devel 

Yum install pkgconfig 
Yum install cmake

Download OpenCV from this link. 

http://sourceforge.net/projects/opencvlibrary/files/latest/download?source=ty
p_redirect


OR(2nd one is tested)

http://softlayer-sng.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.4. 10/opencv-2.4.10.zip

Compile and install

cd your directory which will contain the source file tar -xvf OpenCV-2.4.*.tar.bz2

Next, go into the directory of OpenCV and establish a folder named release and enter it:

cd ~/OpenCV-2.4.*/ 
mkdir release
cd release


Now we are under the release folder and execute the following commands:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..

This piece of code will produce makefiles for further processes. Then, we will enter codes in the terminal:

make
sudo make install


===================ex
[exam10@localhost 3433]$ cd ..
[exam10@localhost ~]$ cd file:///home/exam10/random/OpenCV-2.3.1

bash: cd: file:///home/exam10/random/OpenCV-2.3.1: No such file or directory
[exam10@localhost ~]$ cd /home/exam10/random/OpenCV-2.3.1
[exam10@localhost OpenCV-2.3.1]$ mkdir release
[exam10@localhost OpenCV-2.3.1]$ cd release
[exam10@localhost release]$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
[exam10@localhost release]$ su Password:
[root@localhost release]# make install 


===========

1. GotoFile->New->C/C++Project




2. Chooseanameforyourproject(i.e.DisplayImage).AnEmptyProject
should be okay for this example.

3. Leaveeverythingelsebydefault.PressFinish.4. Yourproject(inthiscaseDisplayImage)shouldappearintheProject
Navigator (usually at the left side of your window).



5. Now,let’saddasourcefileusingOpenCV:
Right click on DisplayImage (in the Navigator). New -> Folder .



  • Name your folder src and then hit Finish
  • Right click on your newly created src folder. Choose New source
    file:
  • Call it DisplayImage.cpp. Hit Finish

6. So,nowyouhaveaprojectwithaempty.cppfile.Let’sfillitwithsome sample code (in other words, copy and paste the snippet below):

#include <cv.h> #include <highgui.h>
using namespace cv;
int main( int argc, char** argv ) {
Mat image;
image = imread( argv[1], 1 );

if( argc != 2 || !image.data ) {
printf( "No image data \n" );
return -1; }
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE ); imshow( "Display Image", image );
waitKey(0);
return 0; }

7. 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
In C/C++ Build, click on Settings. At the right, choose the Tool Settings Tab. Here we will enter the headers and libraries info:

1. 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.

Note
If you do not know where your opencv files are, open

the Terminal and type: pkg-config --cflags opencv
For instance, that command gave me this output: -I/usr/local/include/opencv -I/usr/local/include

2. 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:

/usr/local/lib

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_core opencv_imgproc opencv_highgui 
opencv_ml opencv_video opencv_features2d 
opencv_calib3d opencv_objdetect opencv_contrib 
opencv_legacy 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:

pkg-config --libs opencv

My output (in case you want to check) was: .. 
code-block:: bash

-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
Your project should be ready to be built. For this, go to
Project->Build all

In the Console you should get something like




If you check in your folder, there should be an executable there.

Running the executable
So, now we have an executable ready to run. If we were to use the Terminal, we would probably do something like:

cd <DisplayImage_directory>
cd src
./DisplayImage ../images/HappyLittleFish.png


Assuming that the image to use as the argument would be located in <DisplayImage_directory>/images/HappyLittleFish.png. We can still do this, but let’s do it from Eclipse:

       1. GotoRun->RunConfigurations
  1. UnderC/C++Applicationyouwillseethenameofyourexecutable+ Debug (if not, click over C/C++ Application a couple of times). Select the name (in this case DisplayImage Debug).
  2. Now,intherightsideofthewindow,choosetheArgumentsTab.Write the path of the image file we want to open (path relative to the workspace/DisplayImage folder). Let’s use HappyLittleFish.png: 

4. ClickontheApplybuttonandtheninRun.AnOpenCVwindowshould pop up with the fish image (or whatever you used).

5. Congratulations!YouarereadytohavefunwithOpenCVusingEclipse. 

No comments:

Post a Comment

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...