I've gotten a few requests to put up a tutorial for building a robotic head.
I'm assuming if you want to build a robotic head, you'll have some experience using an arduino, servos, and some other language that can interface between a webcam and the arduino. I used processing as my interface between the arduino and my webcam. I'm also using the OpenCV library for processing.
I'll describe the overarching structure behind the code to give the illusion that a robot is following a person's face. At a high level, there are only a few steps to have a webcam follow a person's face:
- Detect face. Take a look at some OpenCV examples on processing's website.
- Grab X-Y pixel coordinates of the face.
- Calculate the pixel distance between the center of the face and center of the webcam's view. In other words, you're going to take the images from the webcam, and calculate the distance between the center of that image and the center of the face.
- Write an algorithm that minimizes the distance between the webcam's center and the face's center.
- This algorithm will also control the servos.
You can download my processing code here and my arduino code is based on the code found here from letsmakerobots.
Let me know if you guys have any questions. I'll try to answer them as soon as I get a chance.
The following pictures are the first iteration: