While the code given so far in this chapter is sufficient for a whole face recognition system, there still needs to be a way to put the data into the system and a way to use it. Many face recognition systems for research will choose the ideal input to be text files, listing where the static image files are stored on the computer, as well as other important data, such as the true name or identity of the person, and perhaps true pixel coordinates of regions of the face (such as the ground truth of where the face and eye centers actually are). This would either be collected manually or by another face recognition system.
The ideal output would then be a text file comparing the recognition results with the ground truth, so that statistics may be obtained for comparing the face recognition system with other face recognition systems.
However, as the face recognition system in this chapter is designed for learning as well as practical fun purposes, rather than competing with the latest research methods, it is useful to have an easy-to-use GUI that allows face collection, training, and testing interactively from the webcam in real time. So this section will show you an interactive GUI that provides these features. The reader is expected to either use the GUI that comes with this book, or modify it for their own purposes, or ignore this GUI and design their own to perform the face recognition techniques discussed so far.
As we need the GUI to perform multiple tasks, let's create a set of modes or states that the GUI will have, with buttons or mouse clicks for the user to change modes:
- Startup: This state loads and initializes the data and webcam.
- Detection: This state detects faces and shows them with preprocessing, until the user clicks on the Add Person button.
- Collection: This state collects faces for the current person, until the user clicks anywhere in the window. This also shows the most recent face of each person. The user clicks either one of the existing people or the Add Person button to collect faces for different people.
- Training: In this state, the system is trained with the help of all the collected faces of all the collected people.
- Recognition: This consists of highlighting the recognized person and showing a confidence meter. The user clicks either one of the people or the Add Person button to return to mode 2 (Collection).
To quit, the user can hit the Esc key in the window at any time. Let's also add a Delete All mode that restarts a new face recognition system, and a Debug button that toggles the display of extra debug information. We can create an enumerated mode variable to show the current mode.