mac python安装opencv_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:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装opencv_contrib库,可以使用以下命令: pip install opencv-contrib-python 这个命令会自动从PYPI(Python Package Index)上下载并安装opencv_contrib库。 另外,你还可以参考一篇关于Python 3.x安装opencv opencv_contrib的操作方法的文章,里面有详细的步骤和说明,对你有所帮助。 如果你在使用Anaconda环境下,并且已经安装Python 3.5,但是官网提供的opencv包只支持2.7版本,你可以查找一些资料来解决这个问题,以便让opencv能够在3.5版本上运行。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [opencv-contrib-python安装](https://blog.csdn.net/a19990412/article/details/80933680)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Python 3.x 安装opencv+opencv_contrib的操作方法](https://download.csdn.net/download/weixin_38656676/12869791)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Python 3.x 安装opencv+opencv_contrib](https://blog.csdn.net/u010445006/article/details/53782544)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值