一、编译器的选择
由于MSVC较大,一系列配置比较花时间,于是使用QT内的MinGW来编译工程。OpenCV官方目前只有MSVC编译器的库,MinGW的库在Github也有大佬已经分享:
github.comhttps://github.com/huihut/OpenCV-MinGW-Build/releases
如果QT使用MinGW编译器,那么OpenCV也需要MinGW编译再调用。
二、库的选择
MinGW编译的OpenCV的库相对MSVC来说更分散。
1、MSVC编译的 lib 库:

2、MinGW编译的 lib 库只有.a后缀的类Unix的静态库,不是Windows的.lib后缀:

3、MSVC编译的 bin 动态库:

4、MinGW编译的 bin 动态库:

因此Windows下只能调用 bin 目录的动态库。
在QT工程中,导入lib:

导入头文件:

我将库放到了工程目录中,所以这里使用相对路径,方便移植。
此时因该能正常执行app了。
三、遇到过的问题
1、调用库时,使用的lib下的.a后缀的库,不报错,但是app无法链接,无法执行:

换为bin下的动态库就能正常执行了。
2、最开始使用的OpenCV为上文链接中4.5.5版本,但是我本地的环境无法执行,报错无法定位程序输入点:

百度有博主提到将 libstdc++-6 放到 C:\Windows\System32 目录下,但是针对这一版本的OpenCV没什么用。
我换为4.5.2后就能正常执行了,读者可以自行测试。我主要是电脑太慢了,自己编译很费时间。
四、总结
在Windows平台使用MSVC编译器确实能减少很多麻烦,不过我几乎都是在Linux进行开发,实在是不想安装MSVC占用太多空间,这次是需要Windows来执行app,多捣鼓吧。
本编文章主要是针对库的调用,记录我遇到的问题并解决。实际使用OpenCV库还有很多细节,可以查看其他博主的分享。