Passing a C ++ vector to python and back

I am using C ++ code to do some simulations on an image. At some point I need to tag the image clusters for which I want to use python ndimage.label

(because it's almost 10 times faster than my tagging code). However, I am very new to python and have no idea how to pass arguments (image) to python from C ++. No search results have been found so far

  • in C ++ code the image is saved as vector<vector<int>>

  • Python code needs to be depicted as ndarray

  • I would like to convert the output labeled array ( ndarray

    ) from python to vector<vector<int>>

    again

Can anyone suggest how this can be achieved. To begin with, any suggestions will do, although the computation time is of great concern to me.

+3


source to share


1 answer


You can use my library https://github.com/jzwinck/pccl/blob/master/NumPyArray.hpp to create a NumPy array from C ++ using existing data eg. from vector. And any changes made in Python will be reflected in C ++. It depends on Boost.Python, but the main code is simple and uses the NumPy C API directly, so you can only extract that part (key PyArray_NewFromDescr

) as well.



+3


source







All Articles