C++ 不能使用 OpenCV 命名空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16299822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:14:57  来源:igfitidea点击:

Can't use OpenCV namespace

c++eclipseopencv

提问by Outback

I'm trying to install OpenCV and thought I was done... But this has errors:

我正在尝试安装 OpenCV 并认为我已经完成了......但这有错误:

#include <cv.h>
#include <highgui.h>

using namespace cv;

int main( int argc, char** argv )
{
}

Error: Symbol 'cv' could not be resolved

Error: Symbol 'cv' could not be resolved

But apparently the two includes include just fine. The code itself is taken from an example on OpenCV.org so I assume the code is right. And I'm too n00b to diagnose what the problem is, only vaguely knowing what namespaces are...

但显然这两个包括就很好。代码本身取自 OpenCV.org 上的一个示例,所以我认为代码是正确的。而且我太n00b无法诊断问题是什么,只能模糊地知道命名空间是什么......

回答by sansuiso

You are not including the C++ headers but the C ones. You should try to include files such as highgui.hpp, or the global opencv2.hppinstead.

您不包括 C++ 头文件,而是包括 C 头文件。您应该尝试包含诸如highgui.hpp, 或 global 之类的文件opencv2.hpp

If these files do not exist, you have to upgrade for a more recent version of the library. If they exist but your compiler can't find them, you have to use the -I/path/to/includeoption when compiling.

如果这些文件不存在,您必须升级库的更新版本。如果它们存在但您的编译器找不到它们,则必须-I/path/to/include在编译时使用该选项。

回答by PurpleAlien

You sure you're using a C++ compiler and not a C compiler? The code compiles fine from command line, e.g.,:

你确定你使用的是 C++ 编译器而不是 C 编译器?代码从命令行编译得很好,例如:

g++ -o opencv opencv.cpp -I/usr/include/opencv

Johan.

约翰。

回答by Marco Ruiz

You should include in the first space /usr/local/include in GCC C++ Compiler. See the next picture. enter image description here

您应该在 GCC C++ 编译器的第一个空间 /usr/local/include 中包含。看下一张图。 在此处输入图片说明

回答by Outback

I should have mentioned that I a running Linux. The problem was that I didn't have the library path configured. See section "Path Configuration" in this guide: http://opencv.willowgarage.com/wiki/InstallGuide_Linux

我应该提到我正在运行 Linux。问题是我没有配置库路径。请参阅本指南中的“路径配置”部分:http: //opencv.willowgarage.com/wiki/InstallGuide_Linux