[Numpy-discussion] is there a faster way to get a buffer interface than ndarray.tostring()?
Tue Feb 24 18:47:53 CST 2009
On Tue, Feb 24, 2009 at 18:15, Chris Colbert <email@example.com> wrote:
> Hi all,
> I'm new to mailing list and relatively new (~1 year) to python/numpy. I
> would appreciate any insight any of you may have here. The last 8 hours of
> digging through the docs has left me, finally, stuck.
> I am making a wxPython program that includes webcam functionality. The
> script below just brings up a simple display window that shows the webcam
> feed. The problem I am running into is in the WebCamWorker.run() method.
> This method reads the raw pixel data (in string form) from the webcam
> buffer. This data (thank you microsoft!) comes in BGR and bottom-to-top. I
> feed this buffer to the array constructor and then swap the pixel order to
> RGB and top-to-bottom. This all happens very fast, ~1ms on a Quad Core, and
> the majority of that time is spent constructing the array (the numpy pixel
> swapping is on the order of E-5s !). The tostring() method, however, takes a
> whopping 10ms to execute. Unfortunately, the wx.BitmapFromBuffer needs a
> single segment buffer interface as an argument. Is there a way to expose my
> numpy array as a buffer to cut down on this conversion time?
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion