C++ imread未在范围内声明(opencv ECLIPSE)

C++ imread未在范围内声明(opencv ECLIPSE),c++,eclipse,opencv,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; imag

这是一个代码。当我尝试在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;
    }
不知道该怎么办。有什么想法吗??我正在eclipse中运行代码。将opencv库加载到其中。我正在使用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

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

问题已解决,只需在c/c++的gcc链接器路径中添加一些库

对于Python:

在Eclipse IDE中

窗口->首选项->PyDev->解释器Python解释器包->使用pip管理->然后键入“安装cv”并单击运行

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

pip安装opencvpython

现在重新启动IDE。

对于c/c++:

对于Python:

在Eclipse IDE中

窗口->首选项->PyDev->解释器Python解释器包->使用pip管理->然后键入“安装cv”并单击运行

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

pip安装opencvpython


现在重新启动IDE。

从问题选项卡切换到控制台选项卡。您将找到更好的错误消息,并找到用于构建项目的命令。检查链接器命令行以确保您正在链接opencv库。如果您不确定,请编辑您的问题并粘贴到Console选项卡的内容中。您可以通过重新编制项目索引来解决这些问题。在Project Explorer窗格中,右键单击该项目,然后从弹出菜单中选择“索引->重建”。请查看@user4581301,我正在链接正确的库,此代码在没有Eclipse的情况下运行,您是对的。我倒着读。我道歉。未定义的引用是虚假的或过时的。请从“问题”选项卡切换到“控制台”选项卡。您将找到更好的错误消息,并找到用于构建项目的命令。检查链接器命令行以确保您正在链接opencv库。如果您不确定,请编辑您的问题并粘贴到Console选项卡的内容中。您可以通过重新编制项目索引来解决这些问题。在Project Explorer窗格中,右键单击该项目,然后从弹出菜单中选择“索引->重建”。请查看@user4581301,我正在链接正确的库,此代码在没有Eclipse的情况下运行,您是对的。我倒着读。我道歉。未定义的引用是虚假的或过时的。您能提供详细的解决方案吗?因为我遇到了相同的错误,无法确定该怎么办。您能提供详细的解决方案吗?因为我遇到了相同的错误,无法确定该怎么办。
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