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()
  • 相关阅读:
    LIN总线学习-总线逻辑
    使用万用表测量CAN总线电压及实际电压与逻辑电瓶关系
    汽车网络和控制单元的安全威胁研究
    [CANopen] SDO的命令字
    新起点,新开始
    Git Commands
    Obsessive String
    The E-pang Palace
    最长递增子序列(LIS)
    Valid Sets
  • 原文地址:https://www.cnblogs.com/lulu147/p/4901626.html
Copyright © 2011-2022 走看看