gpt4 book ai didi

linux - cmake 错误 : opencv2/opencv. hpp:opencv2/opencv.hpp:No such file or directory

转载 作者:太空宇宙 更新时间:2023-11-04 12:55:16 24 4
gpt4 key购买 nike

我正在用 cmake 编译 opencv 程序。 代码如下:

显示图像.cpp:

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}

Mat image;
image = imread( argv[1], 1 );

if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);

waitKey(0);

return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

project( DisplayImage )

set(OpenCV_DIR /home/lmk/opencv-3.1.0/release)

include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable( DisplayImage DisplayImage.cpp )

target_link_libraries( DisplayImage ${OpenCV_LIBS} )

我将 DisplayImage.cpp 和 CMakeLists.txt 放在我个人主文件夹中名为 test 的文件夹中,即 /home/lmk/test/。 然后我使用命令行:

lmk@lmk-virtual-machine:~/test$ mkdir build
lmk@lmk-virtual-machine:~/test$ cd build
lmk@lmk-virtual-machine:~/test/build$ cmake ..

哪个给我:

-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lmk/test/build

但是当我使用时:

Scanning dependencies of target DisplayImage
[100%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
/home/lmk/test/DisplayImage.cpp:2:30: fatal eror:opencv2/opencv.hpp:No such file or directory
compilation terminated.
make[2]: * [CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o] Error 1
make[1]: *
[CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 1

你知道为什么吗? 我在 VM 中的 ubuntu 14.04 终端中使用 opencv 3.1.0 和 cmake 2.8.12.2!

最佳答案

为什么不使用“典型”方式,使用 find_package()

尝试重复 this 中的步骤教程,并报告正在发生的事情。

关于linux - cmake 错误 : opencv2/opencv. hpp:opencv2/opencv.hpp:No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35935560/

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