刚换mac 好多东西不会 配置环境 每次都要折腾一大壶
这次折腾下opencv 废话不多切入正题
1.准备工作:
在Terminal中输入:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" //这里网上有的教程是用github的,github老是被墙反正我有时候翻不过去
下载Homebrew(通过终端方便的使用它安装管理苹果没有自带的UNIX相关工具软件)附一个学习链接(http://www.zhouming.me/2011/07/mac-os-x-homebrew-install/)
2.安装cmake:(用到1中装的工具)
在Terminal中输入:
brew install cmake
3.安装opencv:
方法一:(这样安装安装的是opencv 2.4.9)
brew install opencv
如果出现
Error: No available formula for opencv (我出现了2333)
在输入brew install opencv前 先输入
brew tap homebrew/science (会卡一下 直接输入brew install opencv好了)
方法二:(可以安装opencv3.0)
先下载opencv的包,然后在终端中进入存放解压后的opencv文件夹,新建一个空的文件夹release,进入该文件夹,编译安装opencv,使用命令如下:
mkdir release
cd release
cmake -G "Unix Makefiles" .. (会卡一下 直接输入make好了)
make
sudo make install
安装好的lib文件存放在“/usr/local/lib”文件夹,h文件存放在“/usr/local/include”。(自动完成的不是要手动的)
至此,opencv for Mac 安装完毕,参考的网址如下:
http://tilomitra.com/opencv-on-mac-osx/
4.在xcode和eclipse中使用opencv:
xcode:
1.新建一个command line project(这里估计和最开始下的command line tools有关吧不是很理解最开始那一步是做什么的)
2.随便新建一个cpp,粘贴一个opencv的程序用来测试
//
// main.cpp
// Opencv_test
//
// Created by 李泽 on 14/11/5.
// Copyright (c) 2014年 ___VISSAC___. 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/lize/aaa.png", 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 (注意这一步,如果用的是macports,路径是不一样的),全选该文件夹下所有后缀是dylib的文件,添加至工程
4.添加lib文件查找支持:点击文件名文件夹,在主界面“Building Settings"选项卡中,双击”Library Search Paths",添加路径"/usr/local/lib"
5.添加头文件:点击工程名文件,还是在“Building Settings"选项卡中,找到"Header Search Paths",添加"/usr/local/include"和"/usr/local/include/opencv"
6.编译链接运行一下,不行再Google 吧我是成功了反正2333
eclipse:
1.右键工程名,选择properties,然后点c/c++ build左边的下拉箭头,选择settings,选择右边选项卡中的tool settings
2.在gcc c++ compiler选项列表中选择includes,然后在paths中添加/usr/local/include/
3.在macos x c++ linker选项列表中选择libraries,在library search path中添加/usr/local/lib/ ,在libraries添加需要使用的lib文件:(不清楚要用到啥就全部添加了好了,再有问题问Google)
opencv_core
opencv_imgproc
opencv_highgui
opencv_ml
opencv_video
opencv_features2d
opencv_calib3d
opencv_objdetect
opencv_contrib
opencv_legacy
opencv_flann
参考:http://blog.sciencenet.cn/home.php?COLLCC=3456986939&COLLCC=3456885714&mod=space&uid=702148&do=blog&quickforward=1&id=657754%20%E5%9C%A8Mac%E4%B8%8B%E4%BD%BF%E7%94%A8OpenCV%EF%BC%8C%20%E5%9C%A8Xcode%E4%B8%8B%E4%BD%BF%E7%94%A8OpenCV