Mac下Opencv(2.4.9)配置Xcode(4.6.1)

1:安装homebrew和cmake
brew install cmake
2:安装opencv
brew tap homebrew/science
brew install 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 libc++(Xcode默认的就是这个
) or not,if not, change it to this!
ps:部分xcode和opencv的版本需要用libstdc++,请自行测试哪个适合自己。
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 shift + command +G, which
will allow you to manually go to a folder. Go to -> /usr/local/lib
6.Select both of these files, libopencv_core.dyliblibopencv_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/hujiawei/Pictures/others/other_naicha/naicha.jpg", 1);
     namedWindow("Display Image", WINDOW_AUTOSIZE);
     imshow("Display Image", image);
     waitKey(0);
return 0;
}








郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。