MacOS X 安装OpenCV3.2

windows平台和linux平台安装参见 官方文档:http://docs.opencv.org/3.2.0/da/df6/tutorial_py_table_of_contents_setup.html

mac下安装在官方平台没找到。参考:

https://www.learnopencv.com/install-opencv-3-on-yosemite-osx-10-10-x/
 
核心指令就两句,超简单。
brew tap homebrew/science
brew install opencv3

但是也遇到了一堆问题。记录过程如下:

1. 
brew install opencv3

报错:

Error: You must `brew link openexr` before homebrew/science/opencv3 can be installed

2. 以为没有装openexr, 查了一下http://www.openexr.com/ 觉得不装也可以,刚好有 --without-openexr这个选项,因此:

brew install opencv3 --without-openexr

报错:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/aclocal/cmake.m4
/usr/local/share/aclocal is not writable.

You can try again using:
  brew link cmake

………………

3. 那就按照提示吧:

brew link pkg-config

报错:

Error: Could not symlink share/aclocal/pkg.m4
/usr/local/share/aclocal is not writable.

4. 哦,没权限。那么:

sudo brew link pkg-config

报错:

Error: Running Homebrew as root is extremely dangerous and no longer supported.

5. 原来不允许,那么只好改文件夹权限了

whoami
# 下面两个命令中的‘whoami’用刚才命令的输出代替
sudo chown -R 'whoami':admin /usr/local/share         
sudo chown -R 'whoami':admin /usr/local/local/bin
brew link pkg-config
brew link cmake
brew install opencv3 --without-openexr

成功,估计一开始的第一步报的错误,也是没有没有权限建立软件接的问题。

6. 链接到python环境,我这是链接到anaconda建的tensorflow1.0环境下

cd /Users/yuetiezhu/anaconda2/envs/tensorflow1.0/lib/python2.7/site-packages
ln -s /usr/local/Cellar/opencv3/3.2.0/lib/python2.7/site-packages/cv2.so cv2.so

/usr/local/Cellar/opencv3/3.2.0/lib/python2.7/site-packages 没有cv.py 只有cv2.so,但是可以用啦

7. 测试一下

source activate tensorflow1.0
python
import cv2

OK了。

posted on 2017-03-15 15:24  梦·想  阅读(876)  评论(0编辑  收藏  举报