5/13/2015

Using OpenCV with Eclipse

Step1:
Download and install Opencv and Eclipse C++


Step2:
Launch Eclipse and create a C++ project and select Linux GCC

Go to "Properties/C/C++ Build/Settings/"
Select GCC C++ Linker/ Libraries
Paste each of them to "Libraries (-l)"
  opencv_core 
  opencv_highgui 
  opencv_features2d 
  opencv_superres opencv_video 
  opencv_calib3d opencv_flann 
  opencv_videostab 
  opencv_calib3d  
  opencv_objdetect 
  opencv_imgproc

You should check whether your opencv libraray exists in ldconfig by $ sudo ldconfig -v | egrep -i opencv.  If it does not exist in ldconfig, you should paste the specified library path to "Library search path(-L)" as follow:
  /usr/local/lib

If your opencv verison >= 3.0, you can paste them and you have opencv contrib module
  opencv_imgcodecs
  opencv_imgproc
  opencv_highgui
  opencv_ml
  opencv_rgbd
  opencv_core
  opencv_stereo
  opencv_viz
  opencv_video
  opencv_features2d
  opencv_calib3d
  opencv_objdetect
  opencv_flann


Step3:
Select GCC C++ Compiler/includes. You should check whether the header of your opencv. It might be placed in  /usr/include or /usr/local/include. So you can use $ find -iname 'opencv' first. After you find it, paste it to " include path(-l) "
 /usr/include  or /usr/local/include




Step4:
Paste the snippet of the code:

#include <opencv2/opencv.hpp> 
using namespace cv;
int main(int argc, char** argv)
{
    Mat inputImage = imread(argv[1]);
    imshow("Input Image", inputImage);
    waitKey(0);
    return 0;
}

Step5:
Ctrl+B to build it
Run the program using terminal: e.g.: $ ./main ~/lena.jpg

If cannot find opencv_core.xx.so at runtime, please add the bellow cmds to .bashrc
export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"

Related Reference:


No comments:

Post a Comment