标签:
核心代码
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()
标签:
原文地址:http://www.cnblogs.com/lulu147/p/4901626.html