1、首先需要使用cmake工具配置opencv源码,生成mingw编译器对应的makefile文件
2、使用安装好的mingw-make 命令进行编译,时间较长半个小时(编译若遇到 hypot未定义,改成_hypot即可)
3、编译好之后,会在相应的install目录下包含所需要的头文件include、静态链接库lib、和动态链接库bin文件夹
4、配置vscode主要是对c_cpp_properties.json、task.jsion进行配置,加入头文件路径和静态链接库路径,动态链接库路径bin文件路径加入到环境变量中即可。
task.jsion文件:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g", //生成调试信息
"-Wall", //开启额外警告
"-static-libgcc", //静态链接
"-std=c++11" ,//c++新特性版本
//opencv 参数
"-I","D:/opencv/opencv-3.1.0/build/install/include",
"-I","D:/opencv/opencv-3.1.0/build/install/include/opencv",
"-I","D:/opencv/opencv-3.1.0/build/install/include/opencv2",
"-L","D:/opencv/opencv-3.1.0/build/install/x64/mingw/lib",
"-l","libopencv_core310",
"-l","libopencv_calib3d310",
"-l","libopencv_features2d310",
"-l","libopencv_flann310",
"-l","libopencv_highgui310",
"-l","libopencv_imgcodecs310",
"-l","libopencv_imgproc310",
"-l","libopencv_video310",
"-l","libopencv_photo310"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"echo":true,
"reveal": "always", //在终端显示信息的策略,可以为always,silent,never
"focus":false, //设置为true可使执行task时焦点聚集在终端.对c/c++意义不大
"panel": "shared" //不同的文件的编译信息共享一个终端面板
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$gcc"
}
]
}
c_cpp_properties.json文件:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
"D:/mingW64/mingw64/x86_64-w64-mingw32/include",
"D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed",
"D:/mingW64/mingw64/include",
"D:/opencv/opencv-3.1.0/build/install/include",
"D:/opencv/opencv-3.1.0/build/install/include/opencv",
"D:/opencv/opencv-3.1.0/build/install/include/opencv2"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/mingW64/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
luanch.json文件中"externalConsole": true,参数可以控制是否显示console终端,这里是需要的,因为要显示imshow展示的图像。