python相机拍照显示_任何快速的Python GUI来显示Camera的实时图像

这是

wxPython代码,它将做到这一点……

import wx

from PIL import Image

SIZE = (640, 480)

def get_image():

# Put your code here to return a PIL image from the camera.

return Image.new('L', SIZE)

def pil_to_wx(image):

width, height = image.size

buffer = image.convert('RGB').tostring()

bitmap = wx.BitmapFromBuffer(width, height, buffer)

return bitmap

class Panel(wx.Panel):

def __init__(self, parent):

super(Panel, self).__init__(parent, -1)

self.SetSize(SIZE)

self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)

self.Bind(wx.EVT_PAINT, self.on_paint)

self.update()

def update(self):

self.Refresh()

self.Update()

wx.CallLater(15, self.update)

def create_bitmap(self):

image = get_image()

bitmap = pil_to_wx(image)

return bitmap

def on_paint(self, event):

bitmap = self.create_bitmap()

dc = wx.AutoBufferedPaintDC(self)

dc.DrawBitmap(bitmap, 0, 0)

class Frame(wx.Frame):

def __init__(self):

style = wx.DEFAULT_FRAME_STYLE & ~wx.RESIZE_BORDER & ~wx.MAXIMIZE_BOX

super(Frame, self).__init__(None, -1, 'Camera Viewer', style=style)

panel = Panel(self)

self.Fit()

def main():

app = wx.PySimpleApp()

frame = Frame()

frame.Center()

frame.Show()

app.MainLoop()

if __name__ == '__main__':

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值