Using OpenCV with Python @Mac

Use OpenCV with Python

I'm addicted to it so I'll briefly summarize how to do it. ... but it's easy.

environment

Mac 10.9.4 Python 2.7.8 OpenCV 2.4.9

procedure

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.

reference

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

Using OpenCV with Python @Mac
[Python] Using OpenCV with Python (Basic)
[Python] Using OpenCV with Python (Image Filtering)
[Python] Using OpenCV with Python (Image transformation)
[Python] Using OpenCV with Python (Edge Detection)
Binarization with OpenCV / Python
Video processing using Python + OpenCV on Mac
"Apple processing" with OpenCV3 + Python3
[S3] CRUD with S3 using Python [Python]
Using Quaternion with Python ~ numpy-quaternion ~
Image editing with python OpenCV
Camera capture with Python + OpenCV
Python3 + Django ~ Mac ~ with Apache
Face detection with Python + OpenCV
Send using Python with Gmail
Try projective transformation of images using OpenCV with Python
Complement python with emacs using company-jedi
Shining life with Python and OpenCV
Harmonic mean with Python Harmonic mean (using SciPy)
Neural network with OpenCV 3 and Python 3
Introducing OpenCV on Mac with homebrew
Easy Python + OpenCV programming with Canopy
Cut out face with Python + OpenCV
Face recognition with camera with opencv3 + python2.7
Load gif images with Python + OpenCV
Notes on using rstrip with python.
Find image similarity with Python + OpenCV
Graph Based Segmentation with Python + OpenCV
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
Install python with mac vs code
Draw arrows (vectors) with opencv / python
Basic study of OpenCV with Python
[AWS] Using ini files with Lambda [Python]
Face detection with Python + OpenCV (rotation invariant)
FizzBuzz with Python3
[Python] Building an environment with Anaconda [Mac]
Install opencv on Mac using Anaconda Navigator
Scraping with Python
Statistics with python
Try mathematical formulas using Σ with python
Behind the flyer: Using Docker with Python
Scraping with Python
Save video frame by frame with Python OpenCV
Using Python and MeCab with Azure Databricks
Try using the camera with Python's OpenCV
Socket communication using socketserver with python now
Capturing images with Pupil, python and OpenCV
Twilio with Python
Integrate with Python
Start using Python
Follow active applications on Mac with Python
Try using Python with Google Cloud Functions
Play with 2016-Python
I tried non-photorealistic rendering with Python + opencv
AES256 with python
Check stock prices with slackbot using python
Image processing with Python & OpenCV [Tone Curve]
Working with OpenStack using the Python SDK
python starts with ()
Tips for using python + caffe with TSUBAME