OpenCV安装
2016-03-31 19:02
337 查看
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目录包含两个文件夹:
opencv和
opencv2。
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, chooseNew->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 settingstab 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 libraryis
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 Frameworksin 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
相关文章推荐
- mac下使用brew配置环境的步骤分享
- python中使用OpenCV进行人脸检测的例子
- opencv 做人脸识别 opencv 人脸匹配分析
- 使用opencv拉伸图像扩大分辨率示例
- Mac系统下使用brew搭建PHP(LNMP/LAMP)开发环境
- mac环境中使用brew安装php5.5.15
- 基于C++实现kinect+opencv 获取深度及彩色数据
- OpenCV 2.4.3 C++ 平滑处理分析
- 教你如何解决XCODE升级后插件不能用问题
- 浅谈Xcode 开发工具 XCActionBar
- xcode 4 制作静态库图文详解
- 使用Xcode为iOS应用项目创建PCH文件的方法及应用示例
- Python中使用OpenCV库来进行简单的气象学遥感影像计算
- 利用Python和OpenCV库将URL转换为OpenCV格式的方法
- python结合opencv实现人脸检测与跟踪
- Python环境搭建之OpenCV的步骤方法
- 解决 Xcode 6-Beta2 智能提示bug
- 针对iOS开发的一些Xcode使用技巧小结
- Xcode中iOS应用开发的一般项目目录结构和流程简介
- XCode编译速度慢的处理方法