Augmenting the basic layout

The creation of the layout is again deferred to a method called augment_layout. We keep the layout as simple as possible. We create a panel for the acquired video frame and draw a row of buttons below it.

The idea is to then click one of the six radio buttons to indicate which facial expression you are trying to record, then place your head within the bounding box, and click the Take Snapshot button.

So, let's have a look at how to build the six buttons, and correctly place them on a wx.Panel object. The code for this is shown in the following block:

    def augment_layout(self):
pnl2 = wx.Panel(self, -1)
self.neutral = wx.RadioButton(pnl2, -1, 'neutral', (10, 10),
style=wx.RB_GROUP)
self.happy = wx.RadioButton(pnl2, -1, 'happy')
self.sad = wx.RadioButton(pnl2, -1, 'sad')
self.surprised = wx.RadioButton(pnl2, -1, 'surprised')
self.angry = wx.RadioButton(pnl2, -1, 'angry')
self.disgusted = wx.RadioButton(pnl2, -1, 'disgusted')
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
hbox2.Add(self.neutral, 1)
hbox2.Add(self.happy, 1)
hbox2.Add(self.sad, 1)
hbox2.Add(self.surprised, 1)
hbox2.Add(self.angry, 1)
hbox2.Add(self.disgusted, 1)
pnl2.SetSizer(hbox2)

You can see that even if there is a lot of code, what we wrote is mostly repetitive. We create a RadioButton for each emotion and add the button to a pnl2 panel.

The Take Snapshot button is placed below the radio buttons and will bind to the _on_snapshot method, as follows:

        # create horizontal layout with single snapshot button
pnl3 = wx.Panel(self, -1)
self.snapshot = wx.Button(pnl3, -1, 'Take Snapshot')
self.Bind(wx.EVT_BUTTON, self._on_snapshot, self.snapshot)
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
hbox3.Add(self.snapshot, 1)
pnl3.SetSizer(hbox3)

As the comment suggests, we created a new panel and added a regular button with the Take Snapshot label. The important part is that we bind the click on the button to the self._on_snapshot method, which will process each captured image once we click on the Take Snapshot button.

The layout will look like the following screenshot:

To make these changes take effect, the created panels need to be added to the list of existing panels, like this:

        # arrange all horizontal layouts vertically
self.panels_vertical.Add(pnl2, flag=wx.EXPAND | wx.BOTTOM,
border=1)
self.panels_vertical.Add(pnl3, flag=wx.EXPAND | wx.BOTTOM,
border=1)

The rest of the visualization pipeline is handled by the BaseLayout class.

Now, let's see how we add boundary boxes to the faces once they appear in the video capture, using the process_frame method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.24.60