How to display image from a list

Dear All,

I want to make a GUI to display live images that I capture with a camera real time or live. What I actually have continously is a list of integers that contain the image. If I save firs to file and the read in again, then I know how to display it from what I have seen on the net or the wxPython demo example of displaying a bit map. By the way is it really a list of integer as I have a monochromatic grayscale image. So it is not a list of tuples or r,g, b values. So actually how do I set the data to a wx.Image. So a simple example. Let say I have an image of size , width 2, height 5. and the pixel values are stored as integer in a list

pixValueList = [0,1,2,3,4,5,6,7,8,9]

how do I display this image ?

Thanks in advance.

robert

···

Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

I think the file images.py will point you in the right direction. Here's a short excerpt:

# This file was generated by encode_bitmaps.py

···

At 03:55 PM 4/25/2008, you wrote:

Dear All,
I want to make a GUI to display live images that I capture with a camera real time or live. What I actually have continously is a list of integers that contain the image. If I save firs to file and the read in again, then I know how to display it from what I have seen on the net or the wxPython demo example of displaying a bit map. By the way is it really a list of integer as I have a monochromatic grayscale image. So it is not a list of tuples or r,g, b values. So actually how do I set the data to a wx.Image. So a simple example. Let say I have an image of size , width 2, height 5. and the pixel values are stored as integer in a list

pixValueList = [0,1,2,3,4,5,6,7,8,9]

how do I display this image ?

Thanks in advance.

robert

#
from wx import ImageFromStream, BitmapFromImage, EmptyIcon
import cStringIO

def getMondrianData():
     return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
\xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
\x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
\x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'

def getMondrianBitmap():
     return BitmapFromImage(getMondrianImage())

def getMondrianImage():
     stream = cStringIO.StringIO(getMondrianData())
     return ImageFromStream(stream)

def getMondrianIcon():
     icon = EmptyIcon()
     icon.CopyFromBitmap(getMondrianBitmap())
     return icon

HTH, Phil

Robert Robert wrote:

I have a monochromatic grayscale image. So it is not a list of tuples or r,g, b values. So actually how do I set the data to a wx.Image. So a simple example. Let say I have an image of size , width 2, height 5. and the pixel values are stored as integer in a list
pixValueList = [0,1,2,3,4,5,6,7,8,9]

First, it's a bit odd, and inefficient, to have this in a list, you'd be better of with the data in a string or array.array.

how do I display this image ?

I'm pretty sure wx only support RBG images to be loaded up in this way. So, you'll need to use another tool to convert your data to RGB. Two options are:

1) PIL: The Python Imaging library

It should be able to do this for you, and once you have an RBG image in PIL, you can make a wxImage out of it:

http://wiki.wxpython.org/WorkingWithImages

2) numpy: Numerical python
numpy provides a n-dimensional array object, and lot of tools for doing math with them. In this case, an RBG image is a Width X Height X 3 array. So for the above data:

import numpy as np

# create an array for your data
RGB = np.zeros((width, height, 3), dtype=np.uint8)
# fill it in: (R = G = B fr grey)
RGB[:,:,0] = pixValueList
RGB[:,:,1] = pixValueList
RGB[:,:,2] = pixValueList
# scale it to 0-255:
RGB *= 255.0/MaxValue # MaxValue is the value of white in your data

#now you've got RBG image data. To make a wx.Image:
image = wx.EmptyImage(width,height)
image.SetData( RGB.tostring())

-Chris

···

Thanks in advance.
robert

------------------------------------------------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. <http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ >

------------------------------------------------------------------------

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Robert Robert wrote:

Dear All,
I want to make a GUI to display live images that I capture with a camera real time or live. What I actually have continously is a list of integers that contain the image. If I save firs to file and the read in again, then I know how to display it from what I have seen on the net or the wxPython demo example of displaying a bit map. By the way is it really a list of integer as I have a monochromatic grayscale image. So it is not a list of tuples or r,g, b values. So actually how do I set the data to a wx.Image. So a simple example. Let say I have an image of size , width 2, height 5. and the pixel values are stored as integer in a list
pixValueList = [0,1,2,3,4,5,6,7,8,9]
how do I display this image ?

