Ask Your Question
1

Eclipse opencv “not declared in the scope” errors at compilation

asked 2014-09-05 19:01:41 -0600

anna.sarp gravatar image

updated 2014-09-07 22:22:06 -0600

I am trying to run the following simple image display opencv program on ubuntu machine.

#include <opencv/cv.h>
#include <opencv/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;
}

when I try to compile it I get errors saying imread, namedWindow, waitKey were not declared in the scope. I followed the eclipse setup instructions on OpenCV website and added include paths(usr/local/include/opencv), library path(usr/local/lib) and library files (opencv_core, opencv_highgui, etc). Any suggestions on solvingthis?

edit retag flag offensive close merge delete

Comments

  • use "opencv2/core/core.hpp" and "opencv2/highgui/highgui.hpp" instead of the old c-headers.

  • include path should be /usr/local/include

berak gravatar imageberak ( 2014-09-08 01:23:53 -0600 )edit

1 answer

Sort by » oldest newest most voted
3

answered 2014-09-08 01:38:57 -0600

updated 2014-09-08 01:42:51 -0600

berak gravatar image

I think the opencv/-headers are just legacy and should be replaced by the opencv2-headers. If you have a look at the old headers, they just include the new opencv2-headers. I can compile your code with these headers:

   #include <opencv2/core/core.hpp>
   #include <opencv2/highgui/highgui.hpp>

   g++ foo.cpp  -lopencv_core -lopencv_highgui

But there are also a logical error: You use argv[1] before checking if argc is 2.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-09-05 19:01:41 -0600

Seen: 12,766 times

Last updated: Sep 08 '14