前置准备:配置MinGW和CMake
手把手教——class1_VScode配置C++环境_linux vscode cpp配置-CSDN博客文章浏览阅读398次,点赞4次,收藏6次。点击Windows x64 Installer:下载msi文件 安装完成后验证。配置gcc文件下bin环境。最后ctrl+F5运行尝试。Win+R 输入cmd。_linux vscode cpp配置https://blog.csdn.net/m0_66701835/article/details/143271400?spm=1001.2014.3001.5501
一.获取opencv文件(w版本需要镜像加速环境或ww)不会的直接下载跳过看部分二
1.下载Opencv
Releases - OpenCVhttps://opencv.org/releases/
2.安装解压
3.打开Cmake选择sources文件和你自己保存文件的路径
4.选择文件
5.去除和勾选以下部分
去除python部分(带python就不要勾选)
勾选BUILD_opencv_world,WITH_OPENGL和BUILD_EXAMPLES,不勾选WITH_IPP、WITH_MSMF和ENABLE_PRECOMPILED_HEADERS(如果有的话),CPU_DISPATCH选空。
重新点击Conf...和Gen...按钮
6.打开你选择的文件夹(我这里是cv2)再打开目录下的bin 输入cmd
7.输入minGW32-make -j 4
然后等待100%,搞定后续会教配置
二.直接下载配置完成的opencv文件
通过百度网盘分享的文件:opencv.zip
链接:https://pan.baidu.com/s/1RtHJ5RA0a28gcw0keDMzmQ?pwd=ki8g
提取码:ki8g
--来自百度网盘超级会员V3的分享
三.配置环境变量
第一个path是:opencv/build/x64/vc15/bin(安装自带)
第二个path是:opencv/build/x64/vc/bin(你创建的)
四.配置文件
1.tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "opencv3.5.2",
"command": "D:\\zhongyixi\\mingw\\mingw64\\bin\\g++.exe",//你的g++
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}\\Debugger\\${fileBasenameNoExtension}.exe",
//上面这个Debugger是我自己定义的,为了方便放置生成的exe文件
//下面都要更改
"D:\\zhongyixi\\opencv\\opencv4.5.3\\opencv\\build\\x64\\cv2\\bin\\libopencv_world453.dll",
"-I",
"D:\\zhongyixi\\opencv\\opencv4.5.3\\opencv\\build\\include",
"-I",
"D:\\zhongyixi\\opencv\\opencv4.5.3\\opencv\\build\\include\\opencv2",
],
"options": {
"cwd": "D:\\zhongyixi\\mingw\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
2.c_cpp_properties.json
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"D:\\zhongyixi\\opencv\\opencv4.5.3\\opencv\\build\\include",
"D:\\zhongyixi\\opencv\\opencv4.5.3\\opencv\\build\\include\\opencv2"
],
"defines": [],
"compilerPath": "D:/zhongyixi/mingw/mingw64/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
3.launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "opencv debuge",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\Debugger\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\zhongyixi\\mingw\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "opencv3.5.2"
},
//后面是系统生成的
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/user/Desktop/opencvC++/class1",
"program": "c:/Users/user/Desktop/opencvC++/class1/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
五.测试运行
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(void)
{
//更改为你的图片路径
cv::Mat img=cv::imread("C:\\Users\\user\\Desktop\\opencvC++\\k1.png");
cv::imshow("img",img);
cv::waitKey(0);
return 0;
}
选择下面进行调试
搞定就可以显示图片了