先写一段简单的opencv程序
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("zhiyin.jpg");
namedWindow("Display Image", WINDOW_NORMAL);
imshow("Display Image", image);
waitKey(0);
return 0;
}
然后按ctrl+shift+p
选择编辑配置
如图进行选择,这时会自动生成一个c_cpp_properties.json的文件
{
"configurations": [
{
"name": "Win32",
"intelliSenseMode": "gcc-x64",
"includePath": [
"${workspaceFolder}",
"D:\\opencv\\build\\include\\",
"D:\\opencv\\build\\include\\opencv2"
],
"defines": [],
"compilerPath": "D:/SysGCC/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"compilerArgs": [
"-fdiagnostics-color=always",
"-g"
],
"browse": {
"path": [
"${workspaceFolder}",
"D:\\opencv\\build\\include\\**"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
创建task.json,需要注意后面一堆-460的程序是在-L的bin文件夹下
{
"version": "2.0.0",
"tasks": [
{
"label": "build C++ program",
"type": "shell",
"command": "D:/SysGCC/mingw64/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"-I",
"D:/opencv/build/include",
"-L",
"D:/opencvtoolchains/bin",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-lopencv_calib3d460",
"-lopencv_core460",
"-lopencv_dnn460",
"-lopencv_features2d460",
"-lopencv_flann460",
"-lopencv_gapi460",
"-lopencv_highgui460",
"-lopencv_imgcodecs460",
"-lopencv_imgproc460",
"-lopencv_ml460",
"-lopencv_objdetect460",
"-lopencv_photo460",
"-lopencv_stitching460",
"-lopencv_video460",
"-lopencv_videoio460",
"-lopencv_videoio_ffmpeg460_64"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
}
]
}
最后按下ctrl+shift+B,即可生成exe文件,在终端执行即可。