一、安装OpenCV for MAC
mkdir release
cd release
cmake -G "Unix Makefiles" .. (注意后面的..其实就是上以级目录,那是 openCV source folder)
--------------------
(this is copy from http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation but had old, we
can use -G "Unix Makefiles")
-------------------------- pls continue below 2 command,then the build process will be finished
--------------------
(this is copy from http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation but had old, we
can use -G "Unix Makefiles")
cmake [<some optional parameters>] <path to the OpenCV source directory>
For example
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
4. 安装好的lib文件存放在“/usr/local/lib”文件夹,h文件存放在“/usr/local/include”。
至此,opencv for Mac 安装完毕,参考的网址如下:
http://tilomitra.com/opencv-on-mac-osx/
install homebrew frist
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
三、在XCode中使用OpenCV
1. 创建一个空的command line工程。
2. 在main.cpp中粘贴以下代码:
//
// main.cpp
// FbyCharacterNormalization
//
// Created by Boyuan Feng on 13-1-24.
// Copyright (c) 2013年 Boyuan Feng. All rights reserved.
//
#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/boyuanfeng/aaa.bmp", 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;
}
3. 添加lib文件:右键点击工程名,选择“Add files to..”,在文件选择对话框弹出来时输入“/”,在弹出的路径框中输入:/usr/local/lib,全选该文件夹下的全部dylib文件,添加至工程。
5. 添加lib文件查找支持: 点击工程名文件,进入“Build Settings”选项卡,在“Library Search Paths”栏中输入“/usr/local/lib”
6. 添加头文件:点击工程名文件,进入“Build Settings”选项卡,在“Header Search Paths”栏中输入:“/usr/local/include /usr/local/include/opencv”
7. 编译运行整个工程,运行成功~~