简体   繁体   English

MinGW C++ 编译器在系统路径中找不到 OpenCV

[英]MinGW C++ compiler cant find OpenCV in the system path

So I'm getting an error stating "fatal error: opencv2\core\mat.hpp: No such file or directory" when trying to compile a small c++ file from.cpp with MinGW.因此,在尝试使用 MinGW 编译来自.cpp 的小型 c++ 文件时,我收到一条错误消息,指出“致命错误:opencv2\core\mat.hpp:没有这样的文件或目录”。 It happens in one form or another in Sublime Text 3, Atom, and on the command line with "gcc myfile.cpp".它以一种或另一种形式发生在 Sublime Text 3、Atom 和带有“gcc myfile.cpp”的命令行上。 I should note that I'm on Windows 10. Here's the code:我应该注意到我在 Windows 10 上。这是代码:

#include <iostream>
#include <opencv2\core\mat.hpp>
#include <opencv2\core.hpp>
#include <opencv2\highgui.hpp>
#include <opencv2\core\types.hpp>
#include <opencv2\imgproc.hpp>

int main()
{
    std::cout << "Hello World!\n";
    cv::Mat img = cv::imread("despair.jpg");
    cv::cvtColor(img, img, cv::COLOR_RGBA2GRAY, 1);
    cv::imshow("1", img);
    cv::waitKey(0);

    cv::Mat mask = cv::Mat(img.rows, img.cols, CV_8UC1, cv::Scalar(255));
    cv::Rect_ <char> roi = cv::Rect_ <cv::Point>(cv::Point(0, 0), cv::Point(10, 10));
    cv::rectangle(mask, roi, cv::Scalar(0), -1);
    cv::Scalar colors = cv::mean(img, mask);
}

Things I've done and tried:我做过并尝试过的事情:

  • Adding C:\OpenCV\opencv\build\include\ to the system path.将 C:\OpenCV\opencv\build\include\ 添加到系统路径。
  • Adding the bin and lib folders in x64/vc15 folder to the system path.将 x64/vc15 文件夹中的 bin 和 lib 文件夹添加到系统路径。
  • Messing and experimenting with the system path in general to try to find anything that might work.通常对系统路径进行混乱和试验,以尝试找到任何可能有效的方法。 (I've tried so many combinations at this point I've forgotten most of them) (此时我已经尝试了很多组合,我已经忘记了大部分)
  • Adding everything to my user specific path.将所有内容添加到我的用户特定路径。
  • Changing the include directory in the.cpp file to be the absolute path to each file I need to include (This works for the exact files I need, but then fails when those files try to include other files they need, like when Mat.hpp tries to include Matx.hpp)将 .cpp 文件中的包含目录更改为我需要包含的每个文件的绝对路径(这适用于我需要的确切文件,但是当这些文件尝试包含他们需要的其他文件时会失败,例如 Mat.hpp试图包含 Matx.hpp)
  • Reinstalling MinGW64.重新安装 MinGW64。
  • Installing MinGW to different folders and updating the system path to reflect the new location.将 MinGW 安装到不同的文件夹并更新系统路径以反映新位置。
  • Changing which text editor I'm using更改我正在使用的文本编辑器
  • Compiling from the command line outside of a text editor从文本编辑器外部的命令行编译

Things in my system path right now:现在我的系统路径中的东西:

  • C:\OpenCV\opencv\build\x64\vc15\lib C:\OpenCV\opencv\build\x64\vc15\lib
  • C:\OpenCV\opencv\build\x64\vc15\bin C:\OpenCV\opencv\build\x64\vc15\bin
  • C:\OpenCV\opencv\build\include\ C:\OpenCV\opencv\build\include\
  • C:\MinGW\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin C:\MinGW\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin

I took this code out of a larger project to test what was going on with it and at this point I'm at my wits end trying to figure out what's wrong.我将这段代码从一个更大的项目中取出来测试它发生了什么,此时我正在努力找出问题所在。 Please send help.请发送帮助。

Add -I option with path to opencv includes and -L with path to opencv libraries, like this:添加带有 opencv 路径的-I选项和带有 opencv 库路径的-L选项,如下所示:

gcc -IC:\OpenCV\opencv\build\include -LC:\OpenCV\opencv\build\x64\vc15\lib test_opencv.cpp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM