Skip to content

Instantly share code, notes, and snippets.

@robb-broome
Last active May 25, 2016 12:45
Show Gist options
  • Save robb-broome/9222746 to your computer and use it in GitHub Desktop.
Save robb-broome/9222746 to your computer and use it in GitHub Desktop.

#Install opencv MacOSX Mavericks

  1. fire up xcode - to insure that command line tools are there.
  2. xcode-select --install (older OS?)
  3. https://developer.apple.com/downloads/index.action# (you need an apple developer account, use your apple id)
  4. brew update
  5. brew tap homebrew/science
Cloning into '/usr/local/Library/Taps/homebrew-science'...
remote: Reusing existing pack: 3765, done.
remote: Counting objects: 63, done.
remote: Compressing objects: 100% (63/63), done.
remote: Total 3828 (delta 27), reused 0 (delta 0)
Receiving objects: 100% (3828/3828), 974.71 KiB | 1.38 MiB/s, done.
Resolving deltas: 100% (1782/1782), done.
Tapped 244 formula

If your py is in good shape you may be able to skip down to 'brew install opencv'. No harm in trying.

  1. brew uninstall python
  2. brew unlink python
  3. brew install python - (many bad links to delete here, ended up forcing it)
     	> brew link --overwrite python
     	Linking /usr/local/Cellar/python/2.7.6... 35 symlinks created
     
  4. pip install numpy... expect a ton of very helpful warnings and complicated-looking output, followed by
     Successfully installed numpy
     Cleaning up...
     
  5. Add to .bashrc or .zshrc:
export PYTHONPATH=/usr/local/Cellar/opencv/2.4.7.1/lib/python2.7/site-packages:$PYTHONPATH

finally, in a new terminal window:

 brew install opencv
➜  we-main git:(feature/112-org-thumb) ✗ rvm:(ruby-2.0.0-p247@we) brew install opencv
==> Installing dependencies for opencv: cmake, libpng
==> Installing opencv dependency: cmake
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/cmake-2.8.12.2.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring cmake-2.8.12.2.mavericks.bottle.2.tar.gz
 /usr/local/Cellar/cmake/2.8.12.2: 701 files, 36M
==> Installing opencv dependency: libpng
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libpng-1.5.17.mavericks.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring libpng-1.5.17.mavericks.bottle.1.tar.gz
 /usr/local/Cellar/libpng/1.5.17: 15 files, 1.0M
==> Installing opencv
==> Downloading https://github.com/Itseez/opencv/archive/2.4.7.1.tar.gz
######################################################################## 100.0%
==> Patching
patching file cmake/OpenCVFindOpenNI.cmake
==> cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/opencv/2.4.7.1 -DCMAKE_BUILD_TYPE=None -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DCMAKE_OSX_DEPLOYMENT_TA
==> make
==> make install
==> Caveats
Set PYTHONPATH if you need Python to find the installed site-packages:
  export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
==> Summary
/usr/local/Cellar/opencv/2.4.7.1: 217 files, 39M, built in 113 seconds

Get a look

brew info opencv
opencv: stable 2.4.7.1
http://opencv.org/
/usr/local/Cellar/opencv/2.4.7.1 (217 files, 39M) *
  Built from source
From: https://github.com/homebrew/homebrew-science/commits/master/opencv.rb
==> Dependencies
Build: cmake ✔, pkg-config ✔
Required: libpng ✔
Optional: eigen ✘, libtiff ✔, jasper ✔, tbb ✘, qt ✔, openni ✘, ffmpeg ✘
==> Options
--32-bit
	Build 32-bit only
--c++11
	Build using C++11 mode
--with-eigen
	Build with eigen support
--with-ffmpeg
	Build with ffmpeg support
--with-jasper
	Build with jasper support
--with-libtiff
	Build with libtiff support
--with-openni
	Build with openni support
--with-qt
	Build the Qt4 backend to HighGUI
--with-tbb
	Enable parallel code in OpenCV using Intel TBB
--without-opencl
	Disable gpu code in OpenCV using OpenCL
==> Caveats
Set PYTHONPATH if you need Python to find the installed site-packages:
  export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

##Notes on implementation

  1. example using opencv to detect a face: https://github.com/ruby-opencv/ruby-opencv/blob/master/test/samples/haarcascade_frontalface_alt.xml.gz
  2. Get the points from opencv: http://www.ruby-doc.org/gems/docs/o/opencv-0.0.6/OpenCV/CvPoint.html
@BhavikDhandhalya
Copy link

Hello there, I followed all steps and its work perfectly , now after installing all the things , in new terminal when I write command like "python" - it was show me python editor with python compiler ,

now in this when I wrote like this "import opencv", it was showing me like this error

Last login: Sat Mar 14 13:54:06 on ttys000
Bhaviks-MacBook-Pro:~ R0b$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import opencv
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named opencv

@bjoernh
Copy link

bjoernh commented Jan 24, 2016

the module name is "cv" not opencv.
try: import cv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment