imread 未在范围内声明(opencv-eclipse)
Posted
技术标签:
【中文标题】imread 未在范围内声明(opencv-eclipse)【英文标题】:imread not declared in scope (opencv-ecllipse) 【发布时间】:2017-07-20 17:41:55 【问题描述】:这是一个代码。当我尝试在 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 中运行代码。将 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
【问题讨论】:
从“问题”选项卡切换到“控制台”选项卡。您会发现更好的错误消息,并且您会发现用于构建项目的命令。检查链接器命令行以确保您正在链接 opencv 库。如果您不确定,请编辑您的问题并粘贴到控制台选项卡的内容中。 附录:问题列表中的前几项是由 Eclipse 自己生成的。您可以通过重新索引项目来解决它们。在 Project Explorer 窗格中,右键单击项目并从弹出菜单中选择 Index->Rebuild。 请立即查看@user4581301 我正在链接正确的库,这段代码在没有 Eclipse 的情况下运行 哈,你说得对。我是倒着读的。我很抱歉。未定义的引用是虚假的或陈旧的。 【参考方案1】:问题解决只需要在gcc链接器路径中添加一些库
【讨论】:
你能不能给出一个详细的解决方案,因为我遇到了同样的错误,不知道该怎么办。【参考方案2】:对于 c/c++:
How to use code completion into Eclipse with OpenCV
对于 Python:
在 Eclipse IDE 中,
窗口 -> 首选项 -> PyDev -> 解释器 -> Python解释器 -> Packages -> 使用 pip 管理 -> 然后输入 'install cv' 并点击 Run
现在,打开命令提示符并输入
pip install opencv-python
现在重新启动您的 IDE。
【讨论】:
以上是关于imread 未在范围内声明(opencv-eclipse)的主要内容,如果未能解决你的问题,请参考以下文章