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
1.cd /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
2.echo /usr/local/opt/opencv@3/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so
3.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
1.>>> import cv2
2.RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
3.Traceback (most recent call last):
4. File "<stdin>", line 1, in <module>
5.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:
1.pip3.6 install -U numpy
Others:
If you want to install OpenCV2 instead of OpenCV3, you can use
1.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
1.brew link opencv@2
to allow cmake find right opencv when make the file.
原地址:http://blog.csdn.net/lyrassongs/article/details/79010717