vscode配置opencv
时间: 2023-10-02 08:06:24 浏览: 99
很高兴为您解答这个问题!您可以按照以下步骤完成vscode配置opencv:
1.首先下载并安装opencv,并将其添加到系统环境变量中;
2.打开vscode,新建一个cpp文件;
3.按下F1,然后输入“选择用户界面”,并选择“配置”;
4.在弹出的搜索栏中输入“c_cpp_properties.json”,并双击打开该文件;
5.在该文件中添加以下代码:
```
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/opencv/build/include/**"
],
"defines": [],
"intelliSenseMode": "msvc-x64",
"compilerPath": "C:/MinGW/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
```
注意:这里的“C:/opencv/build/include”应该替换成你自己的opencv安装路径;
6.保存并关闭该文件;
7.按下F1,然后输入“选择用户界面”,并选择“任务”;
8.在弹出的搜索栏中输入“tasks.json”,并双击打开该文件;
9.在该文件中添加以下代码:
```
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-IC:/opencv/build/include",
"-LC:/opencv/build/x64/mingw/lib",
"-lopencv_world410"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
```
同样需要注意更改“C:/opencv/build/include”和“C:/opencv/build/x64/mingw/lib”为你自己的安装路径;
10.保存并关闭该文件;
11.打开你的cpp文件,按下Ctrl + Shift + B,选择“build”任务,然后按下回车即可编译并运行你的程序了。
希望这能帮到您!
阅读全文