The following example pre works fine for me under OS X, but I’ve had tiny
surprises with wx across platforms. It is nearly the same pre, the difference
is that the result from
cvtColoris reassigned, and a subclass of
wx.Panel
(which is the important part) was added.
import wximport cv, cv2class ShowCapture(wx.Panel): def __init__(self, parent, capture, fps=15): wx.Panel.__init__(self, parent) self.capture = capture ret, frame = self.capture.read() height, width = frame.shape[:2] parent.SetSize((width, height)) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) self.bmp = wx.BitmapFromBuffer(width, height, frame) self.timer = wx.Timer(self) self.timer.Start(1000./fps) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_TIMER, self.Nextframe) def onPaint(self, evt): dc = wx.BufferedPaintDC(self) dc.DrawBitmap(self.bmp, 0, 0) def Nextframe(self, event): ret, frame = self.capture.read() if ret: frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) self.bmp.CopyFromBuffer(frame) self.Refresh()capture = cv2.VideoCapture(0)capture.set(cv.CV_CAP_PROP_frame_WIDTH, 320)capture.set(cv.CV_CAP_PROP_frame_HEIGHT, 240)app = wx.App()frame = wx.frame(None)cap = ShowCapture(frame, capture)frame.Show()app.MainLoop()



