gpt4 book ai didi

c++ - main.cpp :1:10: fatal error: opencv2/highgui. hpp:没有这样的文件或目录

转载 作者:行者123 更新时间:2023-12-02 10:23:50 27 4
gpt4 key购买 nike

我已经在 ubuntu 18.04 中安装了 opencv 并且安装成功,我试过这个命令:
$ pkg-config --modversion opencv
它的输出是: 4.0.1-开发
在此之后,我尝试朗姆酒 C++ 代码:

#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 输出 pkg-config --cflags --libs opencv
但它会引发 fatal error :
main.cpp:1:10: fatal error: opencv2/highgui.hpp: No such file or directory
#include <opencv2/highgui.hpp>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.

我已经查看了一些类似的问题,但我没有找到答案,我认为这是因为环境变量,我不知道我必须设置哪些变量。

最佳答案

在编译命令中,在“opencv”(或您的 OpenCV 版本号)旁边添加一个“4”:

$ g++ main.cpp -o output \`pkg-config --cflags --libs opencv4\`

关于c++ - main.cpp :1:10: fatal error: opencv2/highgui. hpp:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54912640/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com