Mac OS · 2015-02-13

mac上opencv安装步骤

1. 去 http://opencv.org 下载最新版OpenCV for Linux/Mac源文件,目前版本是2.4.3。下载后解压。

2. 去 http://www.cmake.org 下载最新版cmake,.dmg文件,建议使用2.8.12.2版本。下载后安装。
3. 接下来开始安装opencv(注: 如果需要启用多核支持, 可以先按第6点进行修改后再编译,未经测试)

开一个终端,进入opencv解压缩的目录,如cd 然后把文件夹拽进去。
mkdir release
cd ./release
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
4. 至此opencv应该已经装上了。
 注:如果cmake出现错误,请到苹果开发者网站那里下载Command Line Tools安装。(关键)

由于本人是要写python,所以还要进行下一步配置。本人mac是rmbp15,自带的python版本是2.7,终端下输入python后输入import cv,如果提示没有找到cv,请按如下步骤操作。
1. 打开一个终端,cd ~
2. vim .profile
3. 添加export PYTHONPATH=/usr/local/lib/python2.7/site-packages/,其中python2.7根据个人python版本而定。
4. source .profile
5. 至此应该全部完成了。

6.补充:

I got this working with OpenCV 2.4.10 and GCC 4.9.2. I also had to make the following additional changes to the CMakeLists.txt in the root OpenCV directory:

OCV_OPTION(WITH_OPENEXR “Include ILM support via OpenEXR” OFF)
OCV_OPTION(WITH_OPENMP “Include OpenMP support” ON)
OCV_OPTION(BUILD_OPENEXR “Build openexr from source” OFF )

I originally was running into errors with “Undefined symbols for architecture x86_64 cv::imshow, cv::imread, cv::imwrite, etc,” because Homebrew installed a clang OpenCV whereas my project was using GCC. One solution would be to rebuild everything with clang but that was not appealing in my case because I wanted OpenMP support. So I instead used your solution to build a GCC version of OpenCV.