wxpython ClientDC on循环

2024-09-28 21:27:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个要求显示采样视频帧使用wx.ClientDC每当一个按钮被按下。我写的代码检测到按钮按下并进入一个循环,读取帧,但不显示它。我正在用OpenCV读取帧。我不知道我错在哪里

class VideoFrame(gui.wxVideoFrame):

    def __init__(self, parent):
        self.parent = parent
        gui.wxVideoFrame.__init__(self, parent)


        self.webcam = WebcamFeed() #opencv Webcam class to feed frames.
        if not self.webcam.has_webcam():
            print ('Webcam has not been detected.')
            self.Close()

        self.STATE_RUNNING = 1
        self.STATE_CLOSING = 2
        self.state = self.STATE_RUNNING

        self.SetSize(wx.Size(1280, 720)) 

        self.dc = wx.ClientDC(self.panel)

        self.verify.Bind(wx.EVT_BUTTON, self.onVerify) #the button
        self.Bind(wx.EVT_CLOSE, self.onClose)

    def onClose(self, event):
        if not self.state == self.STATE_CLOSING:
            self.state = self.STATE_CLOSING
            self.Destroy()

    def onVerify(self, event):
        #self.verify.Enable(True)
        #i = 0
        while i<= 100:
            frame = self.webcam.get_image()#reads image successfully
            image = wx.Bitmap.FromBuffer(640, 480, frame) 
            self.dc.Clear()
            self.dc.DrawBitmap(image, 0, 0)
            #i += 1
            #print(i)

    def onEraseBackground(self, event):
        return  

Tags: imageselfeventdefnotdc按钮class