Note that there are some explanatory texts on larger screens.

plurals
  1. POFlicker with wxpython displaying webcam video
    primarykey
    data
    text
    <p>I am new to python. I am trying to write a motion detection app. Currently, I am trying to get the webcam video to display on the screen. Current code right now has no flicker at first, but after any resizing, the flicker will come back. Any clue? Also, why doesn't it work without self.Refresh() in the timer event, isn't paint event always happening unless the frame is minimized? Thanks in advance. </p> <pre><code>import wx import cv class LiveFrame(wx.Frame): fps = 30 def __init__(self, parent): wx.Frame.__init__(self, parent, -1, title="Live Camera Feed") self.SetDoubleBuffered(True) self.capture = None self.bmp = None #self.displayPanel = wx.Panel(self,-1) #set up camaera init self.capture = cv.CaptureFromCAM(0) frame = cv.QueryFrame(self.capture) if frame: cv.CvtColor(frame,frame,cv.CV_BGR2RGB) self.bmp = wx.BitmapFromBuffer(frame.width,frame.height,frame.tostring()) self.SetSize((frame.width,frame.height)) self.displayPanel = wx.Panel(self,-1) self.fpstimer = wx.Timer(self) self.fpstimer.Start(1000/self.fps) self.Bind(wx.EVT_TIMER, self.onNextFrame, self.fpstimer) self.Bind(wx.EVT_PAINT, self.onPaint) self.Show(True) def updateVideo(self): frame = cv.QueryFrame(self.capture) if frame: cv.CvtColor(frame,frame,cv.CV_BGR2RGB) self.bmp.CopyFromBuffer(frame.tostring()) self.Refresh() def onNextFrame(self,evt): self.updateVideo() #self.Refresh() evt.Skip() def onPaint(self,evt): #if self.bmp: wx.BufferedPaintDC(self.displayPanel, self.bmp) evt.Skip() if __name__=="__main__": app = wx.App() app.RestoreStdio() LiveFrame(None) app.MainLoop() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload