您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:Ubuntu16.04下Python2.7 安装 OpenCV2.4

51自学网 2021-11-09 14:33:36
  python
这篇教程Ubuntu16.04下Python2.7 安装 OpenCV2.4写得很实用,希望能帮到您。

Ubuntu16.04下Python2.7 安装 OpenCV2.4

事先装有 OpenCV 需要重新安装的,先执行卸载步骤,再安装。

卸载步骤

1.找到当初安装 OpenCV 的 release 或 build 目录,执行以下命令

sudo make uninstall
cd ..
sudo rm -r build
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*

2.删除 usr 文件夹中所有 opencv 相关项

cd /usr/
find . -name "*opencv*" | xargs sudo rm -rf

3.移除 Python 相关

apt-get remove opencv-doc opencv-data python-opencv

安装步骤

1.通过命令安装各种软件包

$ sudo apt-get install build-essential
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

2.进到安装路径下拷贝 OpenCV 源码

$ git clone https://github.com/opencv/opencv.git

3.选择安装的 OpenCV 版本号

$ cd opencv
$ git checkout 2.4

4.使用 Cmake 编译 OpenCV 源码

$ mkdir release
$ cd release
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

5.make 安装 OpenCV

$ make -j4
$ sudo make install

安装到此结束。

测试

命令进入 Python 编辑器

>>> import cv2
>>> print(cv2.__version__)

会输出 OpenCV 的版本号。

cuda 9.0 与 opencv 版本匹配问题:

Cmake 过程中会出现以下问题:

错误
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)
原因

在cuda9里面,NVIDIA把
libnppi.so
换成了
libnppc.so libnppial.so libnppicc.so libnppicom.so libnppidei.so libnppif.so libnppig.so libnppim.so libnppist.so libnppisu.so libnppitc.so libnpps.so

解决方案

修改opencv/cmake/FindCUDA.cmake 文件,将其中的

unset(CUDA_nppi_LIBRARY CACHE)

替换为:

unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)

find_cuda_helper_libs(nppi)
set(CUDA_npp_LIBRARY"${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")

替换为

find_cuda_helper_libs(nppial)
find_cuda_helper_libs(nppicc)
find_cuda_helper_libs(nppicom)
find_cuda_helper_libs(nppidei)
find_cuda_helper_libs(nppif)
find_cuda_helper_libs(nppig)
find_cuda_helper_libs(nppim)
find_cuda_helper_libs(nppist)
find_cuda_helper_libs(nppisu)
find_cuda_helper_libs(nppitc)
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
错误
opencv nvcc fatal   : Unsupported gpu architecture 'compute_20'
原因

cuda9不支持‘ compute-20 ’

解决方案:

更改 OpenCVDetectCUDA.cmake 文件,把有关 ‘ compute-20 ’ 的全删掉

if(CUDA_GENERATION STREQUAL "Fermi")
    set(__cuda_arch_bin "2.0 2.1(2.0)")
  elseif(CUDA_GENERATION STREQUAL "Kepler")
    if(${CUDA_VERSION} VERSION_LESS "5.0")
      set(__cuda_arch_bin "3.0")
    else()
      set(__cuda_arch_bin "3.0 3.5")

替换为

if(CUDA_GENERATION STREQUAL "Fermi")
    set(__cuda_arch_bin "3.0 3.5")
  elseif(CUDA_GENERATION STREQUAL "Kepler")
    if(${CUDA_VERSION} VERSION_LESS "5.0")
      set(__cuda_arch_bin "3.0")
    else()
      set(__cuda_arch_bin "3.0 3.5")

将:

if(${CUDA_VERSION} VERSION_LESS "5.0")
     set(__cuda_arch_bin "1.1 1.2 1.3 2.0 2.1(2.0) 3.0")
elseif(${CUDA_VERSION} VERSION_GREATER "6.5")
     set(__cuda_arch_bin "2.0 2.1(2.0) 3.0 3.5")

替换为:

if(${CUDA_VERSION} VERSION_LESS "5.0")
        set(__cuda_arch_bin "1.1 1.2 1.3 2.0 2.1(2.0) 3.0")
elseif(${CUDA_VERSION} VERSION_GREATER "6.5")
        set(__cuda_arch_bin "3.0 3.5")

然后 cmake 成功。

参考

https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html

https://stackoverflow.com/questions/46584000/cmake-error-variables-are-set-to-notfound

个人网站:心安便是归处
GitHub:oh,ss

  • 2
    点赞
  • 2
    评论
  • 3
    收藏
  • 一键三连
    一键三连
  •  
  • 扫一扫,分享海报

     
<script type=text/javascript crossorigin src="https://csdnimg.cn/release/phoenix/production/qrcode-7c90a92189.min.js"></script><script src="//g.csdnimg.cn/??sharewx/1.2.1/sharewx.js" type="text/javascript"></script><script type="text/javascript" crossorigin src="https://g.csdnimg.cn/user-login/3.0.1/user-login.js"></script><script type="text/javascript" crossorigin src="https://g.csdnimg.cn/collection-box/2.0.6/collection-box.js"></script>
表情包
插入表情
 
 
 
©️2021 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页
<script src="https://g.csdnimg.cn/common/csdn-footer/csdn-footer.js" data-isfootertrack="false" type="text/javascript"></script> <script type="text/javascript"> window.csdn.csdnFooter.options = { el: '.blog-footer-bottom', type: 2 } </script> <script> $("a.flexible-btn").click(function(){ $(this).parents('div.aside-box').removeClass('flexible-box'); $(this).parents("p.text-center").remove(); }) </script> <script type="text/javascript" src="https://g.csdnimg.cn/user-tooltip/2.5/user-tooltip.js"></script> <script type="text/javascript" src="https://g.csdnimg.cn/user-medal/1.0.7/user-medal.js"></script>
 
