ubuntu配置vscode c++ + opencv

ubuntu配置vscode c++ + opencv

ubuntu下配置c++和opencv需要三个文件

  • c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include/opencv2", //请确保你的opencv opencv2头文件夹安装在这个目录
                "/usr/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
  • launch.json
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "preLaunchTask":"build",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
  • tasks.json
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": ["-g", "${file}", "-o", "${fileBasenameNoExtension}.out",
                "-I", "/usr/local/include",
                "-I", "/usr/local/include/opencv",
                "-I", "/usr/local/include/opencv2/",
                "-L", "/usr/local/lib",
                "-l", "opencv_core",
                "-l", "opencv_imgproc",
                "-l", "opencv_imgcodecs",
                "-l", "opencv_video",
                "-l", "opencv_ml",
                "-l", "opencv_highgui",
                "-l", "opencv_objdetect",
                "-l", "opencv_flann",
                "-l", "opencv_imgcodecs",
                "-l", "opencv_photo",
                "-l", "opencv_videoio"
            ]
        }
    ]
}

测试文件

  • test_opencv.cpp
#include
#include
using namespace cv;
using namespace std;

int main()
{
     cout << "----------读摄像机内外参数----------"<< endl;
    // exit(0);
    Mat img=imread("/disk2/zhangheqing/face/Face_tools/ID_Faces/000000001_袁旺.jpg");  // 输入你自己的图片地址
    cv::imshow("image",img);
    cv::waitKey();

    return 0;
}

vscode配置文件和测试文件下载以及opencv下载

  • vscode配置文件和测试文件下载链接
  • opencv3.4.15和opencv_contrib3.4.15下载链接

你可能感兴趣的:(vscode)