<contens>

参考

videocapture

A win32 python extension

http://videocapture.sourceforge.net/

opencv

这个牛!

开始

使用 wxPython GUI , opencv 库:

#!/usr/bin/env python
# coding: utf-8

import wx
from opencv.cv import *
from opencv.highgui import *

class MyFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self,None,-1,'camera')
        self.SetClientSize((640,480))
        self.cap = cvCreateCameraCapture(0)
        self.Bind(wx.EVT_IDLE,self.onIdle)

    def onIdle(self,event):
        img = cvQueryFrame(self.cap)
        self.displayImage(img)
        event.RequestMore()

    def displayImage(self,img,offset=(0,0)):
        bitmap = wx.BitmapFromBuffer(img.width,img.height,img.imageData)
        dc = wx.ClientDC(self)
        dc.DrawBitmap(bitmap,offset[0],offset[1],False)

if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame()
    frame.Show(True)
    app.MainLoop()