install opencv with cuda support and.. brew
You can pass the CMAKE_INSTALL_PREFIX option to cmake to have OpenCV install to a different location. It's analagous to ./configure --prefix. For example:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/reallylocal -D WITH_CUDA ..


This will install it under /opt/reallylocal, leaving /usr/local untouched. Then, to run your custom build, call it with the full path, or put the appropriate directories on your PATH and PYTHONPATH variables when working with it. If you build other projects against your opencv, you'll need to point their build scripts at your custom install location. Leave those paths alone when doing brew tasks and other work, and brew won't care about your other install off to the side.

The OpenCV Install Guide has full details.

I tested this on my OS X 10.8.3 box. /usr stayed clean.

[✘ @ in ~/tmp/homebrew/opencv/install]
$ find /usr &gt; before-install.txt
find: /usr/sbin/authserver: Permission denied
... did the whole build &amp; install in another terminal ...
[✘ @ in ~/tmp/homebrew/opencv/install]
$ find /usr &gt; after-install.txt
find: /usr/sbin/authserver: Permission denied
[✘ @ in ~/tmp/homebrew/opencv/install]
$ diff before-install.txt after-install.txt
[@ in ~/tmp/homebrew/opencv/install]
$