关于最近利用Cmake编译OpenCV的一些心得体会

因为各种需求,各种原因,很多人都尝试自己去Cmake-OpenCV,但是中途遇到的问题真是层次不穷,千奇百怪,就像是唐僧师徒西天取经一样,不经历九九八十一难,得不到真经。

之所以问题层次不穷,千奇百怪,主要还是因为OpenCV是一个庞大的开源软件,并且在不断更新。

首先大家几乎都要遇到的问题便是Cmake的Configure过程中下载必要文件失败的问题,这一般是因为时间久了,写在文件中的源地址失效了…然后我们要么去找到正确的源地址,要么手动去找到这些文件…这个过程其实挺磨人,挺麻烦的。
博主的几篇相关博文中都遇到了这些问题,相关博文链接:
https://blog.csdn.net/wenhao_ir/article/details/124641125
https://blog.csdn.net/wenhao_ir/article/details/125098843
https://blog.csdn.net/wenhao_ir/article/details/125103083

其次还有因版本细微差别导致的各种报错,比如博主在https://blog.csdn.net/wenhao_ir/article/details/125098843中遇到的主要问题。

还有因为OpenCV本身的Cmake文件语法问题导致的错误,比如某博主在博文https://blog.csdn.net/wenhao_ir/article/details/125103083中遇到的第一个问题,if…else…的语法错了。

还有因为缺少第三方库导致的问题…比如博主在博文https://blog.csdn.net/wenhao_ir/article/details/124641125中遇到的缺少OpenBLAS问题…

不仅是博主,别的同学在利用Cmake编译OpenCV的过程中,也不是一帆风顺的,比如博文https://blog.csdn.net/qq_40791099/article/details/88667094就表示整个过程很曲折,他弄了几天才弄好。

说完了问题,接下来是一些经验总结:
1 能用现成的就用现成的,可以直接用官方发布的,也可以用别人编译好的共享出来的,比如博文https://blog.csdn.net/REAL_liudebai/article/details/119356958就是用的别人的。这篇博文用的是英国工程师/博士James Bowley编好的库,他的个人网站网址为 https://jamesbowley.co.uk/,他的自我介绍如下:

I’m a software developer currently working for Ethersec Industries Ltd., where we work on advanced video analytics for security and safety systems. I have a PhD in Mathematics and Computer Science and now spend most of my days writing software in C++, now my go to general purpose programming language of choice. That said for R&D I much prefer working with Python and/or MATLAB if available, or maybe something in between (MEX wrapped C++ code). For more computationally demanding tasks, I use CUDA to adapt suitable algorithms for execution on the GPU.
I am interested in the application of Deep Learning and GPU computing to video analytics and as such I am currently enjoying the latest (2022) iteration of the fastai MOOC. If your interested in accelerating your python image processing pipeline with OpenCV then you may enjoy reading Accelerating OpenCV with CUDA streams in Python where I took a detore from C++ to investigate the performance of the OpenCV python CUDA bindings.

翻译如下:
我是一名软件开发人员,目前在Ethersec Industries Ltd.工作,我们致力于安全和安保系统的高级视频分析。我拥有数学和计算机科学博士学位,现在大部分时间都在用C++编写软件,现在我选择了通用编程语言。也就是说,对于研发,我更喜欢使用Python和/或MATLAB(如果可用),或者介于两者之间的东西(MEX包装的C++代码)。对于计算要求更高的任务,我使用CUDA调整合适的算法以在GPU上执行。
我对深度学习和GPU计算在视频分析中的应用很感兴趣,因此我目前正在享受fastai MOOC的最新(2022年)迭代。如果您对使用OpenCV加速python图像处理管道感兴趣,那么您可能会喜欢阅读python中使用CUDA流加速OpenCV的文章,在这里,我绕道了C++来研究OpenCV python CUDA绑定的性能。

大概意思是:这哥儿们喜欢用Python来研究问题,特别是GPU并行计算,但是他不喜欢用C++,所以它就想办法让OpenCV-python 支持CUDA,于是自己就编译并向大家提供了OpenCV-Python支持CUDA的版本。

扫描二维码关注公众号,回复: 14226178 查看本文章

这哥儿们在页面https://jamesbowley.co.uk/downloads/#OpenCV4.5.0中向大家提供了以下编译好的版本:

  • 01—OpenCV 4.5.0 x64, VS2019 with CUDA all modules + python 3.8
    bindings (Release, Debug )
  • 02—OpenCV 4.5.0 x64, VS2019 with CUDA DNN backend only + python 3.8 bindings (Release, Debug )
  • 03—OpenCV 4.4.0 x64, VS2019 with CUDA all modules + python 3.7 bindings (Release, Debug )
  • 04—OpenCV 4.4.0 x64, VS2019 with CUDA DNN backend only + python 3.7 bindings (Release, Debug )
  • 05—OpenCV 4.3.0 x64, VS2019 with CUDA all modules + python 3.7 bindings (Release, Debug )
  • 06—OpenCV 4.3.0 x64, VS2019 with CUDA DNN backend only + python 3.7 bindings (Release, Debug)
  • 07—OpenCV 4.2.0 x64, VS2019 with CUDA all modules + Anaconda python 3.7 bindings
  • 08—OpenCV 4.2.0 x64, VS2019 with CUDA DNN backend only + Anaconda python 3.7 bindings
  • 09—OpenCV 4.1.0 x64, VS2017 with CUDA 10.1 + python bindings for CUDA
  • 10—OpenCV 4.0 x64, VS2017 with CUDA 10.0, MKL(TBB) and TBB
  • 11—OpenCV 4.0 x64, VS2017 with CUDA 10.0 and MKL(TBB)
  • 12—OpenCV 4.0 x64, VS2017 with CUDA 10.0 and python bindings
  • 13—OpenCV 3.4 x64, VS2017 with CUDA 9.1, MKL(TBB) and TBB
  • 14—OpenCV 3.4 x64, VS2017 with CUDA 9.1 and MKL(TBB)
  • 15—OpenCV 3.4 x64, VS2017 with CUDA 9.1
  • 16—OpenCV v3.3 x64, VS2015 with CUDA
  • 17—OpenCV 3.3 x64, VS2013 with CUDA, MKL(TBB), TBB and python binding
  • 18—OpenCV v3.2 x64, VS2015 with CUDA
  • 19—OpenCV v3.2 x86, VS2015 without CUDA
  • 20—OpenCV v3.2 x64, VS2013 with CUDA
  • 21—OpenCV v3.2 x86, VS2013 without CUDA

如果您要作OpenCV的CUDA方面的开发工作,这些还不够用么??

当然,这只是一个例子,github和CSDN上也有许多别人共享出来自己编译好的OpenCV,大家可直接拿来用。当然,通常来说CSDN上的要么需要C币,要么需要人民币,所以建议大家首选上Github上寻找。

2 如果实在要自己编译,可以的话尽量用新一点的版本,这样在下载必要文件时会比较稳定。

3 一个版本不行,可以换一个版本,因为每个版本的源码和Cmake文件都是有所不同的。

大致就这些,以后想到再补充吧。

如果您有编译OpenCV的需求,可以联系博主,博主别的博文中的源代码里有博主的联系方式,也可CSDN上私信博主。

猜你喜欢

转载自blog.csdn.net/wenhao_ir/article/details/125102981