刚换mac 好多东西不会 配置环境 每次都要折腾一大壶php
此次折腾下opencv 废话很少切入正题html
1.准备工做:linux
安装Homebrew,在Terminal中输入:ios
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" //这里网上有的教程是用github的,github总是被墙反正我有时候翻不过去
c++
如下载Homebrew(经过终端方便的使用它安装管理苹果没有自带的UNIX相关工具软件)附一个学习连接(http://www.zhouming.me/2011/07/mac-os-x-homebrew-install/)git
2.安装cmake:(用到1中装的工具)github
在Terminal中输入:macos
brew install cmakexcode
3.安装opencv:ruby
<p.s.> 首先确认下gcc的问题,可能要先装下command line tools for xcode,自行百度下载安装吧
方法一:(这样安装安装的是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 -j8
sudo make install
安装好的lib文件存放在“/usr/local/lib”文件夹,h文件存放在“/usr/local/include”。(自动完成的不是要手动的)
//
// 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> //这个代码在xcode下是正确的,在eclipse中,要将这里的cvaux.hpp改为cvaux.h
#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;
}