You'll need to convert it to a buffer of RGB bytes where your greyscale values are simply replicated such that R = G = B = original_value. Then you can pass that to wx.Image's SetData method, or the wx.BitmapFromBuffer factory function. I expect that Chris Barker or somebody can tell you how to do that conversion in 1 line with the numpy module...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Dear All,

I wrote a simple wxPython GUI program. It has a frame, and on the frame I put a panel. And on the panel 3 buttons, start, stop, exit. I also plot on the panel a static bitmap. What I want is to plot continuously in a certain frequency images till the user press the stop button. Therefore I use a thread with a callback function. On windows my program runs very well with no problem at all. But when I start it on windows and press the start button I get the following strange error

Xlib: unexpected async reply (sequence 0x76b)!

I’ve searched on the internet and saw that this problem may be cause when you write things to your frame from the thread. But I thought that I was not doing this as I use a wx.PostEvent to refresh my image on the frame. Could someone please help me out with this problem. Her below I post the python script I have.

I
wanted to know also how I disable the (x) fucntionality on my main frame so that the user is obliged to close the program by pressing the exit button. Or is there a way to activate the exit function bind to the exit button when the user pressed the (x) sign on the main frame window ?

Many thanks in advance.

import wx
import cStringIO
import array
import time
import threading
import scipy
import cStringIO

[
EVT_UPDATE_ID, FRAME_ID
] = [wx.NewId() for i in range(1)]

class UpdateImageEvent( wx.PyEvent ):
“”"
Event Class to update the captured image
“”"
def init(self, bmp ):
“”"
@param tekst : bmp image

“”"
wx.PyEvent.init(self)
self.SetEventType( EVT_UPDATE_ID )
self.bmp = bmp

class imageViewerThread( threading.Thread ):
def init( self, refFrame ):
threading.Thread.init( self )
self._finished = threading.Event()
self._interval = 0.05
self._refFrame = refFrame

self.stopTask = None

def init( self ):
pass

def exit( self ):
pass

 def setInterval( self, interval

):
self._interval = interval

def shutdown( self ):
    self.stopTask = True
   
def run( self ):
    self.stopTask = False
    while not self.stopTask:
        self.task()
        self._finished.wait( self._interval )
    self.exit()

def task( self ):
    data = open( "temp.tif", "rb").read()
    stream = cStringIO.StringIO(data)
     bmp = wx.BitmapFromImage(

wx.ImageFromStream( stream ) )

wx.PostEvent( self._refFrame, UpdateImageEvent( bmp ) )

class MyFrame(wx.Frame):
def init(
self, parent, ID, title, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
):
wx.Frame.init(self, parent, ID, title, pos, size, style)

self._parent = parent
Font1 = wx.Font( 10, wx.DEFAULT, wx.NORMAL,
wx.BOLD, False,
“”, wx.FONTENCODING_SYSTEM )

    self.SetMinSize( size )
    self.SetMaxSize( size )
    self.SetSize( size )

self.panel = wx.Panel( self )
self.btn = wx.Button( self.panel, -1, “Start”, pos=( 10,10 ) )
self.btnStop = wx.Button( self.panel, -1, “Stop”, pos=( 10,40 ) )
self.btnExit = wx.Button( self.panel, -1,
“Exit”, pos=( 10,150 ) )

    # bind the button events to handlers
    self.Bind(wx.EVT_BUTTON, self.OnButtonPlot, self.btn )
    self.Bind(wx.EVT_BUTTON, self.OnButtonStop, self.btnStop )
    self.Bind(wx.EVT_BUTTON, self.OnButtonExit, self.btnExit )

self.staticBitmap =
wx.StaticBitmap( self.panel, -1, pos=(150,20), size=(350, 450) )
# set default image
data = open( “image.jpg”, “rb”).read()
stream = cStringIO.StringIO(data)
bmp = wx.BitmapFromImage( wx.ImageFromStream( stream
) )
self.staticBitmap.SetBitmap( bmp )
self.staticBitmap.Refresh()

    self.mThread = None

