[C++-sig] Boost Python wrapper for a c++ class that uses Opencv 2.3
Jim Bosch
talljimbo at gmail.com
Wed Sep 21 15:43:57 CEST 2011
On 09/21/2011 09:31 AM, Kevin Hughes wrote:
> I am trying to create a python library from a class which uses opencv
> 2.3. I want to be able to pass numpy array's into the class where they
> will be converted into cv::Mat's processed then converted back to numpy
> array's and returned.
>
> Here is a simple test class I am working on to get this working before
> wrapping my own class. Currently I am just trying to receive a numpy
> array concert to a cv::Mat, process it and then write it to file. After
> this is working I will work on returning the processed array to python.
>
Without digging too deeply or getting into possibly better solutions,
try adding:
import_array();
inside your BOOST_PYTHON_MODULE block. Or maybe there's some opencv
initialization function you need to call that will do that for you. The
NumPy C-API (which I assume the numpy_to_mat function uses internally)
needs to be initialized when your module is imported, or you'll get
segfaults. The above call to import_array() is how you'd do it if you
were using the NumPy C-API headers directly. In any case, you need to
make sure it gets called somehow.
HTH
Jim Bosch
More information about the Cplusplus-sig
mailing list