作者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
推 Tiberius:別用 while(1), 改用 wx.Timer 吧! 11/22 23:09
推 cute0185:感謝大大指導,現在不會有當掉的問題了 11/27 09:48