Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't used SWIG or SIP, but I find writing Python wrappers with <a href="http://www.boost.org/doc/libs/1_35_0/libs/python/doc/index.html" rel="nofollow noreferrer">boost.python</a> to be very powerful and relatively easy to use.</p> <p>I'm not clear on what your requirements are for passing types between C/C++ and python, but you can do that easily by either exposing a C++ type to python, or by using a generic <a href="http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/object.html" rel="nofollow noreferrer">boost::python::object</a> argument to your C++ API. You can also register converters to automatically convert python types to C++ types and vice versa.</p> <p>If you plan use boost.python, the <a href="http://www.boost.org/doc/libs/1_35_0/libs/python/doc/tutorial/doc/html/index.html" rel="nofollow noreferrer">tutorial</a> is a good place to start.</p> <p>I have implemented something somewhat similar to what you need. I have a C++ function that accepts a python function and an image as arguments, and applies the python function to each pixel in the image.</p> <pre><code>Image* unary(boost::python::object op, Image&amp; im) { Image* out = new Image(im.width(), im.height(), im.channels()); for(unsigned int i=0; i&lt;im.size(); i++) { (*out)[i] == extract&lt;float&gt;(op(im[i])); } return out; } </code></pre> <p>In this case, Image is a C++ object exposed to python (an image with float pixels), and op is a python defined function (or really any python object with a &#95;&#95;call&#95;&#95; attribute). You can then use this function as follows (assuming unary is located in the called image that also contains Image and a load function):</p> <pre><code>import image im = image.load('somefile.tiff') double_im = image.unary(lambda x: 2.0*x, im) </code></pre> <p>As for using arrays with boost, I personally haven't done this, but I know the functionality to expose arrays to python using boost is available - <a href="http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/faq.html#question2" rel="nofollow noreferrer">this</a> might be helpful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload