vscode c++ opencv环境配置
时间: 2023-11-15 09:05:39 浏览: 54
要在VScode中搭建Opencv(C++开发环境),需要进行以下步骤:
1. 下载并安装MinGW和CMake,并将它们添加到系统环境变量中。
2. 下载并安装VScode,并在VScode中安装C++插件。
3. 下载Opencv,并将其解压到一个路径下。
4. 在VScode中打开一个C++项目,并在项目中创建一个名为.vscode的文件夹。
5. 在.vscode文件夹中创建一个名为c_cpp_properties.json的文件,并将以下代码复制到文件中:
```json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/opencv/build/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/mingw/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
```
6. 在.vscode文件夹中创建一个名为tasks.json的文件,并将以下代码复制到文件中:
```json
{
"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/vc15/lib",
"-lopencv_world452"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
```
7. 在VScode中打开一个.cpp文件,并按下Ctrl+Shift+B编译代码。