基于Mac的OpenCV环境
建议使用Brew 安装,如果没有安装brew,先执行下面命令:
$/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
然后,指定目标仓库 $brew tap homebrew/science
安装OpenCV3 $brew install opencv3
安装速度取决于网络,安装完毕需要绑定Python开发环境,有多种土方法:
1)增加环境变量,将opencv 的site-packages 添加到PYTHONPATH中
2)使用ln 软连接,将cv2.so 链接到python 环境的 site-packages中
3)直接cp cv2.so 到 python 环境的 site-packages 目录下
更简单地是执行如下命令:
echo /usr/local/opt/opencv3/lib/python2.7/site-packages >> /usr/local/lib/python2.7/site-packages/opencv3.pth mkdir -p /Users/hecom/.local/lib/python2.7/site-packages echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/hecom/.local/lib/python2.7/site-packages/homebrew.pth
对于强迫症患者
可以全面安装opencv的各种插件,如3方插件,视频插件等:
$brew install opencv3 --with-contrib --with-cuda --with-ffmpeg --with-tbb --with-qt5
可能会遇到很多坑,如
Error: You must ‘brew link texi2html’ before homebrew/science/opencv3 can be installed
当你执行 $brew link texi2html
时又会遇错:
Error: Cowardly refusing to 'sudo brew link' You can use brew with sudo, but only if the brew executable is owned by root. However, this is both not recommended and completely unsupported so do so atyour own risk
说明brew 的权限有问题, 需要解决:
$sudo chown root:wheel ‘which brew’
在Ubuntu上OpenCV3的源码安装
在Ubantu上安装先要做一下准备活动
$ aptitude -f install$ sudo apt-get update
然后安装编译环境:
$sudo apt-get install build-essential安装依赖库
$sudo apt-get install cmake libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
还要安装python 依赖及其它依赖库 $sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
获得opencv源代码
git clone https://github.com/Itseez/opencv.git
终于可以编译安装了:
$cd opencv$cmake -D CMAKE_INSTALL_PREFIX=/home/opencv/build -D CMAKE_BUILD_TYPE=RELEASE ..
最后,安装python-opencv:
$sudo apt-get install python-opencv
OpenCV的Python环境简单验证
一行代码验证OpenCV的Python环境是否成功:
$python -c “import cv2; print dir(cv2)”
如果输出了很多cv2 的属性和函数名的字典,就表示成功;否则的话,还需要继续填坑