码迷,mamicode.com
首页 > 编程语言 > 详细

利用wxpython显示OpenCV图像

时间:2015-10-22 19:12:42      阅读:644      评论:0      收藏:0      [点我收藏+]

标签:

核心代码

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()

 

利用wxpython显示OpenCV图像

标签:

原文地址:http://www.cnblogs.com/lulu147/p/4901626.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!