Suppose you have completed the installation of Homebrew and Python3.6.
Step 1. Download OpenCV using brew
brew install opencv
Step2. Link the downloaded OpenCV .so for Python with Python’s site package
cd /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
echo /usr/local/opt/opencv@3/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so
ln -s /usr/local/opt/opencv@3/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so cv2.so
Step3: Error handling
Enter Python3.6, input “import cv2”, you might get
>>> import cv2
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
Then, what you should do is merely update the numpy to the latest version, like type following in the terminal:
pip3.6 install -U numpy
Others:
If you want to install OpenCV2 instead of OpenCV3, you can use
brew search opencv
to find any version provided by brew. Here I have opencv (which denotes 3) and opencv@2. Currently (2018.01.09), OpenCV2 merely supports python2 while OpenCV3 offers .so to both of 2 and 3.
If you want to install caffe and using OpenCV2, then if you use brew to install both of OpenCV2 and 3, you may need the following instruction
brew link opencv@2
to allow cmake find right opencv when make the file.