windows10系统下安装opencv4.7.0+VSCode+(C++)环境搭建
1.VScode最新版
2.Opencv:opencv-4.7.0、opencv_contrib-4.7.0(扩展库,可自选是否安装)
3.MinGW-w64:选择GCCWindows版本
4.c-make工具:最新版,应选择二进制版本
注意:
打开解压好的vscode,运行code.exe进行安装配置,完成后,打开vscode配置c/c++扩展库(想中文显示面板,可在此查找中文插件,安装)。详细步骤如下:
将其安装包解压后再系统环境变量中添加并保存其bin的Path:如E:\MinGW\bin(避免非法字符)。然后再cmd中输入gcc -version,若如下显示则表示配置成功。
1.解压c-make包,运行cmake包中bin目录的cmake-gui.exe(如C:\cmake-3.26.0-rc3-windows-x86_64\bin)
注
如图,进行创建vscode代码的存储文件夹、配置json文件夹:
对应json文件配置内容如下所示:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"E:/Microsoft-VS-Code/opencv-4.7.0_build/install/include",
"E:/Microsoft-VS-Code/opencv-4.7.0_build/install/include/opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "E:/MinGW/bin/gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "E:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Compile"
}
]
}
注意:"command"中g++的配置,如:“E:/MinGW/bin/g++.exe”,以及其他路径的配置。libopencv_core470中的 “470” 表示对应的opencv版本。
{
"tasks": [
{
"label": "Compile",
"command": "E:/MinGW/bin/g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-m64",
"-Wall",
"-static-libgcc",
"-finput-charset=UTF-8",
"-fexec-charset=GBK",
"-std=c++17",
"-I",
"E:/Microsoft-VS-Code/opencv-4.7.0_build/install/include",
"-I",
"E:/Microsoft-VS-Code/opencv-4.7.0_build/install/include/opencv2",
"-L",
"E:/Microsoft-VS-Code/opencv-4.7.0_build/install/x64/mingw/lib",
"-l",
"libopencv_calib3d470",
"-l",
"libopencv_core470",
"-l",
"libopencv_dnn470",
"-l",
"libopencv_features2d470",
"-l",
"libopencv_flann470",
"-l",
"libopencv_gapi470",
"-l",
"libopencv_highgui470",
"-l",
"libopencv_imgcodecs470",
"-l",
"libopencv_imgproc470",
"-l",
"libopencv_ml470",
"-l",
"libopencv_objdetect470",
"-l",
"libopencv_photo470",
"-l",
"libopencv_stitching470",
"-l",
"libopencv_video470",
"-l",
"libopencv_videoio470"
],
"type": "process",
"problemMatcher": "$gcc",
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "E:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
#include<opencv2/opencv.hpp>
#include<opencv2/highgui.hpp>
using namespace cv;
int main()
{
Mat img=imread("C:/Users/Administrator/Desktop/test.jpg");
//Mat resize_img(img);
Size dsize = Size(round(0.3 * img.cols), round(0.3 * img.rows));//Size型 改变尺寸
resize(img, img, dsize, 0, 0, INTER_LINEAR); //使用双线性插值缩放一下尺寸
//resize(img, resize_img, Size(img.cols/7, img.rows/7));
cv::imshow("test",img);
cv::waitKey();
system("pause");
return 0;
}