Installing OpenCV for Python on Mac Lion

Like previous installs of other command-line tools like FFMPEG, the frustration often does not seem worth the trouble.  Esoteric errors are near impossible to parse and files are installed in odd places (odd to me, at least).  Below are the steps I used to install the OpenCV library (blob detection, facial tracking, etc etc) for use with Python on my Mac, running 10.7.4 (Lion).

Much of this was pulled from a StackOverflow post ( but the suggestions would have been less helpful had they not be corroborated by several other posts with similar suggestions.  That said, this was the only guide I could find that worked well for me (thanks!).

  1. Install MacPorts (download here)
    If you haven’t already – this makes installation mucheasier; test the install by typing the following into the Terminal:

    If you don’t get an error, it installed correctly
  2. Check your Python version
    If you have Lion, you are likely running Python 2.7 – to double-check, type:

    And see what version comes up.  The problem installing OpenCV for Python seems to be a conflict between what version of Python MacPorts assumes and what you’re really running.  To be sure you are using 2.7, type this into the Terminal:
  3. Install NumPy
    Not sure why this is necessary, but appears to be (NumPydoes 2d array processing, so that’s likely the reason); type the following:
  4. Install OpenCV
    We’re ready!  Type the following and be prepared to wait – OpenCV is quite large and takes a while to download and get set up.  If you’ve already installed it in another location (I had) it appears that MacPorts just links it – nice!  Type:
  5. Test
    In the Terminal, type the following to enter Python:

    Then, to test OpenCV, type:

    If you don’t get an error, you’re good!  To exit Python, type:

Some of the suggestions I found say that you need to do some further profile editing and other (weird) stuff – I didn’t need to, but if you have problems it might be worth a try.

To further test the library, try this simple example that converts an image from one file format to another.  I wrote this in TextWrangler, saved the file, and ran it using the #! > Run in Terminal… command (requires the command-line tools to be installed.

The new file should be generated and you’re good to go!

Thoughts, suggestions, or problems?  Please send me an email: mail [at] jeffreythompson [dot] org

Installing ffmpeg (and LAME) on Mac Snow Leopard and Lion

A video still created programmatically; thousands of these can be combined into video using the ffmpeg library – faster and cleaner than a clunky Final Cut project

UPDATE 2: I ran into an error trying to install ffmpeg using these instructions yesterday.  However, installing using MacPorts worked like a charm! I suggest following the instructions for installing LAME first, then use MacPorts to install ffmpeg using the following command:

UPDATE: Having switched recently to Lion, the install below didn’t quite work.  With a small tweak, it appears to be ok – see below for details.

Well, it might not be Lion (doing live musical performance with my laptop makes me leary of new operating systems) but after finding little recent info on installing ffmpeg on a Mac, I’ve put together this basic outline.  For someone who isn’t great at installing libraries using Terminal, it wasn’t completely straightforward, but it works!  You will need the Apple Developer Tools to make this work (so far as I can tell).

UPDATE: I did a fresh install of XCode and had to do one small addition to get everything to compile.  For details, see this post.

This tutorial is based on the tutorial by Stephen Jungels, with some explanation and consolidation targeted at noobs (like myself).  Definite hat tip, Stephen!

The basic steps are as follows, full details after the break:

  1. Install Git
  2. Download LAME
  3. Download ffmpeg
  4. Find or create folder to install to
  5. Install LAME
  6. Install ffmpeg
  7. Test

Continue reading “Installing ffmpeg (and LAME) on Mac Snow Leopard and Lion”