Using OpenCV in eclipse

主宰稳场 提交于 2021-01-27 05:26:47

问题


I am trying to setup opencv in eclipse Luna. I have written a sample 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 have included /usr/local/include/opencv in (Project->Properties->C/C++ Build->Settings->Tool Settings -> GCC C++ Compiler -> Includes -> Include Paths. )

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

My output of the command pkg-config --cflags opencv is -I/usr/local/include/opencv -I/usr/local/include

and the output of pkg-config --libs opencv is

 -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 building 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 anyone help me fixing the problem and explain what is that I was missing.


回答1:


Try to change:

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

To this:

#include <opencv2/opencv.hpp>

You also need to link the Libraries (GCC C++ Linker » Libraries):

opencv_core
opencv_imgcodecs
opencv_highgui

You didn't say which version you are using, but as you have -lopencv_imgcodecs, you are probably using OpenCV 3. If you prefer, follow the instructions here. Also change from CV_WINDOW_AUTOSIZE to WINDOW_AUTOSIZE.



来源:https://stackoverflow.com/questions/32155611/using-opencv-in-eclipse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!