OpenCV安装

Mac下安装OpenCV(配置Xcode)

在Mac上安装OPenCV,使用的开发工具是Xcode7.3,安装的版本是2.4.12。(这是我第一次使用Markdown编写文档,感觉还不错。2016.03.31)

1.安装Cmake

使用安装工具是Homebrew,但是有个错误,使用命令brew install cmake安装cmake在使用的时候会提示找不到cmake命令。所以使用brew cask install cmake来安装Cmake。猜测是因为brew cask能自动链接到程序,而brew只是安装,不负责环境变量的设置。

2.下载和编译OPenCV

2.1 下载OpenCV

下载地址
1>官网网站:http://opencv.org

2>sourceforge:http://sourceforge.net/projects/opencvlibrary/

下载完成之后把源代码拷贝到让自己高兴的任何地方。

2.2 编译OPenCV

起初使用的安装方法也是brew install openCV安装,但是在运行测试代码的时候报错,libpng相关的错误,未找到解决方法,最终使用以下方法编译:

cd <the path of opencv source>
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. 
make
sudo make install

到此OpenCV的安装已经完成,安装路径为/usr/local,该路径可以修改为让你高兴的路径。它安装的文件分布为:

1>头文件:/usr/local/include目录包含两个文件夹:opencvopencv2

2>lib文件:/usr/local/lib目录下包含了opencv相关的动态库。

如果想卸载OpenCV,则可以回到build目录下,执行sudo make uninstall,然后删除上面提到的文件即可。

参考内容:

Building OpenCV from Source Using CMake, Using the Command Line

Installing OpenCV

3.使用Xcode进行OpenCV开发

1.Open Xcode, choose New->New Project->Command Line Tool

2.Name it and select C++ for type

3.Click on your project from the left menu. Click the build settings tab from the top. Filter all. Scroll to Search Paths. Under header search paths, for debug and release, set the path to /usr/local/include.Under library search paths, set the path to $(PROJECT_DIR). Finally, check if C++ standard library is libstdc++ or not, if not, change it to this!

4.Click on your project from the left menu. File->New->New Group, Name the group OpenCV Frameworks.

5.Select the folder (group) you just labeled, OpenCV Frameworks in the left menu. Go to File->add Files, Type 'command+shift+G', which will allow you to manually go to a folder. Go to -> /usr/local/lib

6.Select both of these files, libopencv_core.dylib, libopencv_highgui.dylib, and click Add. (you may need to add other library files from this folder to run other code.)

7.You must include this line of code in the beginning of your main.cpp file:
#include <opencv2/opencv.hpp>

修改main.cpp代码进行测试,如下:

#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv) {
    Mat image;
    image = imread("/Users/hd/Pictures/hd.jpg", 1);
    namedWindow("xx ", WINDOW_AUTOSIZE);
    imshow("xx ", image);
    waitKey(0);
    return 0;
}

参考资料:https://segmentfault.com/a/1190000000711132

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值