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-configbrew link cmake brew install opencv3 --without-openexr
成功,估計一開始的第一步報的錯誤,也是沒有沒有權限建立軟體接的問題。
6. 連結到python環境,我這是連結到anaconda建置的tensorflow1.0環境下
cd /Users/yuetiezhu/anaconda2/envs/tensorflow1.0/lib/python2.7/site-packagesln -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,但是可以用啦
source activate tensorflow1.0python import cv2
以上是MacOS X安裝OpenCV3.2說明介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!