下载
首先,打开
OpenCV-MinGW-Build
,找到对应的
Releases
版本。这里以
OpenCV-4.5.5-x64 | zip | tar.gz
为例,我们点击下拉键
Configuration
:
MinGW-W64 x86_64-posix-seh
【下载最新版本即可】
Windows-11-64bit-22000.434
【Windwos 10也适配】
CMake-3.21.3
【一定要下载对应的版本,否则大概率会编译失败】
下载时有条件的建议搭梯子,负责下行速度很慢。
此处我的安装路径为:
C:\cmake-3.21.3-windows-x86_64
C:\opencv\opencv
C:\mingw64
编译
注意:编译过程有条件的尽量开
vpn
,否则编译过程中涉及相关软件下载可能会很慢甚至失败。注意:编译过程有条件的尽量开vpn,否则编译过程中涉及相关软件下载可能会很慢甚至失败。
打开
cmake-gui.exe
,文件存放在
C:\cmake-3.21.3-windows-x86_64\cmake-3.21.3-windows-x86_64\bin
目录下;
输入
source code
地址或者点击
Browse Source
选项选择对应的
source
路径;
输入
build
存放地址,可自己建立文件夹存放;
点击
Configure
按钮,选择
MinGW Makefiles
本地编译器:
不出意外的话,程序会开始自动生成
Makefiles
等文件配置,需要一段时间请耐心等待。
再次点击
Configure
后再点击
Generate
:
简单总结下:
finish
->
configuring done
->
configure
->
generate
打开
cmd
,
cd
至刚刚的构建目录下
C:/opencv/opencv/build/mingw64-build
,输入编译指令
minGW32-make -j8
,完成后再输入
minGW32-make install
:
将编译后的
C:\opencv\opencv\build\mingw64-build\bin
路径添加到环境变量:
运行
打开
VSCode
,在插件管理搜索对应的插件:
C/C++
:
到工作目录下的
.vscode
文件夹下新建三个文件:
c_cpp_properties.json
、
launch.json
以及
tasks.json
:
编写
c_cpp_properties.json
文件:
{ "configurations" : [ { "name" : "win" , "includePath" : [ "${workspaceFolder} /**" , /*此处修改为你对应的路径*/ "C:/mingw64/include" , "C:/opencv/opencv/build/mingw64-build/install/include" , "C:/opencv/opencv/build/mingw64-build/install/include/opencv2" ], "defines" : [ "_DEBUG" , "UNICODE" , "_UNICODE" ], /*此处修改为本机gcc编译器所在的对应路径*/ "compilerPath" : "C:/mingw64/bin/gcc.exe" , "cStandard" : "c11" , "cppStandard" : "c++17" , "intelliSenseMode" : "clang-x64" } ], "version" : 4 }
{ "version" : "0.2.0" , "configurations" : [ { "name" : "Opencv4.5.5 debug" , // 配置名称,将会在启动配置的下拉菜单中显示 "type" : "cppdbg" , // 配置类型,这里只能为cppdbg "request" : "launch" , // 请求配置类型,可以为launch(启动)或attach(附加) "program" : "${fileDirname} /${fileBasenameNoExtension} .exe" , // 将要进行调试的程序的路径 "args" : [], // 程序调试时传递给程序的命令行参数,一般设为空即可 "stopAtEntry" : false , // 设为true 时程序将暂停在程序入口处,一般设置为false "cwd" : "${workspaceFolder} " , // 调试程序时的工作目录,一般为${workspaceRoot} 即代码所在目录,根据自身情况设定为${fileDirname} "environment" : [], "externalConsole" : false , // 调试时是否显示控制台窗口,设置为true 时会弹出控制台出来,这个随意 "MIMode" : "gdb" , /*此处修改*/ "miDebuggerPath" : "C:/mingw64/bin/gdb.exe" , // miDebugger的路径,注意这里要与MinGw的路径对应 "setupCommands" : [ { "description" : "Enable pretty-printing for gdb" , "text" : "-enable-pretty-printing" , "ignoreFailures" : false } ], "preLaunchTask" : "Opencv4.5.5 compile task" // 需要与tasks.json中的`label`字段保持一致 } ] }
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version" : "2.0.0" , "tasks" : [ { "type" : "shell" , "label" : "Opencv4.5.5 compile task" , /*修改*/ "command"