剛換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;
}