在Mac OSX 10.10 上安装opencv

时间:2023-02-07 02:38:41

http://blog.csdn.net/wdkirchhoff/article/details/41910553

 

在Mac OSX上如果想使用OpenCV,可以通过自己手动编译源码的方式,但比较繁琐。
推荐使用Homebrew来进行安装,步骤很简单,如下:


1、brew tap homebrew/science


2、brew install opencv


等待几分钟,即可安装成功。

下面是配置eclipse:

 

 

1. 按照正常的步骤,使用eclipse建立一个Mac C++工程,包含一个cpp文件。
#include <iostream>
#include
<opencv2/opencv.hpp>
#include
<opencv2/highgui/highgui.hpp>
#include
<opencv/cvaux.hpp>
#include
<fstream>
using namespace std;

#define BYTE unsigned char

int main(int argc, const char * argv[])
{
// insert code here...
#if 1
//get the image from the directed path
IplImage* img = cvLoadImage("/Users/kirchhoff/twd.png", 1);
//NSLog(img);
//create a window to display the image
cvNamedWindow("picture", 1);
//show the image in the window
cvShowImage("picture", img);
//wait for the user to hit a key
cvWaitKey(0);
//delete the image and window
cvReleaseImage(&img);
cvDestroyWindow(
"picture");
#endif
//return
return 0;
}

2. 右击工程名, 选择“Properties”,在属性配置页中选择,点击C/C++ Build, 在下拉选项中选择 Settings. 在右边的选项卡中选择 Tool Settings。
3. 在GCC C++ Compiler选项列表中选择Includes,在Include paths(-l)中添加安装好的opencv的头文件存放目录:/usr/local/Cellar/opencv/2.4.9/include
4. 在MacOS X C++Linker选项列表中选择Library,在Library search path (-L)中添加安装好的opencv Lib文件存放目录:/usr/local/Cellar/opencv/2.4.9/lib
5. 在MacOS X C++Linker选项列表中选择Library, 在Libraries(-l) 中依次点击“+”号,添加需要使用的Lib文件(通常情况下,使用前三个):
opencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_contrib opencv_legacy opencv_flann
6. 重新build all工程,大功告成~~*^_^*