Using OpenCV in eclipse

I am trying to configure opencv in eclipse Luna. I wrote an example application as follows:

#include <cv.h>
#include <highgui.h>
#include<iostream>

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;
}

In my project properties, I included /usr/local/include/opencvin(Project->Properties->C/C++ Build->Settings->Tool Settings -> GCC C++ Compiler -> Includes -> Include Paths. )

and /usr/local/libin(Project->Properties->C/C++ Build->Settings->Tool Settings -> GCC C++ Linker -> Libraries -> Library Search Path. )

My command output pkg-config --cflags opencvis-I/usr/local/include/opencv -I/usr/local/include

and the output pkg-config --libs opencvis

 -L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_viz -lopencv_adas -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_face -lopencv_latentsvm -lopencv_objdetect -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_ml -lopencv_flann -lopencv_xobjdetect -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core -lopencv_hal

When I tried to build my project, I got the following errors.

‘imread’ was not declared in this scope 
‘imshow’ was not declared in this scope 
‘namedWindow’ was not declared in this scope    
‘waitKey’ was not declared in this scope    
Function 'imread' could not be resolved 
Function 'imshow' could not be resolved 
Function 'namedWindow' could not be resolved
Function 'waitKey' could not be resolved    

Can someone help me fix the problem and explain what I am missing.

+4
source share
1 answer

Try changing:

#include <cv.h>
#include <highgui.h>

For this:

#include <opencv2/opencv.hpp>

You also need to link the library libraries (GCC C ++ Linker):

opencv_core
opencv_imgcodecs
opencv_highgui

, , -lopencv_imgcodecs, , , OpenCV 3. , . CV_WINDOW_AUTOSIZE WINDOW_AUTOSIZE.

+6

All Articles