943,879 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 2465
  • Python RSS
Feb 23rd, 2009
0

How to display images simultaneously in wxPython?

Expand Post »
Hi, I found a code that displays multiple images but you have to supply its filename first before it can access it. Is there a way to display an image as soon as it is captured by the camera? The GUI that I am creating is going to be interfaced with a camera and I need to display the captured images as they arrive. Can someone please lend me a hand here? Big thanks and looking forward to learn from you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karenmaye is offline Offline
11 posts
since Feb 2009
Feb 25th, 2009
0

Re: How to display images simultaneously in wxPython?

Click to Expand / Collapse  Quote originally posted by karenmaye ...
Hi, I found a code that displays multiple images but you have to supply its filename first before it can access it. Is there a way to display an image as soon as it is captured by the camera? The GUI that I am creating is going to be interfaced with a camera and I need to display the captured images as they arrive. Can someone please lend me a hand here? Big thanks and looking forward to learn from you.
Your question is a little confusing. When I display an image, I make it into a wx.Image() object or a wx.Bitmap() object. It doesn't really matter whether it came from a file or not.

So ... can you post your code to help clarify what the issue is?

Jeff

P.S. Also, check out the docs for the Image and Bitmap classes:

http://docs.wxwidgets.org/stable/wx_...e.html#wximage
http://docs.wxwidgets.org/stable/wx_....html#wxbitmap
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006
Feb 26th, 2009
0

Re: How to display images simultaneously in wxPython?

Here's the code:

import wx
import os


class MainWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,"Agent-Based Model of Residential Development", size = (640, 480))
self.panel = wx.Panel(self,-1)
self.imageFile = "C:/Documents and Settings/12345/My Documents/Files/Misc/everythingisshit.jpg" # provide a diff file name in same directory/path
self.bmp = wx.Image(self.imageFile,wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
self.bmp.bitmap = wx.StaticBitmap(self.panel, -1, self.bmp)
#self.bmp.bitmap.GetSize()
#self.SetSize(self.bmp.bitmap.GetSize())
#self.Center()

button42 = wx.Button(self.panel, -1, "Read", pos=(540,50))
self.Bind(wx.EVT_BUTTON, self.OnRead ,button42)

def OnRead(self,event):
self.imageFile1="D:/Say cheese!/vanity/iuhf.jpg" # you have to provide a diff image file name
self.bmp = wx.Image(self.imageFile1,wx.BITMAP_TYPE_JPEG).ConvertToBitmap()

self.obj = wx.StaticBitmap(self.panel, -1, self.bmp)
#self.obj.GetSize()
#self.SetSize(self.obj.GetSize())
#self.Center()
self.obj.Refresh()

if __name__ == "__main__":
app = wx.PySimpleApp()
MainWindow().Show()
app.MainLoop()

This displays the image after pressing the Read button but the first image still stays there. The new image just overlaps the previous one. What I want to do is to simultaneously display the image as it is being saved in a folder. How can I do this? Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karenmaye is offline Offline
11 posts
since Feb 2009
Feb 26th, 2009
0

Re: How to display images simultaneously in wxPython?

python Syntax (Toggle Plain Text)
  1. import wx
  2. import os
  3.  
  4.  
  5. class MainWindow(wx.Frame):
  6. def __init__(self):
  7. wx.Frame.__init__(self,None,-1,"Agent-Based Model of Residential Development", size = (640, 480))
  8. self.panel = wx.Panel(self,-1)
  9. self.imageFile = "C:/Documents and Settings/12345/My Documents/Files/Misc/everythingisshit.jpg" # provide a diff file name in same directory/path
  10. self.bmp = wx.Image(self.imageFile,wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
  11. self.bmp.bitmap = wx.StaticBitmap(self.panel, -1, self.bmp)
  12. #self.bmp.bitmap.GetSize()
  13. #self.SetSize(self.bmp.bitmap.GetSize())
  14. #self.Center()
  15.  
  16. button42 = wx.Button(self.panel, -1, "Read", pos=(540,50))
  17. self.Bind(wx.EVT_BUTTON, self.OnRead ,button42)
  18.  
  19. def OnRead(self,event):
  20. self.imageFile1="D:/Say cheese!/vanity/iuhf.jpg" # you have to provide a diff image file name
  21. self.bmp = wx.Image(self.imageFile1,wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
  22.  
  23. self.obj = wx.StaticBitmap(self.panel, -1, self.bmp)
  24. #self.obj.GetSize()
  25. #self.SetSize(self.obj.GetSize())
  26. #self.Center()
  27. self.obj.Refresh()
  28.  
  29. if __name__ == "__main__":
  30. app = wx.PySimpleApp()
  31. MainWindow().Show()
  32. app.MainLoop()
Re-posted with code tags.
Click to Expand / Collapse  Quote originally posted by karenmaye ...
Here's the code:
Karen,

Please make use of code tags when posting in this forum. In order to use them, you must simply wrap your code as such:
[code=python]
# Your code goes in here
[/code]

Oh also, try not to use curse words (as per forum rules), even if they are inadvertently placed in your code
Last edited by jlm699; Feb 26th, 2009 at 9:39 am.
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008
Feb 26th, 2009
0

Re: How to display images simultaneously in wxPython?

OK, that makes sense. Here's what will happen:

In lines 9-10 of your current code, you read in an image from a file.

Instead, you will call your camera's "take a picture" method. It will return either (a) a bitmap, or (b) some kind of proprietary image, as an object.

If (a) then proceed directly to displaying the bitmap as in line 11.

If (b) then you'll need to poke around in the camera's module to find out how to convert the image into a bitmap. Then display as in line 11.

Hope it helps,
Jeff
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Random Help Needed
Next Thread in Python Forum Timeline: how do i make this repeat? >.>





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC