cmake
环境变量D:\Program Files\CMake\bin
w64devkit
官网https://github.com/skeeto/w64devkit/tags
环境变量D:\Program Files\w64devkit\bin
minGW32-make 拷贝并重命名为make
OpenCV
在执行完后,把关于python的都给取消勾选。勾选BUILD_opencv_world,WITH_OPENGL和BUILD_EXAMPLES,不勾选WITH_IPP、WITH_MSMF和ENABLE_PRECOMPILED_HEADERS(如果有的话),CPU_DISPATCH选空。
make -j 4
make install
环境变量D:\repocpp\opencv\build\x64\mingw\bin
vscode配置和测试
打开vscode按Ctrl+Shift+p,点击"C/C++:Edit Configurations(JSON)"就可以生成.vscode文件夹
launch.json
cpp
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Program Files\\w64devkit\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}
c_cpp_properties.json
cpp
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\include",
"D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\include\\opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
tasks.json
cpp
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\Program Files\\w64devkit\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\include",
"-I",
"D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\include\\opencv2",
"-L",
"D:\\repocpp\\opencv\\build\\x64\\mingw\\install\\x64\\mingw\\lib",
"-llibopencv_world455"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
},
],
"version": "2.0.0"
}
测试
拷贝opencv_videoio_ffmpeg455_64.dll,libopencv_world455.dll到项目根目录,文件所在目录D:\repocpp\opencv\build\x64\mingw\install\x64\mingw\bin
cpp
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap(0);
Mat img;
while (1)
{
cap >> img;
if (img.empty())
break;
namedWindow("img", WINDOW_NORMAL);
imshow("img", img);
if (27 == waitKey(20))
break;
}
return 0;
}