栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

任何快速的Python GUI均可显示Camera的实时图像

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

任何快速的Python GUI均可显示Camera的实时图像

这是将执行此操作的wxPython代码…

import wxfrom PIL import ImageSIZE = (640, 480)def get_image():    # Put your pre 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 bitmapclass 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()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/407429.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号