Installing OpenCV on OS/X with Python

2 minute read

I need to get OpenCV working on my system for a couple of image processing tasks I have for work, and as with many complex software systems, it was somewhat difficult to get it working on my system, a macbook pro running Leopard (OS/X 10.5).

Their installation instructions were fairly good.  I first tried to use regular old make, but I had a few issues with libraries that regular old make couldn’t find.  So I installed cmake to use for this purpose.  I highly recommend it.
With cmake, I was successful with the suggested instructions:
% mkdir build
% cd build
After that, ‘make’ and ‘make install’.  
I ran into a few issues during this process.
  • No swig on my system.  The installation page lists it as an optional install, but it’s needed for python, and python is what I want (they say this, but I thought it would do something other than just ignore my desire for python).  So install swig, and use the CMake GUI tool to make sure that your SWIG_DIR is set correctly.
  • Couldn’t find my Python.h file.  Since I had installed my python using darwinports, my Python.h isn’t really where it was looking.  I fixed this by editing the CMakeCache.txt to change PYTHON_INCLUDE_PATH:PATH=/sw/include/python2.5.  If your swig stuff is complaining about no Python.h (but you have one), find your Python.h and change this line in CMakeCache.txt.  There’s probably a more elegant solution, but this worked.
  • For some reason CMake was pointing to the wrong SDK on my system (.  It wanted to use the 1.4u version, but I’ve got 1.5, so I changed /Developer/SDKs/MacOSX10.4u.sdk to /Developer/SDKs/MacOSX10.5.sdk using the CMake GUI.
  • Couldn’t find my resulting opencv library.  I copied it to the /Library/Python path.
  • I wanted to make sure it installed all of the examples, so I selected them using hte CMake GUI utility.

Note that I did try the darwinports version, and lost a couple of hours trying to figure out how to get the python piece of that to work on my system.  I don’t suggest that path.

I am pleased to report that now the python examples (at least) work on my system.  Including the which I needed to do the actual task ahead of me.  So, hurray.
I decided that to implement a houghcircles example I should really get the C code examples working, and thanks to the helpful instructions here I was able to do it easily. Follow those instructions and then you’ll be able to compile and run all of the C example files (and make your own, and run them too!)
So I wrote a houghcircles example using some of the example code from the opencv book, and it works, kinda.  Pretty well I think, for just futzing around for an evening:


Someone wrote to me about this blog post and said they were having some trouble with using the iSight for video input.  I discovered I was having the same problem.  The answer, gleaned from various places on the internets, was to unset DYLD_LIBRARY_PATH in my environment.  Confuses the heck out of openCV.  Which is kind of a problem because ROS requires it, at least to build.  So if you get weird library missing/wrong errors, unset that bad boy and see if it helps.