安装 opencv + 致命错误:"opencv2/core.hpp"文件未找到



我已经使用官方安装程序安装了open cv:

https://docs.opencv.org/4.5.2/d0/db2/tutorial_macos_install.html

我在mac上做这个,这个过程花了3个小时。安装后,安装目录如下所示:

apple@Apples-MacBook-Air.local:~/Learning/openCV/cpp$  pwd
/Users/apple/Learning/openCV/cpp
apple@Apples-MacBook-Air.local:~/Learning/openCV/cpp$  ls
3rdparty            CTestTestfile.cmake     bin             data                 
opencv_data_config.hpp      setup_vars.sh
CMakeCache.txt          Makefile            cmake_install.cmake     doc              
opencv_lapack.h         test-reports
CMakeDownloadLog.txt        OpenCVConfig-version.cmake  cmake_uninstall.cmake        
include             opencv_python_config.cmake  tmp
CMakeFiles          OpenCVConfig.cmake      configured          lib              
opencv_python_tests.cfg     unix-install
CMakeVars.txt           OpenCVModules.cmake     custom_hal.hpp          modules              
opencv_tests_config.hpp     version_string.tmp
CPackConfig.cmake       apps                cv_cpu_config.h         opencv               
python_loader
CPackSourceConfig.cmake     basicOp.cpp         cvconfig.h          opencv2         
samples

现在,我正在编写一个非常简单的程序来测试安装,看起来我需要做的事情比我目前所做的要多。

我的简单程序:

#include<iostream>
#include<opencv2/core.hpp>
int main() {
std::string imagePath = samples.findFile("starry_night.jpg");
cv::Mat imageMatrix   = cv::imread(imagePath);
if(imageMatrix.empty()) {
std::cout << "Matrix is empty" << std::endl;
}
}

编译这个错误会产生如下错误:

apple@Apples-MacBook-Air.local:~/Learning/openCV/programs$  g++ imageRead.cpp 
imageRead.cpp:2:9: fatal error: 'opencv2/core.hpp' file not found
#include<opencv2/core.hpp>

没有问题,我可以理解,由于非链接的开放cv库。

所以,我用: 编译
apple@Apples-MacBook-Air.local:~/Learning/openCV/programs$  g++ imageRead.cpp -I/Users/apple/Learning/openCV/cpp/include -L/Users/apple/Learning/openCV/cpp/lib/

imageRead.cpp:2:9:致命错误:'opencv2/core.hpp'文件未找到# include

它仍然给我相同的错误。基本上,我传递了路径,让gcc考虑链接。

有什么建议吗?如果需要的话,我可以提供更多的细节。

您是否尝试了#include<opencv2/opencv.hpp>而不是#include<opencv2/core.hpp>?

相关内容

  • 没有找到相关文章

最新更新