解决opencv在vs code中头文件找不到的问题

在一段程序中,有引用opencv头文件

#include 
#include 
#include 
#include 

尽管cmake会通过,但这时候vs code在这些下面会出现红色波浪线

无法打开 源 文件 "opencv2/core/core.hpp"
无法打开 源 文件 "opencv2/features2d/features2d.hpp"

这是为什么呢?
cmake会通过说明cmakelists里面代码链接是没有问题的,出现问题的地方在于vs code没有链接好opencv的头文件
解决方法如下:
先找到opencv头文件的位置

sudo find / -iname "*opencv*"

会出现

jianzhuozhu@jianzhuozhu-OptiPlex-9020:~$ sudo find / -iname "*opencv*"
/opt/ros/kinetic/include/opencv-3.3.1-dev
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/opencv.hpp
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/opencv_modules.hpp
/opt/ros/kinetic/bin/opencv_traincascade
/opt/ros/kinetic/bin/opencv_annotation
/opt/ros/kinetic/bin/opencv_interactive-calibration
/opt/ros/kinetic/bin/opencv_version
/opt/ros/kinetic/bin/opencv_createsamples
/opt/ros/kinetic/bin/opencv_waldboost_detector
/opt/ros/kinetic/bin/opencv_visualisation
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_videostab3.so.3.3
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_bgsegm3.so.3.3
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_flann3.so.3.3.1
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_videoio3.so.3.3

在vs code中ctrl+shift+p,选择C/C++: 编辑配置(UI),将如下路径添加到包含路径中

添加

/opt/ros/kinetic/include/opencv-3.3.1-dev
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2

即可
红色波浪线消失。

你可能感兴趣的:(linux)