self.Connect( wx.ID_ANY, wx.ID_ANY,
FRAME_ID,
self.UpdateImage )

def UpdateImage( self, event ):
self.staticBitmap.SetBitmap( event.bmp )
self.staticBitmap.Refresh()

def OnButtonPlot( self, evt
):
self.mThread = imageViewerThread( self.panel, exposureTime )
self.mThread.init()
self.mThread.start()
self.btn.Enable( False )
self.btnStop.Enable( True )
self.btnExit.Enable( False )

def OnButtonStop( self, evt ):
self.mThread.shutdown()
del self.mThread
self.mThread = None
self.btn.Enable( True )
self.btnStop.Enable( False )
self.btnExit.Enable( True )

def
OnButtonExit(self, event):
self.Close(True)
self.Destroy()

class main(wx.App):
def OnInit(self):
win = MyFrame(None, FRAME_ID, “GigE Viewer”, size=( 850, 550 ),
style = wx.DEFAULT_FRAME_STYLE)
win.Show( True )
return True

application = main(0)
application.MainLoop()

···

Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

Chris (and others),

Some of you seem to know the ins and outs of wxPython REALLY well. I wish there were more example code out there that could steer us in the right direction instead of looking at the wxpython docs (with no examples).

In any case, I’ve moved my drawing code out of a thread and placed it in the OnIdle() function of my Window Class.

Here’s my main problem: I am creating a streaming socket from a renderer that passes pixel information on-the-fly. This code is implemented in my ScanMR() function and it works well (without any GUI). Here’s the format of the function:

scanMR( clientWindow, hostname, portNumber ):
# get the renderer socket info, port, etc… and open it

while True:
# if there is no more socket connection
# then we are done rendering…
break

            # compute the tile information and store
            # it into an approved buffer for converting   
            # to a bitmap
            ...
            rgba = all pixel data for a tile (rgba).

            # call the writeTile function to write this tile (bitmap)  
            #  to the window.
            writeTile ( clientWindow, x, y, tileWidth, tileHeight, rgba )        

      # we are done
      # close the socket
      # return to ON_IDLE or main Window

writeTile ( clientWindow, x, y, tileWidth, tileHeight, rgba ):
# write some rectangles on the screen
# i don’t use the data from rgba yet.
dc = wx.BufferedDC( wx.ClientDC(clientWindow), clientWindow.buffer)
dc.DrawRect(x,y,tileWidth,tileHeight)

2 things:

  1. This will only display the rectangles AFTER rendering is complete! Even if I put a clientWindow.Refresh() call in the writeTile() function, the window doesn’t show the tiles being rendered as it gets streamed in. Arrghh!!!

  2. ON_IDLE isn’t going to work for me. I need something that will continuously draw to the screen when there is streaming activity. With ON_IDLE, my mouse pointer HAS to be in the window in order for the event to get processed. This led me to creating my own MainLoop() function but I don’t know how to create that.

Lastly, I don’t understand how wx.Timer can play in this.

-M

···

Date: Mon, 28 Apr 2008 10:11:34 -0700
From: Chris.Barker@noaa.gov
Subject: Re: [wxpython-users] Xlib: unexpected async reply (sequence 0x76b)!
To: wxpython-users@lists.wxwidgets.org

Robert Robert wrote:

Dear All,

I wrote a simple wxPython GUI program. It has a frame, and on the frame
I put a panel. And on the panel 3 buttons, start, stop, exit. I also
plot on the panel a static bitmap. What I want is to plot continuously
in a certain frequency images till the user press the stop button.
Therefore I use a thread with a callback function. On windows my program
runs very well with no problem at all. But when I start it on windows
and press the start button I get the following strange error

Xlib: unexpected async reply (sequence 0x76b)!

I’ve searched on the internet and saw that this problem may be cause
when you write things to your frame from the thread. But I thought that
I was not doing this as I use a wx.PostEvent to refresh my image on the
frame.

You are calling:

bmp = wx.BitmapFromImage( wx.ImageFromStream( stream ) )

