Face Recognition and tracking using Servo Using Rpi

Can someone guide me in how to make a particular face recognition and tracking through the camera attached to the servo.
I need help particularly in the servo part , how do i code the servo to keep tracking the face.

1 Like

Hi Christopher,

Welcome to the forum :grinning:

Tim has put together a guide on how to do just that with the Pi.

If you have any questions relating to the guide there is another forum thread you can find here.


Hi everyone,

I have a adafruit servo hat and not a pan-tilt hat. How will the code change to use the servo hat rather than the pan-tilt HAT?

Hey Jaco,

The code available here for the pan-tilt hat setup will change a little if you are using a different hat.

For the adafruit servo hat specifically you will need to change what library is imported for the hat in your declarations. so “from pantilthat import *” will be replaced with

from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)

As for the usage in the code itself you will need to change every usage of pan() and tilt() to a version of

kit.servo[0].angle = 180

For this adafruit servo hat the [0] is referencing the channel the servo is connected to so you would need to determine what servo you wanted to perform the pan functions and match that servo channel to those functions. same goes for the tilt functions.

The 180 in my given example changes the angle of the servo. For most of the code you wouldn’t need to update much and only change these lines when needed. For example the code in the tutorial has this section

#Update the servos

assuming you had your pan servo on channel 1 and you tilt servo on channel 2 you would update this to look something like.

#Update the servos
kit.servo[1].angle = int(cam_pan-90)
kit.servo[2].angle = int(cam_tilt-90)

I would definitely suggest looking at the documentation for your Adafruit servo hat which, if I have found the right one, is available here. Just to make sure I haven’t missed any of the nuances of your setup.

If you need any more help don’t hesitate to ask!