<script type="text/javascript"> var timert = setInterval(function(){ sideToolbar = $(".csdn-side-toolbar"); if (sideToolbar.length > 0) { sideToolbar.css('cssText','bottom:64px !important;') clearInterval(timert); } }, 200); </script> <script> var articleId = 81019536; var commentscount = 2; var curentUrl = "https://blog.csdn.net/wgshun616/article/details/81019536"; var myUrl = "https://my.csdn.net/"; var highlight = ["opencv2.4","ubuntu16.04","opencv2","ubuntu16","python2.7","opencv","ubuntu","python2","ubunt","open","python","ope","pytho","ubun","pen","enc","ub","u16","nc","pyth","op","pe","cv2","on2","nt","py","安装","cv","hon","下","04","4","7"];//高亮数组 var isRecommendModule = true; var isBaiduPre = true; var baiduCount = 2; var share_card_url = "https://app-blog.csdn.net/share?article_id=81019536&username=wgshun616" var articleType = 1; var baiduKey = "Ubuntu16.04下Python2.7 安装 OpenCV2.4"; var userNewReport = false; var needInsertBaidu = true; var recommendRegularDomainArr = ["blog.csdn.net/.+/article/details/","download.csdn.net/download/","edu.csdn.net/course/detail/","ask.csdn.net/questions/","bbs.csdn.net/topics/","www.csdn.net/gather_.+/"] var codeStyle = "atom-one-dark"; var baiduSearchType = "title"; var canRead = true; var blogMoveHomeArticle = false; var showPcWindowAd = false; var showHeadWord = true; var showSearchText = ""; var linkPage = true; var articleSource = 1; var articleReport = '{"pid": "blog", "spm":"1001.2101"}'; var isShowToQuestion = false; var baiduSearchChannel = 'pc_relevant' var baiduSearchIdentification = '.no_search_link' var distRequestId = '1636439255950_09209' var initRewardObject = { giver: currentUserName, anchor: username, articleId: articleId, sign: '' } var isLikeStatus = false; var isUnLikeStatus = false; var studyLearnWord = "赠12个月" </script> <script src="https://csdnimg.cn/public/sandalstrap/1.4/js/sandalstrap.min.js"></script>
 
 
实付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值
<script src="https://csdnimg.cn/release/blogv2/dist/components/js/pc_wap_highlight-a6777dccd0.min.js" type="text/javascript"></script> <script src="https://csdnimg.cn/release/blogv2/dist/components/js/pc_wap_common-48322534fc.min.js" type="text/javascript"></script> <script src="https://csdnimg.cn/release/blogv2/dist/components/js/edit_copy_code-1320dfe85c.min.js" type="text/javascript"></script> <script> // 全局声明 if (window.csdn === undefined) { window.csdn = {}; } window.csdn.sideToolbar = { options: { report:{ isShow: true, }, qr: { isShow: false, }, guide: { isShow: true } } } $(function(){ $(document).on('click',"a.option-box[data-type='report']",function() { window.csdn.userLogin.loadAjax(function(res){ if(userNewReport){ window.csdn.feedback({ "type":'blog', "rtype":'article', "rid":articleId, "reportedName":username, "submitOptions":{ "title":articleTitle, "contentUrl":articleDetailUrl }, "callback":function(){ showToast({ text: "感谢您的举报,我们会尽快审核!", bottom: '10%', //toast距离页面底部的距离 zindex: 9000, //为了防止被其他控件遮盖,z-index默认为2 speed: 500, //toast的显示速度 time: 1500//toast显示多久以后消失 }); } }) }else{ showReport(false,articleTitles); } }) }); }) </script> <script src="https://g.csdnimg.cn/baidu-search/1.0.9/baidu-search.js" type="text/javascript"></script> <script src="https://csdnimg.cn/release/download/old_static/js/qrcode.js"></script> <script src="https://g.csdnimg.cn/lib/qrcode/1.0.0/qrcode.min.js"></script> <script src="https://g.csdnimg.cn/user-ordercart/3.0.0/user-ordercart.js" type="text/javascript"></script> <script src="https://g.csdnimg.cn/user-ordertip/4.1.3/user-ordertip.js" type="text/javascript" ></script> <script src="https://g.csdnimg.cn/order-payment/3.0.2/order-payment.js" type="text/javascript" ></script> <script src="https://csdnimg.cn/release/blogv2/dist/pc/js/common-8738548423.min.js" type="text/javascript"></script> <script src="https://csdnimg.cn/release/blogv2/dist/pc/js/detail-af0503e895.min.js" type="text/javascript"></script> <script src="https://csdnimg.cn/release/blogv2/dist/pc/js/column-c7621afc01.min.js" type="text/javascript"></script> <script src="https://g.csdnimg.cn/side-toolbar/3.0/side-toolbar.js" type="text/javascript"></script> <script src="https://g.csdnimg.cn/copyright/1.0.4/copyright.js" type="text/javascript"></script> <script> $(".MathJax").remove(); if ($('div.markdown_views pre.prettyprint code.hljs').length > 0) { $('div.markdown_views')[0].className = 'markdown_views'; } </script> <script type="text/javascript" src="https://csdnimg.cn/release/blog_mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ "HTML-CSS": { linebreaks: { automatic: true, width: "94%container" }, imageFont: null }, tex2jax: { preview: "none", ignoreClass:"title-article" }, mml2jax: { preview: 'none' } }); </script> <script type="text/javascript" crossorigin src="https://g.csdnimg.cn/common/csdn-login-box/csdn-login-box.js"></script>
Ubuntu16.04下python2.7安装opencv
crnn-mxnet-chinese-text-recognition
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。