1.在mac终端内,使用brew安装opencv3,这时我的opencv被安装到/usr/local/Cellar/opencv3/3.2.0内。
2.新建xcode 项目,选择command line tool,在项目目录内新建一个group,把/usr/local/Cellar/opencv3/3.2.0/lib内的含有libopencv的dylib都添加进去。
3.在build settings 内更改Header Search Paths为/usr/local/Cellar/opencv3/3.2.0/include, Library Search Paths 更为/usr/local/Cellar/opencv3/3.2.0/lib。注意此处不能copy网上仅仅是/usr/local/include 或者/usr/local/lib,要根据你opencv安装地址而定
4.在main函数中输入,即可显示出图片,注意图片的路径要正确,自己定。
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
String imageName("/Users/mac-jcc/Desktop/opencv-00/jcc.png");
Mat image;
image = imread(imageName, IMREAD_COLOR);
if(image.empty())
{
cout<<"could not open or find the image"<<std::endl;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window",image );
waitKey(0);
return 0;
}