Mac OS X安装opencv并配置到Xcode和eclipse上

1.安装OpenCV for MAC:

1).首先下载opencv for mac安装源文件,http://opencv.org/downloads.html,解压缩

2).安装brew:终端输入:

           ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

     更新Homebrew,Terminal中输入:brew selfupdate

3).安装cmake:brew install cmake

4). 进入存放解压后的opencv文件夹,新建一个空的文件夹release,进入该文件夹,编译安装opencv,使用命令如下:

       tar zxvf OpenCV-2.4.3.tar.bz2

       cd OpenCV-2.4.3

       mkdir release

       cd release

       cmake -G "Unix Makefiles" ..

       make

       sudo make install

      安装好的lib文件存放在“/usr/local/lib”文件夹,h文件存放在“/usr/local/include”

2.Xcode中使用OpenCV:

1).添加lib文件:右键点击工程名,选择“Add files to..”,在文件选择对话框弹出来时输入“/”,在弹出的路径框中输入:/usr/local/lib,全选该文件夹下的全部dylib文件(添加opencv_core,opencv_highgui, opencv_imgproc, opencv_ml四个就足够了),添加至工程。

2). 添加lib文件查找支持: 点击工程名文件,进入“Build Settings”选项卡,在“Library Search Paths”栏中输入“/usr/local/lib”

3).添加头文件:点击工程名文件,进入“Build Settings”选项卡,在“Header Search Paths”栏中输入:“/usr/local/include   /usr/local/include/opencv”

4).对于C++版的OpenCV,会出现下面的错误:

     Undefined symbols for architecture x86_64

    “cv::imshow(std::__1::basic_string, std::__1::allocator > const&, cv::_InputArray const&)”, referenced from:
_main in main1.o
     ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决方法为:

      Open Build Settings by double-clicking on the project name with the Xcode icon.

       In this window, under “Architectures” section, set “Base SDK” to “Current OX S”.

       Now scroll down to “Apple LLVM compiler 4.1 – Language” section.

       In “C++ Language Dialect”, change it to “Compiler Default”. In “C++ Standard Library”, change it from “libc++ (LLVM …)” to “libstdc++ (GNU C++ …)”

3.Eclipse配置OpenCV:

1).安装带有CDT的Eclipse,使用eclipse建立一个Mac C++工程,包含一个cpp文件

2).右击工程名, 选择“Properties”,在属性配置页中选择,点击C/C++ Build, 在下拉选项中选择 Settings. 在右边的选项卡中选择 Tool Settings

3).GCC C++ Compiler选项列表中选择Includes,在Include paths(-l)中添加安装好的opencv的头文件存放目录:/usr/local/include/(注意最后面的/不能少)

4.在MacOS X C++Linker选项列表中选择Library,在Library search path (-L)中添加安装好的opencv Lib文件存放目录:/usr/local/lib/

5.MacOS X C++Linker选项列表中选择Library, 在Libraries(-l) 中依次点击“+”号,添加需要使用的Lib文件(通常情况下,使用前三个):

opencv_core opencv_imgproc opencv_highgui opencv_ml

你可能感兴趣的:(Mac,OS,X/Linux)