opencv for Python在mac os上的安裝

Install OpenCV for Python on Mac OS X
In our previous post we described how to develop driver assistance systems on Android devices. We are using OpenCV SDK for Android, but during the app development we had to test & calibrate the cameras using a computer. Out platform for now is Mac OS X (Yosemite). Therefore, we needed to install & configure OpenCV for Python on Mac.

Install OpenCV
The “traditional” way didn’t work out: downloading OpenCV zip from their website and then compile it & link it with Python. There is a simpler way to do it using Homebrew.

Homerew is a package manager for Mac OS X, more info can be found on their website.

Installing brew is simpler than you think, just run this in terminal:

1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
You might need to install Python first:

1
brew install python
Add OpenCV using the following commands:

1
brew tap homebrew/science
Install OpenCV:

1
brew install opencv
Your OpenCV installation will be located at:

1
/usr/local/Cellar/opencv/2.4.10/
Python setup
The final part is to setup Python, use the following:

1
2
3
cat ~/.bash_profile | grep PYTHONPATH
ln -s /usr/local/Cellar/opencv/2.4.10/lib/python2.7/site-packages/cv.py cv.py
ln -s /usr/local/Cellar/opencv/2.4.10/lib/python2.7/site-packages/cv2.so cv2.so
That’s it! If you have issue with Python when running some OpenCV samples, you need to make sure that you have numpy & matplotlib installed. You can do this using brew, in terminal enter:

1
2
pip install numpy
pip install matplotlib
Demo
Here is a simple Python sample to test out that everything works fine:

1
2
3
4
5
6
7
8
import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('road.png', 0)
plt.imshow(img, cmap='gray', interpolation='bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
More information & sources:

OpenCV: http://www.opencv.org/
Homebrew package manager: http://brew.sh/
Install OpenCV for Python on Mac: https://jjyap.wordpress.com/2014/05/24/installing-opencv-2-4-9-on-mac-osx-with-python-support/
Calibrate camera with OpenCV & Python: http://www.janeriksolem.net/2014/05/how-to-calibrate-camera-with-opencv-and.html
OpenCV Python samples: https://github.com/Itseez/opencv/tree/master/samples/python2

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末富俄,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子桃焕,更是在濱河造成了極大的恐慌契沫,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件吼畏,死亡現(xiàn)場離奇詭異督赤,居然都是意外死亡,警方通過查閱死者的電腦和手機泻蚊,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進店門躲舌,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人性雄,你說我怎么就攤上這事没卸「睿” “怎么了?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵约计,是天一觀的道長诀拭。 經(jīng)常有香客問我,道長煤蚌,這世上最難降的妖魔是什么耕挨? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮尉桩,結果婚禮上俗孝,老公的妹妹穿的比我還像新娘。我一直安慰自己魄健,他們只是感情好赋铝,可當我...
    茶點故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著沽瘦,像睡著了一般革骨。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上析恋,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天良哲,我揣著相機與錄音,去河邊找鬼助隧。 笑死筑凫,一個胖子當著我的面吹牛,可吹牛的內容都是我干的并村。 我是一名探鬼主播巍实,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼哩牍!你這毒婦竟也來了棚潦?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤膝昆,失蹤者是張志新(化名)和其女友劉穎丸边,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體荚孵,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡妹窖,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了收叶。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片骄呼。...
    茶點故事閱讀 39,795評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出谒麦,到底是詐尸還是另有隱情俄讹,我是刑警寧澤哆致,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布绕德,位于F島的核電站,受9級特大地震影響摊阀,放射性物質發(fā)生泄漏耻蛇。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一胞此、第九天 我趴在偏房一處隱蔽的房頂上張望臣咖。 院中可真熱鬧,春花似錦漱牵、人聲如沸夺蛇。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽刁赦。三九已至,卻和暖如春闻镶,著一層夾襖步出監(jiān)牢的瞬間甚脉,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工铆农, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留牺氨,地道東北人。 一個月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓墩剖,卻偏偏與公主長得像猴凹,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子岭皂,可洞房花燭夜當晚...
    茶點故事閱讀 44,724評論 2 354

推薦閱讀更多精彩內容