inside your thread – I think wxGTK uses X to manipulate bitmaps, so
that’s your problem. The rule of thumb is – if it is wx.Anything, don’t
call it inside a thread unless you know it’s safe, like wx.PostEvent and
wx.CallAfter.

You can probably do all this with a wx.Timer, and not bother with
threads at all. Otherwise, more the bitmap generation from the thread to
the main code.

-Chris

I wanted to know also how I disable the (x) fucntionality on my main
frame so that the user is obliged to close the program by pressing the
exit button. Or is there a way to activate the exit function bind to the
exit button when the user pressed the (x) sign on the main frame window ?

Take a look at styles for wx.Frame, I think there is one that eliminates
the (X) – also, you can catch EVT_CLOSE, and override it there, I think.

-Chris


Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


Back to work after baby– how do you know when you’re ready?

Marlin Rowley wrote:

Chris (and others),

Some of you seem to know the ins and outs of wxPython REALLY well. I wish there were more example code out there that could steer us in the right direction instead of looking at the wxpython docs (with no examples).

I use the wxPython Demo, the book and the wiki to find most of the examples I want. The docs are more for knowing what arguments go where. I think there's a Google Summer of Code project that is supposed to update the wiki or the docs or both. Maybe that will help some.

I suppose we should get people to vote on what's least covered and then someone could write up the top 5 or 10 into wiki pages...but that should be a separate thread.

<snip>

2 things:

1) This will only display the rectangles AFTER rendering is complete! Even if I put a clientWindow.Refresh() call in the writeTile() function, the window doesn't show the tiles being rendered as it gets streamed in. Arrghh!!!

This sounds like something that should be in an OnPaint event handler. Unfortunately, I have yet to experiment with that part of wxPython so you'll have to wait for one of the gurus to respond.

2) ON_IDLE isn't going to work for me. I need something that will continuously draw to the screen when there is streaming activity. With ON_IDLE, my mouse pointer HAS to be in the window in order for the event to get processed. This led me to creating my own MainLoop() function but I don't know how to create that.

Lastly, I don't understand how wx.Timer can play in this.

-M

You can use a wx.Timer object that fires constantly and in it's handler, do whatever you want. Here's some general code for using a timer:

<code>
self.pollingPeriod = 10000 # 10 seconds

self.timer = wx.Timer(self)
self.timer.Start(self.pollingPeriod)
self.Bind(wx.EVT_TIMER, self.myTimerHandler, self.timer)

def myTimerHandler(self, event):
     # do something here like update your drawing
     pass

</code>

HTH

Mike

Mike Driscoll wrote:

Marlin Rowley wrote:

Chris (and others),

Some of you seem to know the ins and outs of wxPython REALLY well. I wish there were more example code out there that could steer us in the right direction instead of looking at the wxpython docs (with no examples).

I use the wxPython Demo, the book and the wiki to find most of the examples I want. The docs are more for knowing what arguments go where. I think there's a Google Summer of Code project that is supposed to update the wiki or the docs or both. Maybe that will help some.

Google doesn't accept projects that are mostly documentation so we prioritized those to the bottom of the list. Here are the projects that were accepted:

http://code.google.com/soc/2008/wxpython/about.html

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

All this information is overwhelming my mind… :frowning:

I put all the scanMR() code into a Timer event function (there goes my modularity). I’m now able to get it to “see” tiles pretty quickly without the Xlib error, BUT I can’t get the OnPaint() function to be called to update my window menus,etc… because my Timer is taking up ALL the processing!!! LOL!

Here’s what I have for the Timer:

class RenderWindow(wx.Window):
def init( self,parent,ID,pos,size ):
wx.Window.init( self,parent,ID,pos,size )
self.timer = wx.Timer(self)
self.timer.Start( 0.001 ) <<< ---------------- THIS GIVES ME PERFECT SYNC WITH STREAMING DATA, BUT AT A COST!

   # binding events
    self.Bind( wx.EVT_TIMER, self.RenderImage, self.timer )

def RenderImage( self,event ):
    ....
   # do all my tile processing here.. but what is needed for the OnPaint() function to be called as fast??
    ...

def OnPaint( self,event ):
print ‘OnPaint() called…’
dc = wx.BufferedPaintDC( self,self.buffer )

