作者cute0185 (上官袭人)
看板Python
标题[问题] Python 控制 Webcam
时间Thu Nov 22 10:49:31 2007
目前想用Python 来写一个显示 Webcam画面的程式
利用了VideoCapture(
http://videocapture.sourceforge.net/)
来控制Webcam取得视讯画面,然後将画面连续显示在wx.Panel中
不过只能持续5秒左右,之後程式就当了,小弟不才
不知道有没有人可以给个指教,谢谢
以下为程式码
import wx, time
from VideoCapture import Device
class Panel1(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
wx.EVT_PAINT(self, self.on_paint)
def on_paint(self, event=None):
webcam = Device()
dc = wx.PaintDC(self)
dc.Clear()
while(1):
pil = webcam.getImage()
image = wx.EmptyImage(pil.size[0], pil.size[1])
image.SetData(pil.convert('RGB').tostring())
dc.DrawBitmap(wx.BitmapFromImage(image), (350-pil.size[0])/2, 1,
True)
time.sleep(0.5)
app = wx.PySimpleApp()
frame1 = wx.Frame(None, -1, "Webcam test", size=(350, 300))
panel1 = Panel1(frame1, -1)
frame1.Show(True)
app.MainLoop()
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.130.33.216
1F:推 Tiberius:别用 while(1), 改用 wx.Timer 吧! 11/22 23:09
2F:推 cute0185:感谢大大指导,现在不会有当掉的问题了 11/27 09:48