Hi Dat,
I see what you mean. What you are asking is doable but it is rather
technically challenging. In order to expose a function returning cv::Mat in
your Boost.Python module, you need to register *in your module* some code to
convert from a C++'s cv::Mat object to a Python object and vice versa. If you
don't register any conversion code in your module, the default conversion
code that Boost.Python provides is to generate a TypeError exception. Since
you would like to use PyOpenCV for the purpose of wrapping cv::Mat, I think
your two best choices are:
1) rip apart Mat.pypp.cpp and any source files you need from PyOpenCV's
source archive and compile/link them together with your code wrapping MyClass.
2) write C++ to_python/from_python conversion code that, when called, imports
pyopencv, gets the Python type of its Mat object, and does the conversion
between a C++ object and a Python object properly. More specifically, the
to_python code must take a pointer to your cv::Mat and create a Python object
of type PyOpenCV's Mat that wraps around your cv::Mat object. The from_python
code must take a Python object, verify that it is of type PyOpenCV's Mat, and
return a pointer to the wrapped cv::Mat object. You will also have to worry
about reference counting. Take a look at the following files for examples:
ndarray.hpp
ndarray.cpp
sequence.hpp
sequence.cpp
in which I have written some conversion code to interface with numpy's
ndarray. The code is based on an example in Py++, which is based on
Boost.Python's _undocumented_ API. :)
Cheers,
Minh-Tri
>>
ctypes-openc...@googlegroups.com<
ctypes-opencv%2Bunsu...@googlegroups.com>
>> .