1.安装homebrew
网上方法很多,自行搜索
2.安装cmake
sudo brew install cmake
3.下载opencv源代码
wget https://github.com/Itseez/opencv/archive/2.4.13.zip
4.解压安装
unzip 2.4.13.zip cd opencv-2.4.13/ mkdir build cd build/ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON .. make sudo make install
5.将cv2.so文件链接到python的site-packages目录
sudo ln -s /usr/local/lib/python2.7/site-packages/cv2.so /Library/Python/2.7/site-packages/
6.python里测试
>>> import cv2 >>> print cv2.__version__ 2.4.13
另:homebrew 可以直接安装opencv,没有测试,这里仅供参考:
brew update brew tap homebrew/homebrew-science brew install opencv
时间: 2024-10-07 05:27:44