···

Date: Mon, 28 Apr 2008 12:58:40 -0700
From: Chris.Barker@noaa.gov
Subject: Re: [wxpython-users] Xlib: unexpected async reply (sequence 0x76b)!
To: wxpython-users@lists.wxwidgets.org

Marlin Rowley wrote:

Some of you seem to know the ins and outs of wxPython REALLY well. I
wish there were more example code out there that could steer us in the
right direction instead of looking at the wxpython docs (with no examples).

There is, and you’ve now been pointed to it, but you are trying to do
something pretty tricky.

scanMR( clientWindow, hostname, portNumber ):

call the writeTile function to write this tile (bitmap)

to the window.

This needs to be a wx.CallAfter call (or wx.PostEvent)

  1. ON_IDLE isn’t going to work for me.

I’ve never found it useful, but it may work if you put a WakeUpIdle in
there to keep it going.

I need something that will
continuously draw to the screen when there is streaming activity.

Lastly, I don’t understand how wx.Timer can play in this.

you set up a wx.timer for a pretty short time and each time it is fired,
it calls a function that checks to see if there is a new tile available,
and if, so, it renders it, then re-sets the timer to do it again.

You may need to put a wx.App.Yield(True) in there, so that other events
get processed too.

-Chris


Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


Make i’m yours. Create a custom banner to support your cause.

Nevermind. Start( 10 ) is fine enough to keep a good stream and the GUI updated pretty quickly… whew…

···

From: marlin_rowley@hotmail.com
To: wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] Xlib: unexpected async reply (sequence 0x76b)!
Date: Mon, 28 Apr 2008 16:32:56 -0500

All this information is overwhelming my mind… :frowning:

I put all the scanMR() code into a Timer event function (there goes my modularity). I’m now able to get it to “see” tiles pretty quickly without the Xlib error, BUT I can’t get the OnPaint() function to be called to update my window menus,etc… because my Timer is taking up ALL the processing!!! LOL!

Here’s what I have for the Timer:

class RenderWindow(wx.Window):
def init( self,parent,ID,pos,size ):
wx.Window.init( self,parent,ID,pos,size )
self.timer = wx.Timer(self)
self.timer.Start( 0.001 ) <<< ---------------- THIS GIVES ME PERFECT SYNC WITH STREAMING DATA, BUT AT A COST!

   # binding events
    self.Bind( wx.EVT_TIMER, self.RenderImage, self.timer )

def RenderImage( self,event ):
    ....
   # do all my tile processing here.. but what is needed for the OnPaint() function to be called as fast??
    ...

def OnPaint( self,event ):
print ‘OnPaint() called…’
dc = wx.BufferedPaintDC( self,self.buffer )


Date: Mon, 28 Apr 2008 12:58:40 -0700
From: Chris.Barker@noaa.gov
Subject: Re: [wxpython-users] Xlib: unexpected async reply (sequence 0x76b)!
To: wxpython-users@lists.wxwidgets.org

Marlin Rowley wrote:

Some of you seem to know the ins and outs of wxPython REALLY well. I
wish there were more example code out there that could steer us in the
right direction instead of looking at the wxpython docs (with no examples).

There is, and you’ve now been pointed to it, but you are trying to do
something pretty tricky.

scanMR( clientWindow, hostname, portNumber ):

call the writeTile function to write this tile (bitmap)

to the window.

This needs to be a wx.CallAfter call (or wx.PostEvent)

  1. ON_IDLE isn’t going to work for me.

I’ve never found it useful, but it may work if you put a WakeUpIdle in
there to keep it going.

I need something that will
continuously draw to the screen when there is streaming activity.

Lastly, I don’t understand how wx.Timer can play in this.

you set up a wx.timer for a pretty short time and each time it is fired,
it calls a function that checks to see if there is a new tile available,
and if, so, it renders it, then re-sets the timer to do it again.

You may need to put a wx.App.Yield(True) in there, so that other events
get processed too.

-Chris


Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


Make i’m yours. Create a custom banner to support your cause.


Spell a grand slam in this game where word skill meets World Series. Get in the game.

