zoukankan      html  css  js  c++  java
  • 利用wxpython显示OpenCV图像

    核心代码

    import wx, cv2
    import numpy as np
    
    # Start with a numpy array style image I'll call "source"
    
    # convert the colorspace to RGB from cv2 standard BGR, ensure input is uint8
    img = cv2.cvtColor(np.uint8(source), cv2.cv.CV_BGR2RGB) 
    
    # get the height and width of the source image for buffer construction
    h, w = img.shape[:2]
    
    # make a wx style bitmap using the buffer converter
    wxbmp = wx.BitmapFromBuffer(w, h, img)
    
    # Example of how to use this to set a static bitmap element called "bitmap_1"
    self.bitmap_1.SetBitmap(wxbmp)

     实例程序

    import wx, cv2
    import numpy as np
    
    class Frame(wx.Frame):
        def __init__(self,parent=None,id=-1,pos=wx.DefaultPosition,title="Hello,wxPython!"):
            source = cv2.imread('./6.jpg', cv2.IMREAD_COLOR)    
            img = cv2.cvtColor(np.uint8(source), cv2.cv.CV_BGR2RGB) 
            h, w = img.shape[:2]
            wxbmp = wx.BitmapFromBuffer(w, h, img)
            size = wxbmp.GetWidth(),wxbmp.GetHeight()
            wx.Frame.__init__(self,parent,id,title,pos,size)
            wx.StaticBitmap(parent=self,bitmap=wxbmp)
    
    class App(wx.App):
        def OnInit(self):
            self.frame = Frame()
            self.frame.Show()
            self.SetTopWindow(self.frame)
            return True
    
    def main():
        app = App()
        app.MainLoop()
    
    if __name__ == "__main__":
        main()
  • 相关阅读:
    React初步学习-利用React构建个人博客
    React入门介绍(2)- React Component-React组件
    React入门介绍(1)-ReactDOM.render()等基础
    (3)Gojs model简介
    javascript脚本的延时加载
    javascript中的this作用域详解
    mongodb命令
    vim
    关于格式转换
    公告栏添加时钟
  • 原文地址:https://www.cnblogs.com/lulu147/p/4901626.html
Copyright © 2011-2022 走看看