- OpenCV 4 with Python Blueprints
- Dr. Menua Gevorgyan Arsen Mamikonyan Michael Beyeler
- 314字
- 2021-06-24 16:50:00
Mapping the GUI base class
The FilterLayout GUI will be based on a generic, plain layout class called BaseLayout, which we will be able to use in subsequent chapters as well.
The BaseLayout class is designed as an abstract base class. You can think of this class as a blueprint or recipe that will apply to all the layouts that we are yet to design, that is, a skeleton class that will serve as the backbone for all of our future GUI code.
We start the file by importing the packages that we will use—the wxPython module, which we use to create the GUI; numpy, which we use to do matrix manipulations; and OpenCV (of course):
import numpy as np
import wx
import cv2
The class is designed to be derived from the blueprint or skeleton, that is, the wx.Frame class:
class BaseLayout(wx.Frame):
Later on, when we write our own custom layout (FilterLayout), we will use the same notation to specify that the class is based on the BaseLayout blueprint (or skeleton) class, for example, in class FilterLayout(BaseLayout):. But for now, let's focus on the BaseLayout class.
An abstract class has at least one abstract method. We are going to make the method abstract by ensuring that if the method stays unimplemented, the application will not run and we throw an exception:
class BaseLayout(wx.Frame):
...
...
...
def process_frame(self, frame_rgb: np.ndarray) -> np.ndarray:
"""Process the frame of the camera (or other capture device)
:param frame_rgb: Image to process in rgb format, of shape (H, W, 3)
:return: Processed image in rgb format, of shape (H, W, 3)
"""
raise NotImplementedError()
Then, any class that is derived from it, such as FilterLayout, must specify a full implementation of that method. This will allow us to create custom layouts, as you will see in a moment.
But first, let's proceed to the GUI constructor.
- Vue.js設(shè)計(jì)與實(shí)現(xiàn)
- Design Principles for Process:driven Architectures Using Oracle BPM and SOA Suite 12c
- 深入淺出Java虛擬機(jī):JVM原理與實(shí)戰(zhàn)
- Visual FoxPro 程序設(shè)計(jì)
- 機(jī)器人Python青少年編程開發(fā)實(shí)例
- Learn Scala Programming
- 單片機(jī)應(yīng)用技術(shù)
- 小程序開發(fā)原理與實(shí)戰(zhàn)
- 深入淺出Serverless:技術(shù)原理與應(yīng)用實(shí)踐
- HTML5與CSS3基礎(chǔ)教程(第8版)
- Go語言入門經(jīng)典
- Neo4j 3.x入門經(jīng)典
- DevOps 精要:業(yè)務(wù)視角
- Professional JavaScript
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)(Windows 7+Office 2010)