Marlin Rowley wrote:

Nevermind. Start( 10 ) is fine enough to keep a good stream and the GUI updated pretty quickly.. whew..

That's probably still more timer events than you need. The human eye can not distinguish more than 20-60 frames per second, but with a 10 ms timer delay you are going to have 100 updates per second, which will just be wasted CPU cycles.

Another approach to to consider for your application is to let your background thread determine when the data it has received thus far is at the point where another tile could be rendered and when that is true it can call some function in the GUI thread via wx.CallAfter. That function can do the rendering of the image and whatever else is needed and then call self.Refresh. That way the display is only being updated as fast as the data is arriving, with no wasted refreshes.

BTW, to answer some of you other questions, the EVT_PAINT event is sent to a window when the system senses that it needs to be refreshed (either because some other window has 'damaged' it, or because the program itself tells it that it needs to be done by calling one of the Refresh methods) and when there are no other pending events. In other words, it is a low-priority event that can be starved out if there are too many other events pending. There is also the Update method which causes the EVT_PAINT to be sent immediately if the window needs refreshed.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

So basically put:

wx.GetApp().Yield(True)

at the end of writing a tile in the body of:

def RenderImage() ?

I’ll try that.

-M

···

Date: Mon, 28 Apr 2008 14:50:59 -0700
From: Chris.Barker@noaa.gov
Subject: Re: [wxpython-users] Xlib: unexpected async reply (sequence 0x76b)!
To: wxpython-users@lists.wxwidgets.org

Marlin Rowley wrote:

Nevermind. Start( 10 ) is fine enough to keep a good stream and the GUI
updated pretty quickly… whew…

You may be able to help with:

def RenderImage( self,event ):

do all my tile processing here… but what is needed for the

OnPaint() function to be called as fast??

put:
self.Refresh()
self.Update()

here, that will force a paint.

but what you may want is:

wx.GetApp().Yield(True)

That will pause the app to clear out the event loop. This allows other
button presses, etc, to be processed.


Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


Express yourself wherever you are. Mobilize!

In a quick example I’ve tried what you said but with the

import numpy as np

pixValueList = [0,1,2,3,4,5,6,7,8,9]

width = 2

height = 5

RGB = np.zeros((width, height, 3), dtype=np.uint8)

RGB[:,:,0] = pixValueList

I get the error

ValueError: shape mismatch: objects cannot be broadcast to a single shape

How do I fill the RGB array correctly. Note that len( pixValueList ) = width * height

···

Christopher Barker Chris.Barker@noaa.gov wrote:

Robert Robert wrote:

I have a monochromatic grayscale image. So
it is not a list of tuples or r,g, b values. So actually how do I set
the data to a wx.Image. So a simple example. Let say
I have an image of
size , width 2, height 5. and the pixel values are stored as integer in
a list

pixValueList = [0,1,2,3,4,5,6,7,8,9]

First, it’s a bit odd, and inefficient, to have this in a list, you’d be
better of with the data in a string or array.array.

how do I display this image ?

I’m pretty sure wx only support RBG images to be loaded up in this way.
So, you’ll need to use another tool to convert your data to RGB. Two
options are:

  1. PIL: The Python Imaging library

It should be able to do this for you, and once you have an RBG image in
PIL, you can make a wxImage out of it:

WorkingWithImages - wxPyWiki

  1. numpy: Numerical python
    numpy provides a n-dimensional array object, and lot of tools for doing
    math with them. In this case, an RBG image is a Width X Height X 3
    array. So for the above data:

import numpy as np

create

an array for your data
RGB = np.zeros((width, height, 3), dtype=np.uint8)

fill it in: (R = G = B fr grey)

RGB[:,:,0] = pixValueList
RGB[:,:,1] = pixValueList
RGB[:,:,2] = pixValueList

scale it to 0-255:

RGB *= 255.0/MaxValue # MaxValue is the value of white in your data

#now you’ve got RBG image data. To make a wx.Image:
image = wx.EmptyImage(width,height)
image.SetData( RGB.tostring())

-Chris

Thanks in advance.

robert


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try
it now.



wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.