1

Here is a code. when i try to build it in eclipse it says "imread" and almost all functions are not declared in the scope.

    #include <cv.h>
    #include <opencv2/opencv.hpp>
    #include <highgui.h>

    using namespace cv;

    int main( int argc, char** argv )
    {
      Mat image;
      image = imread( "download.jpg",0 );

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

List of errors are shown below

Description Resource    Path    Location    Type
make: *** [src/DisplayImage1.o] Error 1 DisplayImage            C/C++ Problem
make: *** [display] Error 1 display         C/C++ Problem
‘namedWindow’ was not declared in this scope    DisplayImage1.cpp   /DisplayImage/src   line 23 C/C++ Problem
‘imread’ was not declared in this scope DisplayImage1.cpp   /DisplayImage/src   line 15 C/C++ Problem
‘waitKey’ was not declared in this scope    DisplayImage1.cpp   /DisplayImage/src   line 26 C/C++ Problem
‘imshow’ was not declared in this scope DisplayImage1.cpp   /DisplayImage/src   line 24 C/C++ Problem
undefined reference to `cvRound'    display     line 929, external location: /usr/local/include/opencv2/core/types_c.h  C/C++ Problem
undefined reference to `cvRound'    display     line 930, external location: /usr/local/include/opencv2/core/types_c.h  C/C++ Problem
undefined reference to `cvFree_'    display     line 305, external location: /usr/local/include/opencv2/core/core_c.h   C/C++ Problem
undefined reference to `cvFree_'    display     line 313, external location: /usr/local/include/opencv2/core/core_c.h   C/C++ Problem
undefined reference to `cvGetRows'  display     line 382, external location: /usr/local/include/opencv2/core/core_c.h   C/C++ Problem
undefined reference to `cvGetCols'  display     line 408, external location: /usr/local/include/opencv2/core/core_c.h   C/C++ Problem
undefined reference to `cvReleaseMat'   display     line 477, external location: /usr/local/include/opencv2/core/core_c.h   C/C++ Problem

Don't know what to do. Any idea ?? i am running the code in eclipse.Load opencv library to it.i m Using ubuntu. Any help will be appriciated

console message:

make all 
Building file: ../src/DisplayImage.cpp
Invoking: Cross G++ Compiler
g++ -I/usr/local/include/opencv -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/DisplayImage.d" -MT"src/DisplayImage.d" -o "src/DisplayImage.o" "../src/DisplayImage.cpp"
Finished building: ../src/DisplayImage.cpp

Building file: ../src/DisplayImage1.cpp
Invoking: Cross G++ Compiler
g++ -I/usr/local/include/opencv -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/DisplayImage1.d" -MT"src/DisplayImage1.d" -o "src/DisplayImage1.o" "../src/DisplayImage1.cpp"
../src/DisplayImage1.cpp: In function ‘int main(int, char**)’:
../src/DisplayImage1.cpp:15:30: error: ‘imread’ was not declared in this scope
   image = imread( argv[1], 1 );
                              ^
../src/DisplayImage1.cpp:23:52: error: ‘namedWindow’ was not declared in this scope
   namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
                                                    ^
../src/DisplayImage1.cpp:24:34: error: ‘imshow’ was not declared in this scope
   imshow( "Display Image", image );
                                  ^
../src/DisplayImage1.cpp:26:12: error: ‘waitKey’ was not declared in this scope
   waitKey(0);
            ^
make: *** [src/DisplayImage1.o] Error 1
srk
  • 599
  • 1
  • 6
  • 17
  • Switch from the Problems tab to the Console tab. You will find better error messages and you will find the commands used to build the project. Check the linker command line to make sure you are linking the opencv library. If you aren't sure, edit your question and paste in the contents of the Console tab. – user4581301 Jul 20 '17 at 17:45
  • Addendum: the first few items in the Problems list are generated by Eclipse itself. You may be able to solve them by reindexing your project. In the Project Explorer pane, Right click the project and select Index->Rebuild from the pop-up menu. – user4581301 Jul 20 '17 at 18:06
  • please see now @user4581301 – srk Jul 20 '17 at 18:35
  • and i m linking the right libraries, this code is running without eclipse – srk Jul 20 '17 at 18:36
  • Ha., You're right. I read that backwards. My apologies. The undefined references were bogus or stale. – user4581301 Jul 20 '17 at 18:52
  • So what should i do – srk Jul 20 '17 at 19:05
  • Are DisplayImage and DisplayImage1 the same code in different files? In other words, one builds and the other doesn't? – user4581301 Jul 20 '17 at 22:04
  • No they are different @user4581301 – srk Jul 21 '17 at 06:30

2 Answers2

0

Problem solved just need to add some libraries in gcc linker path

srk
  • 599
  • 1
  • 6
  • 17
  • 2
    can you put a detailed solution because I am getting the same error and can't figure out what to do. –  Sep 23 '17 at 16:02
0

For c/c++:

How to use code completion into Eclipse with OpenCV

For Python:

In Eclipse IDE,

Window -> Preferences -> PyDev -> Interpreters -> Python Interpreter -> Packages -> Manage with pip -> then type 'install cv' and click Run

now, open Command Prompt and type

pip install opencv-python

now restart your IDE.

SidPro
  • 428
  • 1
  • 5
  • 16