Let's look at two approaches to integrating face tracking and swapping into Cameo. The first approach uses a single camera feed and swaps face rectangles found within this camera feed. The second approach uses two camera feeds and copies face rectangles from one camera feed to the other.
For now, we will limit ourselves to manipulating faces as a whole and not subelements such as eyes. However, you could modify the code to swap only eyes, for example. If you try this, be careful to check that the relevant subrectangles of the face are not None
.
For the single-camera version, the modifications are quite straightforward. On initialization of Cameo
, we create a FaceTracker
and a Boolean variable indicating whether debug rectangles should be drawn for the FaceTracker
. The Boolean is toggled in onKeypress()
in response to the X key. As part of the main loop in run()
, we update our FaceTracker
with the current frame. Then, the resulting...