window下使用vscode 配置opencv环境
注释:工程位置不能有中文 1、安装vscode,网上搜索 2、下载mingw64 ,然后解压添加环境变量 参考:C:\MinGW\bin 3、下载opencv编译过文件,一般我们可以在csdn上找文件 参考:F:\opencv\build\x64\MinGw\install ,这是我下载的opencv文件夹,我们只需要install文件夹,然后拷贝到F: 添加环境变量:F:\install\x64\mingw\bin 4、下一步,打开vscode,创建一个main.cpp 文件
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap(0);
Mat img;
cout<<"jsy"<<endl;
while (1)
{
cap >> img;
if (img.empty())
break;
namedWindow("img", WINDOW_NORMAL);
imshow("img", img);
if (27 == waitKey(20))
break;
}
return 0;
}
点击 “运行”“启动调试” 会生成一个文件夹.vscode 然后配置里面三个文件
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"F:/install/include",
"F:/install/include/opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "F:/MinGW/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "F:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}
一般点击生成时,gdb.exe位置正确,就不用修改
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "F:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"F:/install/x64/mingw/bin/libopencv_world452.dll",
"-I","F:/install/include",
"-I","F:/install/include/opencv2"
],
"options": {
"cwd": "F:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
Ctrl + shift + p 进入命令面板
cmakeconfig 产生build文件夹 c/c++ edit编辑配置 产生 c_cpp_propro …这个文件,配置c/c++编辑环境, 参考链接 https://blog.csdn.net/zaf0516/article/details/96888644
|