Installing OpenCV on Mac OS X Snow Leopard

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. Version 2 ships with Python bindings and simply you can “import cv” module in Python after you’ve installed it.

The easiest way to install OpenCV on Mac is to use package management systems like port, fink or homebrew. They will automatically download, compile and install needed packages for you.

In this tutorial I’ll use brew, how ever you can use your preferred package manager.

Here is the short explanation of the installation process (every thing will be done on Terminal.app)

1. Install brew package manager. (instructions here)
2. Update brew formulas:

brew install git
brew update

3. Install opencv:

brew install opencv

and brew will automatically installs CMake and checks out opencv repository, Builds and installs it.

Note that you should edit your PYTHONPATH to make opencv working with Python. I wrote a simple script to do this automatically for Python 2.6 (Also brew should be installed on it’s default location).

RND=/tmp/$RANDOM
PYTHONPATH=`echo $PYTHONPATH | sed -e 's/\/usr\/local\/lib\/python2.6\/site-packages\/://g'`
cat ~/.bash_profile | grep -Ev "PYTHONPATH" > $RND
echo export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:"'$PYTHONPATH' >> $RND
mv $RND ~/.bash_profile

Just copy the script above and type:

pbpaste | sh

Close the Terminal and reopen it.

Now you can simply open your Python interpreter and type “import cv”.

Done. :)

Advertisement

4 Responses to Installing OpenCV on Mac OS X Snow Leopard

  1. bet365 says:

    how are you I was luck to approach your topic in google
    your topic is impressive
    I obtain a lot in your Topics really thank your very much
    btw the theme of you blog is really fabulous
    where can find it

  2. Ben says:

    Hi!

    This post is fantastic. Just one question, I get this error when I run the 2nd command – do you know what I should do?

    cat ~/.bash_profile | grep -Ev “PYTHONPATH” > $RND
    cat: /Users/benrichardson/.bash_profile: No such file or directory

    Ben :)

    • Anonymous says:

      create .bash_profile in your home directory with something like this:
      touch ~/.bash_profile
      and try the script again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.