Bag - 0



Make A Snapchat lens for your webcam?

Ever use a Snapchat lens and just wonder “How’d they do that?”. Well, even if not, I’m going to take a look at some of the face tracking and computer vision technologies that ma...

DIY Retro Style Digital Camera

Cameras have been around for centuries. But since the birth of digital, many of the old film cameras have just been tossed aside. Let’s give these amazing pieces of technology a second chance by ...

Turn An Old RC Car Into A Ping Pong Ball Blaster!

Ok, let’s be honest. Is there any real need for a ping pong ball machine gun? No. But then again, is there any real need for a water gun? No. Both are definitely great for pranking friends or to ...

Simple Voice Controlled Home Automation

Ever wanted to make your home automatically do what you ask it? In this guide, I make a cheap home automation system that you can control with your phone and/or your voice! This is just an extremely ba...

How To Make An Android App In 7 Minutes!

When it comes to being a good tinkerer, a great tool to have in your arsenal is the ability to quickly mach up a mobile app. But programming an app from scratch is very time consuming. So I’m goi...

Step 1

Install Software

In order to track faces using a webcam, you need to install “Computer Vision” software. There’s an easy to use python-based software called “SimpleCV” that is free to install on Windows, Mac and Linux. My instructions below are for how to install it on a Raspberry Pi.

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install ipython python-opencv python-scipy

sudo pip install

sudo pip install pyparsing svgwrite

sudo modprobe bcm2835-v4l2

Step 2

Writing The Program

Here’s some sample python code that I used to track a mustache onto faces that the webcam recognizes:


from SimpleCV import *
display = Display()
cam = Camera()
mustache = Image("stache4.png")
mask = mustache.hueDistance(color=Color.GREEN).binarize()
result = (mask.invert() - mustache)

face_cascade = HaarCascade("face.xml")
nose_cascade = HaarCascade("nose.xml")

while display.isNotDone():
 image = cam.getImage().flipHorizontal()
 faces = image.findHaarFeatures(face_cascade)
 if faces:
 faces = faces.sortArea()
 face = faces[-1]
 myFace = face.crop()
 noses = myFace.findHaarFeatures(nose_cascade)
 if noses:
 noses = noses.sortArea()
 nose = noses[0]
 xf = face.x - (face.width()/2)
 yf = face.y - (face.height()/2)
 xm = nose.x - (nose.width()/2)
 ym = nose.y - (nose.width()/2)

xstache = xf+xm-(mustache.width/2)+(nose.width()/2)
 ystache = yf+ym+(2*nose.height()/3)
 image = image.blit(mustache,pos=(xstache,ystache), mask=mask.invert())