Webcam + Timelapse + OpenCV
Since the start of the year, I’ve made my laptop automatically take a photo of me every minute. A while ago I made a time lapse video out of it, but used a frame averaging technique, so it’s a bit blurry, but still interesting.
The main problem is that my head is not positioned exactly in the same spot every time the photo is taken, so the average frame becomes blurry. I looked into facial recognition and found OpenCV which is a free “computer vision” library written in C++. OpenCV comes with face detection, eye detection, and all sorts of different image and video processing tools. It also has wrappers for languages such as Python, Ruby and C#, so I decided to give the Python interface a go.
Compiling it took a fair amount of work on OS X with working Python bindings, and it was completely worth it. Once OpenCV was ready to go, detecting a face was trivial. It gives you a rectangle for each face that were detected in the image.
Usually it’s pretty accurate, but when I attempted to run this through all the webcam frames collected, it would sometimes think an inanimate object was a face:
There are ways to tweak how sensitive the detection is, but I thought it would be cool to also detect my eyes. Eye detection appears to be more inaccurate, so I made it count if there are 2 eyes detected within the detected face rectangle. The white squares are detected eyes (the label says “in”) and the blue squares (“out”) are eyes detected outside the face rectangle. The eye detected on the right does creepily look like an eye!
Once a correct face is detected, the position of the face is moved to the center of the image, so that my head is always in the center for the time lapse. I filtered out any images that didn’t detect a face or if the face was too small on the screen. I also set it to only pick 10 images per day, ending up with 1280 frames. It took me a weekend to do all of this, and here’s the video:
All the data is backed up to Amazon S3 just incase the laptop dies, so I plan on continuing this project, possibly for the rest of my life! I’ll be interested to hear what other ideas you have that I can do with these images. My next plan is to do more frame-average videos similar to the first video posted.