Skip to content

My Face Tracking Robot

April 26, 2012

I’ve been playing with the OpenCV (Computer Vision) library for Python in my spare time, and it is pretty fun. It opens up a whole new world of possibilities. Now I can work on motion detection, facial recognition, sentry guns, etc.

Previously, I rigged up a miniature motion-controlled turret using 9g micro servos, cardboard and duct tape.
This time, I got a little more serious and used MG-995 servos and better hardware. The arduino software works exactly the same however, so I could just plug it right in.

That’s cool and all, but I want it to track people or track faces and follow them automatically. So… I mounted a webcam on top of my device and I wrote up some quick arduino code that listens for signals through the serial/USB port and moves it in the appropriate direction.



All the face tracking goodness will happen on the laptop then send signals to the arduino which will then rotate the pair of servos accordingly. Sounds like a plan!

Now, I made 2 different versions of the arduino code and 2 different versions of the python code because I wasn’t sure what would work better.
Face detection requires Haar cascades which require training. For your information, I didn’t need to train my program, I just used cascade files that were available to me. (Already includes full body, frontal face, profile face, upper body, lower body, etc.) Without further training, it has difficulty detecting tilted faces, sideways faces, and upside-down faces.

So I wrote another version that only detects a face initially, then keeps running a template match with the first matched face. This finds the segment in the screen that most closely resembles the face. This now works with upside-down faces, but doesn’t work well with shrinking faces or expanding faces (when you move too close or too far from the camera).

As for the arduino code, I made one that just takes a simple 0 for reset and 1-4 to move x angles up,right,down,left. I also made another one that takes [x-coordinate]x[y-coordinate]y and jumps the servos to that destination.

What I find works best is the pure face detection + directional arduino code.

See it in action!

You can download the source code here:
https://github.com/cranklin/Face-Tracking-Robot

Enjoy!

From → Hacks

16 Comments
  1. Do you have the include files for this as well? I assume it is the sentry python files that I would be using?

    • Hi, for this example, I was using:
      sentrygun2.py
      pan_tilt_serial.ino

      Is that what you were asking?

  2. Hey good work man, just curious How about using camshift instead of template matching and in case if face goes out of the screen do a face track again and then switch to camshift. Well i’m not that sure of the speed factors though.. !!

    • Thanks abelpaul. I haven’t tried camshift, but I’ll experiment with it. Thank you for the heads up. I’m looking for better ways to detect faces.

  3. Rob permalink

    What kind of equipment would you need to create one of these? And also, would it be possible to create some sort of robot arm for this face tracker to sit on top, so it can do heights?

  4. Hi there! Your site is running lagging in my situation, that consumed just like a minute or two to
    actually load up, I do not know if it is just simply me
    or perhaps your web site although google performed fine for me.

    Nevertheless, Thanks for publishing such type of beautiful blog post.

    I think it really has already been really beneficial to individual who actually
    visit here. I have to state that you have done wonderful work with this and additionally hope to see
    many more amazing content from you. I have got your site book marked to see blogs you post.

  5. I’m not sure where you are getting your information, but great topic.
    I needs to spend some time learning more or understanding more.
    Thanks for fantastic information I was looking for this info for my
    mission.

  6. Hey! Your website is running slow for me, this consumed sort of a
    moment to reload, I personally dont know whether it is just simply me or your
    web site however twitter performed acceptable
    for me. Well, Thanks for writing a remarkably beautiful article.

    I believe it has been totally beneficial to visitor who seem
    to visit here. I’m hoping I’ll be able to find a lot more awesome content
    and I also really should complement by telling you’ve done
    amazing job. Soon after viewing the content,
    I have book-marked your site.

  7. Hurrah! Finally I got a blog from where I be able to really get useful information concerning my study and knowledge.

  8. Hello! Your websites are loading lagging , that consumed sort of a moment to reload, I really do
    not know if it is just simply me or your web-site
    however twitter worked fine for me. Nevertheless, I appreciate you for placing such a awesome articles.
    Everyone who discovered this site really should have found this article absolutely helpful.

    I really hope I’ll be able to get a lot more remarkable information and I also really should compliment simply by saying you’ve done
    fantastic work. To obtain additional knowledge from articles that you post, I actually
    have bookmarked this page.

  9. Stretching oover 72,000 ha in the northern part of Sichuan Province, the jagged Jiuzhaigou valley reaches a height of more than 4,800 m, thus comprising a series of diverse forest ecosystems.

    Its superb landscapes are particularly interesting
    for their series of narrow conic karst land forms and spectacular
    waterfalls. Some 140 bird species also inhabit the valley,
    as well as a number of endangered plant and annimal species, including the giant panda and
    the Sihuan takin.

  10. Hey there, You have done a fantastic job. I will definitely digg it and personally suggest to my
    friends. I’m confident they’ll be benefited from this web site.

  11. Thanks for publishing this awesome article. I’m a long time reader but I’ve never been compelled to leave a comment.
    I subscribed to your blog and shared this on my Twitter.
    Thanks again for this great post!

  12. Good way of explaining, and nice piece of writing to
    get information about my presentation subject, which i
    am going to present in academy.

  13. This is a topic that’s near tto my heart… Many thanks!
    Exactly where are ypur contact details though?

Trackbacks & Pingbacks

  1. Artificial Intelligence Applied to Your Drone | cranklin.com

Leave a reply to www.gta5mac.com Cancel reply