Category Archives: OpenCV

How to build OpenCV with GPU support via MacPorts in OS X 10.8

First thing first, install the NVIDIA CUDA libraries from https://developer.nvidia.com/cuda-downloads (take notice that last night, OS X 10.9 Mavericks has got its update too!)

Second, open Terminal and add the two paths below

export PATH=/Developer/NVIDIA/CUDA-5.5/bin:$PATH
export DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-5.5/lib:$DYLD_LIBRARY_PATH

if previously installed, uninstall opencv.

sudo port uninstall opencv @2.4.6.1_2+python27

If you have a different version installed, MacPorts will tell you and you’ll need to change the one above with your own, of course. Now you need to edit the opencv’s portfile

sudo port edit --editor nano opencv

nano will open up, scroll down and change the appropriate settings to

-DWITH_CUDA=ON

and optionally

-DWITH_CUBLAS=ON
-DWITH_CUFFT=ON
-DWITH_OPENCL=ON

you “could” also add

-DWITH_CUSPARSE=ON

(although I’m not completely sure this is the right syntax for cusparse though! Please do let me know if this is the case)

Now, it’s time to clean the previous installation

sudo port clean opencv

And at last, type

sudo port upgrade -s -n --force opencv

to rebuild the amended portfile. The flag -n avoids rebuilding of the dependencies and -s starts building from the source code only with no binaries whatsoever and now you can go get yourself a cuppa, even two, as this step will take a bit (about half a hour on a rMBP).

These links below can be helpful too:

http://ewen.mcneill.gen.nz/blog/entry/2012-06-04-macports-rebuilding-broken-port/

https://trac.macports.org/browser/trunk/dports/graphics/opencv/Portfile

http://stackoverflow.com/questions/11035500/trying-to-build-opencv-2-4-1-with-opengl-support

installing OpenCV on MacOS Snow Leopard for Python 2.6

As a result of encountering problems in installing OpenCV, I thought I would drop a few lines with the sequence of steps that worked for me, in the end. However Homebrew looks cooler, and probably it is, I found it more helpful to make use of MacPorts and do all of the installation with it.

My specific problem was that Python 2.6 (Framework) was 32-bit which then clashed with the Homebrew installation of OpenCV 2.3.1a which is 64-bit. Homebrew instructions says you can customise the installation to 32-bit but… it just didn’t work, not even in installing Python 2.6 64-bit as a Framework.

So, I moved on to try the MacPorts option and that actually managed to install Python 2.6 64-bit as a Framework, in the first place, and the rest of the libraries followed smoothly after too.

So, installing MacPorts is step one. Use the Terminal from now on.

2) sudo port selfupdate
3) install zlib, sudo port install zlib +universal
4) install Python 2.6.8 (as framework and 64-bit), sudo port install python26 +universal
5) make it the first choice,
sudo port select –set python python26 (or ‘sudo port select python python26’ in Mac OS Lion)
6) install OpenCV,
sudo port -v install opencv +python26
7) (optional) install PyQt4 and OpenGL library,
sudo port install py26-pyqt4

sudo port install py26-opengl

That’s all.

A test to see whether your python is 64-bit is open python in Terminal and type
print hash(‘a’)
If the result is 12416037344 then you’re setup with a 64-bit python framework.

Hope this helps,
Ivano