Posts

Showing posts from September, 2013

Calling OpenCV functions via Cython from Python 3.X.

I have managed to run OpenCV function from Python3 via Cython today, so I want to write about it. Before you start something like this, you should know you have to read at least header files of C library to write right definition in Cython,because Cython does not do that for you. I am using virtualenv, python from pythonz, and home-brewed OpenCV. Almost everything of C++ works just fine with Cython, but still, you should do some Voodoo things like for integer template argument. ctypedef void* int_parameter ctypedef int_parameter two "2" ctypedef Point_[float, two] Point2f Now, main sample Cython code is following. #===== testopencv.pyx ======== import numpy as np cimport numpy as np # for np.ndarray from libcpp.string cimport string from libc.string cimport memcpy cdef extern from "opencv2/core/core.hpp": cdef int CV_WINDOW_AUTOSIZE cdef int CV_8UC3 cdef extern from "opencv2/core/core.hpp" namespace "cv": cdef cppclass Mat: Ma

Boost.python for virtualenv (FINALLY!)

After hours of struggling, I did succeed to build boost for multiple pythons on virtualenv environments. Boost Web Site helped me very much.  As a conditions, you should know python 2.7.3 and 3.2 were installed by pythonz + virtualenv beforehand. I installed boost.python as follows. 1. Download boost from here . 2. unzip archive. > tar -xvfz boost_1_XX_X.tar.bz2 3. Exec bootstrap.sh > cd boost_1_XX_X > ./bootstrap.sh  4. Edit project-config.jam as follows # Boost.Build Configuration # Automatically generated by bootstrap.sh import option ; import feature ; # Compiler configuration. This definition will be used unless # you already have defined some toolsets in your user-config.jam # file. if ! darwin in [ feature.values ] { using darwin ; } project : default-build darwin ; # Python configuration using python : 2.7 : /PATH/TO/VIRTUALENV/PYTHON2.7 : /PATH/TO/VIRTUALENV/PYTHON2.7/HEADERS #includes : /PATH/TO/VIRTUALENV/PYTHON2.7/LIBS #libraries ;