当前位置: 首页>>代码示例>>Python>>正文


Python FigureCanvasTkAgg.flush_events方法代码示例

本文整理汇总了Python中matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.flush_events方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasTkAgg.flush_events方法的具体用法?Python FigureCanvasTkAgg.flush_events怎么用?Python FigureCanvasTkAgg.flush_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backends.backend_tkagg.FigureCanvasTkAgg的用法示例。


在下文中一共展示了FigureCanvasTkAgg.flush_events方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Application

# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import flush_events [as 别名]

#.........这里部分代码省略.........
        self.currentFrame = 0


    def createFrames(self):
        top = self.winfo_toplevel()
        top.rowconfigure(0, weight=1)
        top.columnconfigure(0, weight=1)

        self.rowconfigure(0, minsize=200, weight=1)
        self.rowconfigure(1, minsize=200, weight=1)
        self.columnconfigure(0, minsize=10,  weight=0)
        self.columnconfigure(1, minsize=400, weight=1)

        self.toolbarFrame   = tk.LabelFrame(self, text='Toolbar')
        self.originalFrame  = tk.LabelFrame(self, text='Original')
        self.processedFrame = tk.LabelFrame(self, text='Processed')

        self.toolbarFrame.grid  (row=0, column=0, rowspan=2, sticky=tk.N+tk.S+tk.E+tk.W)
        self.originalFrame.grid (row=0, column=1, sticky=tk.N+tk.S+tk.E+tk.W)
        self.processedFrame.grid(row=1, column=1, sticky=tk.N+tk.S+tk.E+tk.W)

        self.createToolbar(self.toolbarFrame)
        self.createOriginalFrame(self.originalFrame)
        self.createProcessedFrame(self.processedFrame)


    def createToolbar(self, parentFrame):
        self.quitButton  = tk.Button(parentFrame, text='Quit',          command=self.quit)
        self.startButton = tk.Button(parentFrame, text='Start capture', command=self.start)
        self.stopButton  = tk.Button(parentFrame, text='Stop capture',  command=self.stop)

        self.startButton.grid(row=0,sticky=tk.N+tk.S+tk.E+tk.W)
        self.stopButton.grid (row=1,sticky=tk.N+tk.S+tk.E+tk.W)
        self.quitButton.grid (row=2,sticky=tk.S+tk.E+tk.W)

        parentFrame.rowconfigure(2, weight=1)

    def createOriginalFrame(self, parentFrame):
        self.originalFigure = plt.figure(figsize=(5,3))
        self.originalAxes = self.originalFigure.add_subplot(111)
        self.originalAxes.set_xticklabels([])
        self.originalAxes.set_yticklabels([])
        self.originalCanvas = FigureCanvasTkAgg(self.originalFigure, master=parentFrame)
        self.originalCanvas.show()
        self.originalCanvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
        

    def createProcessedFrame(self, parentFrame):
        self.processedFigure = plt.figure(figsize=(5,3))
        self.processedAxes = self.processedFigure.add_subplot(111)
        self.processedAxes.set_xticklabels([])
        self.processedAxes.set_yticklabels([])
        self.processedCanvas = FigureCanvasTkAgg(self.processedFigure, master=parentFrame)
        self.processedCanvas.show()
        self.processedCanvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
        

    def start(self):
        if self.cap is None:
            self.cap = cv2.VideoCapture(0)
            print 'created video capture object'
            self.currentFrame = 0
            self.processVideo()

    def stop(self):
        if self.cap is not None:
            self.cap.release()
            self.cap = None
            print 'released video capture object'

    def processVideo(self):
        if self.cap is not None:
            #print 'process video frame %d' % self.currentFrame

            _, image_original_bgr = self.cap.read()

            b,g,r = cv2.split(image_original_bgr)
            image_original_rgb = cv2.merge([r,g,b])

            if self.currentFrame == 0:
                self.originalImageAxes = self.originalAxes.imshow(image_original_rgb)
            else:
                self.originalImageAxes.set_data(image_original_rgb)

            if self.currentFrame == 0:
                self.processedImageAxes = self.processedAxes.imshow(image_original_rgb)
            else:
                self.processedImageAxes.set_data(image_original_rgb)

            self.updateFigures()

            self.currentFrame = self.currentFrame + 1
            self.after(1, self.processVideo)
    
    def updateFigures(self):
        self.originalCanvas.draw()
        self.originalCanvas.flush_events()

        self.processedCanvas.draw()
        self.processedCanvas.flush_events()
开发者ID:markusmorawitz77,项目名称:PythonImageProcessing,代码行数:104,代码来源:histogram_tk001.py


注:本文中的matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.flush_events方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。