Make a face tracking camera on Raspberry Pi !
This article is recommended for such people!
  • Someone who wants to do something with Raspberry Pi
  • Someone who wants to do something with Python or machine learning
  • Someone who wants to make a face tracking camera

I tried to build a face tracking system based on Raspberry Pi and Python, machine learning technology.
I’m going to share to you how to make the face tracking camera today.

If you want to see more detail, please see the YouTube video for about 20 seconds.
You can see that the camera attached to the Raspberry Pi is chasing Mozart’s photo.
The camera has a servomotor which moves horizontally and vertically.
It is directed towards the face of Mozart.

I will write out the framework of this system, including Python Code, used materials, and so on…

Python Code

This system works with Python code.
I mainly referred to this web page.
(Reference:Raspberry Pi3 とカメラモジュールで顔追跡カメラを作る (Making face tracking camera with Raspberry Pi and camera module))

I further improved the code.

I thought that some people might be interested in the code and write it first.
I’m going to introduce “The framework of the system” with Python Code.

System structure

The program is divided into three parts.
as illustration above,

  1. Library import
  2. Definition of parameters and various characters, initialization, etc.
  3. Processing part (from “while(True)”)

I will explain important things in the system.

Library import

Definition of parameters and various characters, initialization, etc.

Installing of 2-axis servo motors!

 

In this system, two servomotors (2 SG90s) are used.

There are three lines per servomotors.
Each line is below.

  • Yellow : GPIO number 4 (X) and 17 (Y)
  • Red : To 5V power supply
  • Brown :  To GND

Power and ground can be anywhere.
It is ok if you connect as shown below.

 

 

Determine the movable range of X-axis and Y-axis on the program

Set this movable range empirically while actually moving the servomotor !
(It’s safer!!)

So, please change X_MAX and Y_MAX directly at the final adjustment stage.

After that, it works by posting the program.

 

Although the product link is attached, the camera kit here is a little substandard.

In addition, there is no connector part linking the base stage and the servomotor! ! Lol

I was patient because the price was cheap.
I made it by processing the connecting part.

I also attach a camera module link, but if you have a webcam, that will do.

Important point

Please keep in mind that the connection confirmation of the camera and the GPIO pin can be used.

On each terminal,

  • vcgencmd get_camera
  • sudo pigpiod

Just press enter!

There’s Endless possibility with Raspberry Pi!!!!

You can do anything with Raspberry Pi!
The face tracking camera was also fairly easy to make.
Why not to make some systems using Raspberry Pi for everyone.