前面都OK之后,还要记得添加opencv的环境变量,不然的话,后面会提示找不到libopencv_highgui348.dll等一系列dll文件
其中MinGW是我们自己新建的空文件夹,用来存放opencv经过cmake编译后的文件,D:\opencv\build\x64\MinGW\bin文件夹下存放的就是.dll文件
好,现在为止所有环境都搞定了,写个cpp试一下
#include<opencv2/opencv.hpp>
#include<opencv2/highgui.hpp>
using namespace cv;
int main()
{
Mat img=imread("D:/lzb-soft-dir/vs-code/test.jpg");
cv::imshow("image",img);
cv::waitKey();
return 0;
}
还要配置一下这三个文件
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: 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": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:/opencv/build/include",
"D:/opencv/build/include/opencv",
"D:/opencv/build/include/opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\mingw64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
tasks.json
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"D:/opencv/build/include",
"-I",
"D:/opencv/build/include/opencv",
"-I",
"D:/opencv/build/include/opencv2",
"-L",
"D:/opencv/build/x64/MinGW/lib",
"-l", "libopencv_core348",
"-l", "libopencv_imgproc348",
"-l", "libopencv_video348",
"-l", "libopencv_ml348",
"-l", "libopencv_highgui348",
"-l", "libopencv_objdetect348",
"-l", "libopencv_flann348",
"-l", "libopencv_imgcodecs348",
"-l", "libopencv_photo348",
"-l", "libopencv_videoio348"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
到这里差不多就OK了,执行一下exe