The Beardinator

Processing final uses facial recognition to let you draw a beard that moves with your face.

I used Proclipsing at first. I started out just using a simple motion tracking video mirror as described in our book. Then I switched to the popular OpenCV package for facial recognition. Eclipse did not like this for some reason, so after banging my head against a wall a few dozen times I switched back to “native” Processing.

The beard code started out as drawing straight lines, just to get the tracking right. Then making the lines grow and shrink on command. Next on to the wavy lines part of a nice long flowing beard, using curved vertices. Then a tricky bit, making the lines continue to be curved but also wave back and forth in a gentle overall sine function. And then the REALLY tricky bit, letting each hair move on its own random angle and direction so that the waving would be “realistic”.
Now, Processing could handle a lot of that for me with the push and popMatrix() and rotation/transformations, but I wanted to be able to move this to other platforms someday, maybe write an app. So that meant lots of maths. I did not love the maths, but thankfully I had help*.

After quite a bit of debugging, we also got the lines to grow and shrink correctly again, which had broken somewhere in there. And then I added a few more things – like the ability to lighten or darken the hair color, switch to a random hair color, empty the hair array to start drawing new hairs when the maximum number was already hit (I chose 200, then 300, for a maximum. More hairs than that looked like your face was being attacked by a mutant tribble). And lastly a screencap function, in case your beard was truly epic.

Then I tried to mess with it right before presenting the final, and managed to totally break it. Whyyyyy?
I tried to add some fancier code for the facial recognition and finish debugging (array reset isn’t quite right). And then nothing worked. But later that night I figured out* what on earth went wrong (mislabeled variable!) and with a sigh of relief, declared it finito.

Short hair, random color screencap
*Special thanks to Emma Persky!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s