main.cpp:1:10: 致命错误: opencv2/highgui.hpp: 没有那个文件或目录 [英] main.cpp:1:10: fatal error: opencv2/highgui.hpp: No such file or directory
问题描述
我已经在 ubuntu 18.04 中安装了 opencv 并且安装成功,我试过这个命令:$ pkg-config --modversion opencv其输出为:4.0.1-dev在此之后,我尝试朗姆酒 C++ 代码:
I have install opencv in ubuntu 18.04 and it was installed successfully, I have tried this command: $ pkg-config --modversion opencv and its output is: 4.0.1-dev after this i have tried to rum c++ code:
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace std;
int main( int argc, char** argv ) {
cv::Mat image;
image = cv::imread("sample.jpeg" , CV_LOAD_IMAGE_COLOR);
if(! image.data ) {
std::cout << "Could not open or find the image" << std::endl ;
return -1;
}
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );
cv::imshow( "Display window", image );
cv::waitKey(0);
return 0;
}
使用这个命令::~/cpp_test$ g++ main.cpp -o output pkg-config --cflags --libs opencv
但它抛出了一个致命错误:
with this command: :~/cpp_test$ g++ main.cpp -o output pkg-config --cflags --libs opencv
but it throws a fatal error:
main.cpp:1:10: fatal error: opencv2/highgui.hpp: No such file or directory
#include <opencv2/highgui.hpp>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
我已经复习了一些类似的问题,但我没有找到答案,我认为这是因为环境变量的原因,我不知道我必须设置哪些变量.
I have reviewed some similar questions but i did not find my answer, i think this is because of environment variables and i do not know which variables i have to set.
推荐答案
在编译命令中,在opencv"旁边添加一个4"(或者你的 OpenCV 版本号):
In the compiling command add a "4" next to "opencv" (or the number of your version of OpenCV):
$ g++ main.cpp -o output \`pkg-config --cflags --libs opencv4\`
这篇关于main.cpp:1:10: 致命错误: opencv2/highgui.hpp: 没有那个文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!