| | |
How to display images simultaneously in wxPython?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
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.
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
•
•
•
•
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.
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
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
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.
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.
python Syntax (Toggle Plain Text)
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()
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.
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
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
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
![]() |
Other Threads in the Python Forum
- Previous Thread: Random Help Needed
- Next Thread: how do i make this repeat? >.>
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog data decimals dictionaries dictionary directory drive dynamic error examples exe file float format function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule script scrolledtext sqlite statistics stdout string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia windows write wxpython xlib






