Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 649
Alin Avatar asked Sep 10 '10 00:09

Alin


4 Answers

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

$ sudo port install opencv +python26
like image 93
Ned Deily Avatar answered Nov 11 '22 04:11

Ned Deily


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.

like image 41
rype Avatar answered Nov 11 '22 04:11

rype


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

like image 1
pyfunc Avatar answered Nov 11 '22 04:11

pyfunc


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.

like image 1
meduz Avatar answered Nov 11 '22 04:11

meduz