You are on page 1of 7

instructables

Face Tracking Pan-Tilt Camera

by FlorenceC6

A camera pan-and-tilt gimbal that is capable of tracking faces using computer vision and machine training so it can
follow you around as you film or vlog. This way your face is always the centre of the action!

You can also train this gimbal to follow not only human faces but also objects, pets, food, or anything you can
imagine by using different training data.

(Sorry for the potato quality of the MacBook camera)

Face Tracking Pan-Tilt Camera: Page 1


Step 1: Materials

(2) Servos

(1) Arduino Uno

(1) Jumper cables

3D print one

or buy one http://www.ebay.ca/itm/Pan-Tilt-Camera-Servo-Gimb... (includes the servos)

or make one of your own using scrap wood pieces and glue

Step 2: Installing Python

If you have programmed in Python (2.7) before, text editor and terminal. Most of the time, I just use
you can skip this step. Sublime Text and Terminal (built-in command line
tool for a Mac). But, if you've never programmed or
The language I used for the programs that track the used Python before, I recommend starting with a
faces and send the coordinates to the Arduino is simple free IDE like WingIDE.
Python so it must be installed in your computer to be
able to run the code. My code uses Python 2.7 so download that from
here:
I personally use PyCharm as my main python IDE but https://www.python.org/downloads/release/python-2...
you can use other IDE's like WingIDE, or just use a

Face Tracking Pan-Tilt Camera: Page 2


Step 3: Installing OpenCV and NumPy

If you already have OpenCV and NumPy installed below.


in your computer you can skip this step.
import cv2
The libraries I am using are OpenCV and NumPy so
both libraries must be installed in your computer. If you do not get any error messages when you run it,
OpenCV is an open-sourced computer vision library then you have installed it successfully
used to find faces in still images. I've adapted my
code to work on frames of a live video. While, NumPy To install NumPy, open your command line tool
is a powerful numeric calculations library for Python. (Terminal for Mac/Linux users and Command Prompt
for Windows users) and type the following
For Windows users install OpenCV by following this
guide: pip install numpy
http://docs.opencv.org/3.2.0/d5/de5/tutorial_py_s...
Pip is a package that comes when you install Python
For Mac users I often had trouble installing it the way in your computer so it works cross-platform.
OpenCV recommended so I use homebrew to install
it. Follow this set of instructions on how to install Similarly, if you want to check if NumPy has been
homebrew and OpenCV: installed successfully, run the following snippet of
http://www.pyimagesearch.com/2016/12/19/install-o... code below:

Installing OpenCV can be a hit-or-miss sometimes, import numpy


so test if you have OpenCV using the snippet of code

Step 4: Install ArduinoIDE

If you already have ArduinoIDE installed in your computer you can skip this step.

You can download the ArduinoIDE for the Arduino website: https://www.arduino.cc/en/Main/Software

Face Tracking Pan-Tilt Camera: Page 3


Step 5: Wiring the Servos

The wiring for this project is pretty straight forward. Follow the diagram above.

Face Tracking Pan-Tilt Camera: Page 4


Step 6: Printing the Camera Gimbal

You can 3d print this camera gimbal designed by Jake King:

http://www.thingiverse.com/thing:71492

Step 7: Run the Code

You can download the code from my Github. I will Then , compile and upload the Arduino sketch.
update this as I continue to improve the code.
To exit the video capture mode, go to the screen that
https://github.com/raptor16/FacialRecognitionCamer.. is running the video capture -- Python IDLE -- and hit
. "q" to quit.

First run the main.py using your Python IDE

Face Tracking Pan-Tilt Camera: Page 5


Step 8: Calibrating the Camera

Once you run the code, you will get two prompts. One is the average distance of the person the track from the
camera and the other is the field of view of the camera.

Face Tracking Pan-Tilt Camera: Page 6


Step 9: More...

Change the training data, so if you want to film your much the same steps since I use a Mac and
cat for example, copy and paste the pictures of your Raspberry Pis are computers that run on Linux. Now,
cat to the training folder and the camera will be you'll have a more compact camera setup.
tracking your cat. You can learn more about training
the HaarCascade here: If you want to improve the system you can also try
http://memememememememe.me/post/training-haar- playing with the code and controlling Depth and z-
cas... axis zoom functionality.

Run the code in a Raspberry Pi, which is a pretty

Step 10: Vote for Me!

I've entered this instructables to both the robotics and the photography contest. Please vote for me if you liked it.

Face Tracking Pan-Tilt Camera: Page 7

You might also like