Face Following Smart Camera For Video Shooting

This post was originally published on this site

Video shooting is used in many areas now but when you talk about the video shoot capturing the movement of face or object in real-time response is very difficult for the cameraman. moving the camera at the same rate as the face or target object movement is very difficult when you do it manually with your hand.So we have decided why not let’s try to make a smart camera that enables us to shoot video of moving heads in real time . So today we will make a smart system with some motors that captures the video in real time detect the face and move the camera along with the movement of the face.

Bill of Material

Prerequisites 

Use the following commands to set up the Python modules in the Raspberry Pi board:

sudo pip3 install gpiozero

sudo pip3 install opencv-python

sudo pip3 install nmap

sudo pip3 install dlib

sudo pip3 install face_recoginition

To enable the RPi camera, use sudo raspi-config and then go to interfaces.

Coding 

Write two different codes: one for target object tracking and the other for face and camera tracking. Here, the camera obtains the x and y coordinates of the face and then translates them into the movement angle of the servo motor. In the code, only the x-coordinate of the servo motor and not the y-coordinate movement of the face is being tracked. But you can add one more servo motor to track the y-coordinate facial movement. 

Implement the facial recognition code that was earlier written for the face recognition robot project and then import a few new libraries into the code. Make sure to import the gpiozero library in the code to control the servo. Then set the pin number of Raspberry Pi to control the servo motor. Here you can use any PWM pin of Raspberry Pi. A Bonnet has been attached to the Raspberry Pi, whose pin A (rather than that of Raspberry Pi) allows direct access to control the servo.

After getting the x-coordinate of the face, use it to write position values for the servo motor so that the shaft moves simultaneously with facial movement. This will enable the attached camera to move along as well.

Connection

Connect the servo positive wire (red) to a 5V power source and negative of power source (black wire) to the GND pin of Raspberry Pi. Next, connect the yellow wire of the servo motor to the GPIO pin of Raspberry Pi. Now mount the Raspberry Pi camera on the servo (as shown below).

Testing 

Run the code and move your face in front of the camera. The camera follows the movements of your face with the same speed, making it smooth to shoot a video from any given angle.

 The project can be enhanced further for the camera to follow linear/vertical facial movements.

Code