Alin
Alin

Reputation: 73

opencv macport python bindings

using the MacPorts install of OpenCV does not seem to install the python bindings anywhere. Are they included, where do they go?

Upvotes: 7

Views: 6938

Answers (5)

AlcubierreDrive
AlcubierreDrive

Reputation: 3664

Here is what I had to do:

STEP ONE

Use Macports to install opencv.

STEP TWO

Put these two files somewhere on your PYTHONPATH (for example in your site-packages):

STEP THREE

Create the below soft links (because cv2.so expects the dylibs to be in /usr/local but MacPorts installs to /opt/local):

cd /usr/local/lib/
ln -s /opt/local/lib/libopencv_core.2.3.dylib libopencv_core.2.3.dylib
ln -s /opt/local/lib/libopencv_flann.2.3.dylib libopencv_flann.2.3.dylib
ln -s /opt/local/lib/libopencv_imgproc.2.3.dylib libopencv_imgproc.2.3.dylib
ln -s /opt/local/lib/libopencv_video.2.3.dylib libopencv_video.2.3.dylib
ln -s /opt/local/lib/libopencv_ml.2.3.dylib libopencv_ml.2.3.dylib
ln -s /opt/local/lib/libopencv_features2d.2.3.dylib libopencv_features2d.2.3.dylib
ln -s /opt/local/lib/libopencv_highgui.2.3.dylib libopencv_highgui.2.3.dylib
ln -s /opt/local/lib/libopencv_calib3d.2.3.dylib libopencv_calib3d.2.3.dylib
ln -s /opt/local/lib/libopencv_objdetect.2.3.dylib libopencv_objdetect.2.3.dylib
ln -s /opt/local/lib/libopencv_legacy.2.3.dylib libopencv_legacy.2.3.dylib
ln -s /opt/local/lib/libopencv_contrib.2.3.dylib libopencv_contrib.2.3.dylib

Upvotes: -1

rype
rype

Reputation: 71

I experienced this same issue. It seems the OpenCV Python bindings are built and installed, but they are not referenced in the "site-packages" directory. I have found a solution by adding a symbolic link to the built "cv.so" file in the "site-packages" directory of the Python package installed by MacPorts. These instructions are tested on a setup using Mac OS 10.6.6. The subject MacPorts packages are "python27" and "opencv".

To ensure that the Python bindings are actually on your drive, you will need to ensure you invoked the opencv package with the python variant:

sudo port install opencv +python27

The "cv.so" shared object file will be built in the following directory:

/opt/local/@@PYTHON_PKGD@@

It will be necessary to create a symbolic link in your Python's "site-packages" directory. You can find the path to this directory by executing these commands in your Python interpreter:

from distutils.sysconfig import get_python_lib
print get_python_lib()

The path returned should be similar to the following:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

Create a symbolic link to the shared object ("cv.so") within this directory:

ln -s /opt/local/@@PYTHON_PKGD@@/cv.so /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cv.so

Now you should be able to import the cv module within your interpreter:

import cv

Your setup might be slightly different if you are using a different version of Python or OpenCV; however, the general methodology should be the same with the exception of the path names. There may be a better way to do this, but this methodology seems to work well.

Upvotes: 7

meduz
meduz

Reputation: 4241

be sure to have py26-numpy installed to have support for basic functions such as cv.fromarray :

sudo port install py26-numpy

opencv will compile silently without numpy (it's not strictly a dependency).

sudo port install -v opencv +python26

there you can check that the binding to numpy is effective.

Upvotes: 1

pyfunc
pyfunc

Reputation: 66719

This should get installed in

/Library/Python/2.6/site-packages

if you use sudo port install ..

The directories 2.6, 2.5 .. will depend on python version on path.

Thanks Ned, Correcting the above - These are mac os x distribution.

Macports does put every thing under :

/opt/local/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages

Upvotes: 1

Ned Deily
Ned Deily

Reputation: 85055

Have you selected the +python26 variant for the MacPorts port?

$ sudo port install opencv +python26

Upvotes: 10

Related Questions