CONFIGURE ECLIPSE WITH C++ AND OPENCV
ref:http://rodrigoberriel.com/2014/10/using-opencv-3-0-0-with-eclipse/
1. Assumed eclipse and cdt (C++ Development tools) already installed. if not, pls follow this:
a. Install C++ Development (CDT):
ref:https://eclipse.org/cdt/downloads.php
Help -> Install New Software -> Add… ->
Add Repository form:
Name: C++ Development Tools
Location: http://download.eclipse.org/tools/cdt/releases/8.8.1 (CDT 8.8.1 FOR ECLIPSE MARS)
b. Check All and Install
2. Creating a New C++ Project on Eclipse
a. File » New » C++ Project;
b. Give a name to your project in Project Name; for example: TestOpenCV
c. Choose Executable » Empty Project in Project Type;
d. Check Linux GCC in Toolchains and press Next;
e. Click on Finish;
3. Linking OpenCV to the newly created project
a. Select the project and go to the menu Project » Properties (or press Alt+ENTER);
b. We’re going to modify somethings on Tool Settings tab of C/C++ Build » Settings;
c. 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;
|
1 2 |
teddy@teddy-K43SJ:~$ pkg-config --cflags opencv -I/usr/local/include/opencv -I/usr/local/include |
d. 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;
|
1 2 |
teddy@teddy-K43SJ:~$ pkg-config --libs opencv -L/usr/local/lib -lopencv_cudabgsegm -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_stitching -lopencv_cudafeatures2d -lopencv_superres -lopencv_cudacodec -lopencv_videostab -lopencv_cudaoptflow -lopencv_cudalegacy -lopencv_cudawarping -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lippicv -lopencv_highgui -lopencv_videoio -lopencv_photo -lopencv_imgcodecs -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev |
e. 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
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
teddy@teddy-K43SJ:~$ cd /usr/local/lib/ teddy@teddy-K43SJ:/usr/local/lib$ ls *opencv*so libopencv_aruco.so libopencv_imgcodecs.so libopencv_bgsegm.so libopencv_imgproc.so libopencv_bioinspired.so libopencv_line_descriptor.so libopencv_calib3d.so libopencv_ml.so libopencv_ccalib.so libopencv_objdetect.so libopencv_core.so libopencv_optflow.so libopencv_cudaarithm.so libopencv_photo.so libopencv_cudabgsegm.so libopencv_plot.so libopencv_cudacodec.so libopencv_reg.so libopencv_cudafeatures2d.so libopencv_rgbd.so libopencv_cudafilters.so libopencv_saliency.so libopencv_cudaimgproc.so libopencv_shape.so libopencv_cudalegacy.so libopencv_stereo.so libopencv_cudaobjdetect.so libopencv_stitching.so libopencv_cudaoptflow.so libopencv_structured_light.so libopencv_cudastereo.so libopencv_superres.so libopencv_cudawarping.so libopencv_surface_matching.so libopencv_cudev.so libopencv_text.so libopencv_datasets.so libopencv_tracking.so libopencv_dnn.so libopencv_videoio.so libopencv_dpm.so libopencv_video.so libopencv_face.so libopencv_videostab.so libopencv_features2d.so libopencv_xfeatures2d.so libopencv_flann.so libopencv_ximgproc.so libopencv_fuzzy.so libopencv_xobjdetect.so libopencv_highgui.so libopencv_xphoto.so |
Done!
4. Lets test it!
a. Right-click on the project in Project Explorer and go to New » Folder;
b. Give a name to the folder, for instance: src.
c. Right-click on the src folder and go to New » File;
b. Give a name to the file, for instance: DisplayImage.cpp and type (or copy and paste) the code snippet below. Don’t forget to save the file.
|
1 2 3 4 5 6 7 8 9 10 11 |
#include <opencv2/opencv.hpp> using namespace cv; int main(void){ Mat inputImg=imread("/home/teddy/opencv/samples/data/lena.jpg"); imshow("Input Image",inputImg); waitKey(0); return 0; } |
Project » Build All (or Ctrl+B) to build;
5. Run the program
a. Right-click on the project in Project Explorer and go to Run As » Local C/C++ Application
b. The image should be appeared!!!