imread未在范围内声明(opencv-ecllipse)

时间:2017-07-20 17:41:56

标签: c++ eclipse opencv

这是一个代码。当我尝试在eclipse中构建它时,它说" imread"并且几乎所有函数都没有在范围中声明。

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

错误列表如下所示

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

不知道该怎么做。任何的想法 ??我在eclipse.Load opencv库中运行代码到它.i m使用ubuntu。 任何帮助都将得到满足

控制台消息:

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

2 个答案:

答案 0 :(得分:0)

问题解决了只需要在gcc链接器路径中添加一些库

答案 1 :(得分:0)

对于c / c ++:

How to use code completion into Eclipse with OpenCV

对于Python:

在Eclipse IDE中,

窗口-> 首选项-> PyDev -> 解释器-> Python解释器-> 软件包-> 通过点子管理->然后键入“ 安装简历”并单击“运行”

现在,打开命令提示符并键入

pip安装opencv-python

现在重新启动IDE。