I was trying to display an image in multiple ways and I suddenly encountered that.
When I instantiate the bitmap straight from the buffer using:
bitmap = wx.Bitmap( width, height, depth )
bitmap.FromBuffer( width, height, image_buffer ) # image_buffer is a numpy array that contains a picture taken by a remote device
``
This is how it looks:
bitmap = wx.Bitmap( width, height, depth )
img = wx.ImageFromBuffer( width, height, image_buffer ) #Note that I do not even use that value afterwards
bitmap.FromBuffer( width, height, image_buffer )
``
The buffer seems to be ok as I display it a few lines before using OpenCV’s cv2.imshow( window_title, image_buffer ) (that function creates a window and displays a buffer into it)
Also, it looks the same if I don’t display it in the OpenCV’s window a few lines before
.
Then, when I try to display another image after that one, it is properly displayed.
However, if I add the following line:
``
The first image is properly displayed.
wx.ImageFromBuffer() is not supposed to do anything to the data in the buffer. Neither is wx.Bitmap.FromBuffer()…
I am not quite sure I understand the problem you're seeing, but I think your wx.Bitmap code is not quite right. FromBuffer is a class method that returns a wx.Bitmap, so instead of creating a bitmap and then calling FromBuffer, you just do this:
I was trying to display an image in multiple ways and I suddenly encountered
that.
When I instantiate the bitmap straight from the buffer using:
bitmap = wx.Bitmap( width, height, depth )
bitmap.FromBuffer( width, height, image_buffer ) # image_buffer is a numpy
array that contains a picture taken by a remote device
This is how it looks:
[incomplete_frame.PNG]
The buffer seems to be ok as I display it a few lines before using OpenCV's
cv2.imshow( window_title, image_buffer ) (that function creates a window and
displays a buffer into it)
Also, it looks the same if I don't display it in the OpenCV's window a few
lines before
.
Then, when I try to display another image after that one, it is properly
displayed.
However, if I add the following line:
bitmap = wx.Bitmap( width, height, depth )
img = wx.ImageFromBuffer( width, height, image_buffer ) #Note that I do not
even use that value afterwards
bitmap.FromBuffer( width, height, image_buffer )
The first image is properly displayed.
wx.ImageFromBuffer() is not supposed to do anything to the data in the
buffer. Neither is wx.Bitmap.FromBuffer()...
Thank you for mentioning that, I had never paid attention to the “static” keyword in the documentation (I am not much experimented in Python, and even less in reading documentation).
Which has the advantage (in my case) of not copying data (I was wrong in the first mail, FromBuffer do copy data) and decreases the time for creating the bitmap by 3 (a little bit less than 1.5ms versus 4.5ms for FromBuffer (real time)).