On Oct 17, 2007, at 3:59 PM, Jefferson Provost wrote:
> On Oct 16, 2007, at 4:55 PM, Brian Gerkey wrote:
>> On Oct 16, 2007, at 11:59 AM, Alexis Maldonado wrote:
>>> Lately, the Python bindings of PlayerCVs are not including all the
>>> constants from libplayerc. This probably needs to be fixed in the
>>> file. In the meantime, just use p.subscribe(1). (And do the same
>>> for the
>>> other constants that you might need, just look up the appropriate
>>> value in
>> Patches to fix this would be most appreciated....
> I've been considering writing a SWIG or BoostPython wrapper for
> (parts of) the C++ library. The SWIG-generated wrapper code for the
> C library has some incredible inefficiencies. E.g. it was taking 500
> milliseconds to get an image from a camera device on my 2GHz Athlon.
> Copying the equivalent of a 320x240 color image from an array in
> python only takes about 5ms.
> Looking inside playerc_wrap.c, I discovered that
> _wrap_playerc_camera_image_get calls PyInt_FromLong individually on
> all 8 million elements of the image data array before setting them
> one-by-one the result list.
> I assume that swig is doing equally dumb things elsewhere.
Actually, it turns out that SWIG doesn't do this by default. It's
the playerc.i typemaps that do it. I was able to speed things up
enormously for getting images by replacing the typemap for 'uint8_t
[ANY]' with this:
%typemap(out) uint8_t [ANY]
$result = PyBuffer_FromMemory((void*)$1,sizeof(uint8_t)*$1_dim0);
This just returns a Python buffer object pointing at the image data.
Then you can use PIL's Image.fromstring() or Image.frombuffer() to
very rapidly (<1ms) create an image object that can be manipulated in
I'll be happy to send a patch if you want it.