【问题标题】:OpenCV hello world not compiling like it shouldOpenCV hello world 没有像它应该的那样编译
【发布时间】:2011-09-21 16:14:14
【问题描述】:

我正在使用 OpenCV 2.3.1 设置新机器。机器是Windows 7的机器,我按照OpenCV网站给出的安装说明(使用CMake和MinGW构建)。

这是我的代码:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main() {
    char var;
    cv::Mat img;
    img = cv::imread("C:/test/img.jpg");
    cv::namedWindow("Image");
    cv::imshow("Image", img);
    std::cin >> var;
    return 1;
}

这是我的 make 命令:

g++ -o main main.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy

这是我的路径:

C:\OpenCV-2.3.1\install\bin;C:\OpenCV-2.3.1\install\include;C:\QtSDK\QtCreator\bin;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CMake 2.8\bin;C:\QtSDK\mingw\bin;

这是我的错误:

main.cpp:2:33: error: opencv2/core/core.hpp: No such file or directory
main.cpp:3:39: error: opencv2/highgui/highgui.hpp: No such file or directory
main.cpp: In function 'int main()':
main.cpp:8: error: 'cv' has not been declared
main.cpp:8: error: expected ';' before 'img'
main.cpp:9: error: 'img' was not declared in this scope
main.cpp:9: error: 'cv' has not been declared
main.cpp:10: error: 'cv' has not been declared
main.cpp:11: error: 'cv' has not been declared

这没有意义。为什么编译不出来?为什么找不到opencv2/core/core.hpp?

【问题讨论】:

  • 你能发布一个你遵循的指令的链接吗?

标签: c++ opencv computer-vision


【解决方案1】:

g++ 在查找包含文件时不考虑%PATH%(Unix 上为$PATH)。

在编译命令中添加以下内容:-IC:\OpenCV-2.3.1\install\include:

g++ -IC:\OpenCV-2.3.1\install\include -o main main.cpp -lopencv_core ...

【讨论】:

  • 这是对 QT creator 无法正确编译的更多故障排除......同样的问题吗?
【解决方案2】:

您没有包含正确的 OpenCV 目录。

我在C:\OpenCV2.3 中安装了以前版本的 OpenCV,这些是我必须为我的编译器添加的路径以查找标头:

C:\OpenCV2.3\build\include\opencv

C:\OpenCV2.3\build\include\opencv2

C:\OpenCV2.3\build\include

传统上,g++ 使用带有 -I 标志的标头目录,您似乎根本没有使用它。

【讨论】:

    【解决方案3】:

    在像操作系统这样的unix上

         g++ filename.cpp -o exec `pkg-config opencv cvblob --libs --cflags`
    

    (如果您正在检查 blob,cvblob 可选)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      相关资源
      最近更新 更多