Installing openCV 2.1 with Python bindings on Mac Leopard

I had a tricky time installing openCV 2.1 on my 10.5 Mac (Leopard) recently, the build instructions aren’t brilliant in the wiki. Here are my notes.

I used the Mac notes as a guide and followed the new-style CMake system to build from scratch. I made sure during ‘cmake -G’ that new-style Python support was enabled and that it would build C and Python examples. I also needed WITH_CARBON=ON else the GUI examples all seg-fault. I didn’t change the default for WITH_QUICKTIME, my cameras worked just fine.

Next ‘c’ to configure, ‘g’ to generate and then ‘sudo make -j8′ and ‘sudo make install’ – 10 minutes later it was all compiled.

The libraries need to go into DYLD_LIBRARY_PATH, my .bash_profile now has:

export DYLD_LIBRARY_PATH=[other stuff]:/Users/ian/Documents/OpenCV-2.1.0/lib:$DYLD_LIBRARY_PATH

Finally, to make it work in Python I added the following to the .bash_profile:

export PYTHONPATH=/Users/ian/Documents/OpenCV-2.1.0/lib:$PYTHONPATH

Now ‘import cv’ works in Python, it is looking for cv.so in the /lib directory, without the PYTHONPATH update you’ll find that the C demos run but the Python demos will fail on ‘import cv’.

Out of the box on my Leopard machine the built-in iSight (and later a Philips camera) worked just fine for face_detect.py. The result of a few more hours tinkering was Headroid1, instructions for this will appear on this blog later:

OpenCV Reference Book:

The openCV book is rather excellent, everything is in C++ but the Python API is easy to figure out and the reference text makes it all clear.

5 Comments

  • hi, is there an idiot (non-programmer) resource available for understanding what needs to be done and how to do it – for the installation of OpenCV and the other ‘code bits’ to get this working on my macbook/macpro?

    I’ve kinda run into a non-programmer brick wall when it comes to actually doing something with the files i’ve downloaded :-(

    as far as servo control goes, would a lynxmotion SSC-32 do the same job as the (as yet unavailable) botbuilder board?

  • Hi David. Open source’s biggest quoted problem is the lack of clear docs – given the trouble I had that’s exactly why I wrote the above post.

    The best place to go ask questions would be their official group:
    http://tech.groups.yahoo.com/group/OpenCV/
    and (very politely!) ask for help with the Mac.

    Re. the Lynxmotion device – it looks similar so it’d probably work just fine. You could mail Steve @ BotBuilder – he’ll sell you one (he has them pre-built) they’re just not listed for sale yet.

    For more guidance do come ask questions in the Google Group:
    http://groups.google.com/group/aicookbook

  • Hi Ian,
    Thanks for the reply. I’ve used macs for >20 years and have almost never needed to poke around with real code, however i’ve downloaded the latest Xcode, installed it and macports, been into terminal ” sudo port install opencv ” and it’s currently chugging away configuring and installing. So hopefully i’m now on the right track.

  • Thanks for posting this! It was really helpful and got me up and running =)

  • Seirey wrote:

    Good night Ian!

    Great post! Its the best about this topic until now!

    I have a problem:
    When i come to “sudo make -j8″ it gives an error on 54% and dont continues, it returns to the terminal. Do you have any idea of what’s happening?

    Thank you!

Leave a Reply

Your email is never shared.Required fields are marked *