I'm addicted to it so I'll briefly summarize how to do it. ... but it's easy.
Mac 10.9.4 Python 2.7.8 OpenCV 2.4.9
If you have numpy installed in advance, the Python libraries cv.py and cv2.py are included in the OpenCV directory (/usr/local/Cellar/opencv/version/ if installed with brew) when you install OpenCV. One thing to do. Just make these symlinks under your Python site-packages directory.
Below, from the installation of OpenCV.
brew tap homebrew/science
Next, check if numpy is included. The same applies when using a virtual environment with virtualenv. Make sure numpy is installed,
brew install opencv
Next, go to the Python site-packages directory you are currently using and use the following command to make a symbolic link. So if you're not using virtualenv, for example
cd /Library/Python/2.7/site-packages/
If you are using virtualenv, for example
cd ~/.virtualenv/Environment name/lib/python2.7/site-packages
All you have to do is use the following command to create a symbolic link!
ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv.py cv.py
ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv2.so cv2.so
If you import as below and no error occurs, it is successful!
➜ ~ python
Python 2.7.8 (default, Oct 16 2014, 05:18:45)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
>>> import cv2
If you get a segmentation fault, the symbolic link is not broken. If you just copy cv.py and cv2.py under site-packages, it will look like this. I think that just copying it does not connect to the main body of OpenCV. Please be careful.
If you get an error saying that there is no library called cv in the first place, there is a high possibility that the Python package is not installed at the same time when you installed OpenCV, so uninstall OpenCV once and make sure that numpy is installed. Please check and try again.
To be honest, it's just as it is, except for the virtualenv crap. Use OpenCV with Python! There are many articles, but the following link was the most concise and good. Installing OpenCV 2.4.9 on Mac OSX with Python Support
Recommended Posts