[C++-sig] Boost Python wrapper for a c++ class that uses Opencv 2.3

Kevin Hughes k.hughes at queensu.ca
Wed Sep 21 16:25:52 CEST 2011


Thanks for the reply, I tried adding import_array(); to my
BOOST_PYTHON_MODULE block but I still got an error when importing my library
into python, the same same error I mentioned above.

On Wed, Sep 21, 2011 at 9:43 AM, Jim Bosch <talljimbo at gmail.com> wrote:

> 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
> ______________________________**_________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/**mailman/listinfo/cplusplus-sig<http://mail.python.org/mailman/listinfo/cplusplus-sig>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20110921/9bf7635c/attachment.html>


More information about the Cplusplus-sig mailing list