Face Recognition With Raspberry Pi + OpenCV + Python

Core Electronics
5 Jul 202107:14

Summary

TLDRThis video from Crow Electronics demonstrates how to use a Raspberry Pi and open source software to create a facial recognition system. It covers the setup with necessary hardware, installing packages, capturing facial images, training the model with Python scripts, and finally, using the trained model for real-time face identification. The tutorial also extends the project by integrating a servo motor controlled by the Raspberry Pi's GPIO pins, responding to recognized faces. The video highlights the ease of implementing machine learning with accessible tools and open source software.

Takeaways

  • 🤖 The video is a tutorial on how to use a Raspberry Pi to recognize faces with the help of open source software.
  • 📷 OpenCV and the Python face recognition package are the two main tools used for real-time computer vision and face detection.
  • 🛠️ A Raspberry Pi, official camera module, micro SD card, power supply, HDMI cord, monitor, mouse, and keyboard are the hardware requirements.
  • 💻 The Raspberry Pi 4 Model B is recommended for its extra computing power.
  • 🔍 The camera module needs to be enabled in the Raspberry Pi configuration menu for the project to work.
  • 📝 The 'headshots_pycam.py' Python script is used to take photos of faces for training the face recognition model.
  • 👤 Users should take around 10 photos of their face from different angles for better recognition.
  • 📁 A separate folder is created for each person's face photos to store the training images.
  • 🔧 The 'train_model.py' script is used for training the model with the collected face images.
  • 📡 The 'facial_rec.py' script runs the identification process, displaying a live stream and identifying known faces.
  • 🔄 The Raspberry Pi can differentiate between known and unknown faces, labeling them accordingly.
  • 🛠️ By modifying the 'facial_rec.py' script, the Raspberry Pi can control a servo or other mechanisms using GPIO pins when a known face is detected.
  • 👍 The video credits OpenCV, the face recognition package, and Carolyn Dunn for their contributions to the software used in the project.

Q & A

  • What is the main purpose of the video?

    -The main purpose of the video is to demonstrate how to use a Raspberry Pi with open source software to recognize faces and control a servo based on face recognition.

  • Which open source software is mentioned for real-time computer vision problems?

    -OpenCV is mentioned as the open source software for solving real-time computer vision problems.

  • What is the role of the Python face recognition package?

    -The Python face recognition package computes bounding boxes around a face in real time, aiding in the face recognition process.

  • What are the hardware requirements for setting up the face recognition system with Raspberry Pi?

    -The hardware requirements include a Raspberry Pi, an official camera module, a micro SD card, a power supply, an HDMI cord and monitor, a mouse and keyboard, and optionally a servo for additional control.

  • Why is a Raspberry Pi 4 Model B recommended for this project?

    -The Raspberry Pi 4 Model B is recommended due to its extra computing power which is invaluable for running the machine learning algorithms required for face recognition.

  • How can one enable the camera interface on the Raspberry Pi?

    -The camera interface can be enabled through the Raspberry Pi configuration menu, found under the 'Preferences' and then the 'Interfaces' tab.

  • What is the purpose of the 'headshots_pycam.py' Python script?

    -The 'headshots_pycam.py' script is used to take photos of faces using the official Raspberry Pi camera for training the face recognition model.

  • How many photos of a face should be taken for the training process?

    -It is suggested to take around 10 photos of a face, including different angles, for better recognition accuracy during the training process.

  • What is the command to start the face recognition training process?

    -The command to start the training process is 'python train_model.py', run from the 'facial_recognition' directory.

  • How does the Raspberry Pi identify a known face and respond?

    -When a known face is identified, the Raspberry Pi draws a yellow box around the face and writes the person's name next to it in the live stream window.

  • What can be done to control a servo using face recognition results?

    -The Raspberry Pi can be programmed to send signals via the GPIO pins to control a servo, activating it when a known face is recognized and keeping it inactive for unknown faces or no face at all.

Outlines

00:00

🤖 Raspberry Pi Face Recognition Setup

This paragraph introduces a project where a Raspberry Pi is used to recognize faces using open source software. The narrator explains the synergy between open source software and Raspberry Pi, highlighting two key tools: OpenCV for real-time computer vision and the Python face recognition package. The project involves training the Raspberry Pi to identify a person's face and then using that recognition to control a servo. The required hardware is listed, including a Raspberry Pi 4 Model B for its computing power, an official camera module, a micro SD card, and other accessories. The process starts with setting up the Raspberry Pi, enabling the camera, and installing necessary packages. The user is guided to take photos of their face for training the model and to run a Python script for training the face recognition system.

05:00

🛠️ Enhancing Raspberry Pi with Face-Controlled Servo

The second paragraph delves into the practical application of the face recognition system by integrating it with a servo. The narrator demonstrates how to modify the Python code to send signals via the Raspberry Pi's GPIO pins when a known face is detected. This allows the servo to rotate, creating an interactive element to the project. The video shows a practical example where the servo only activates when the narrator's face is recognized, otherwise, it remains inactive. The narrator expresses gratitude to the developers of OpenCV and the face recognition package, as well as to Carolyn Dunn for creating software that integrates these systems effectively. The paragraph concludes by emphasizing the potential of this software for various projects and ends with a sign-off until the next video.

Mindmap

Keywords

💡Raspberry Pi

Raspberry Pi is a series of small, single-board computers developed to promote the teaching of basic computer science in schools and in developing countries. In the video, it is the central device used for building a facial recognition system, showcasing its versatility and computational capabilities.

💡Open Source Software

Open source software refers to a type of software whose source code is available to the public for use, modification, and enhancement. In the context of the video, open source software like OpenCV and the Python face recognition package are utilized to create a real-time face recognition system on the Raspberry Pi.

💡OpenCV

OpenCV, which stands for Open Source Computer Vision Library, is a library of programming functions mainly aimed at real-time computer vision. In the video, OpenCV is highlighted as a crucial tool for solving real-time computer vision problems, such as detecting and processing faces in images or video streams.

💡Python Face Recognition Package

The Python face recognition package is a library used for facial recognition tasks. It is mentioned in the video as a tool that computes bounding boxes around faces in real time, which is essential for the Raspberry Pi to recognize and identify individuals.

💡Machine Learning

Machine learning is a subset of artificial intelligence that provides systems the ability to learn and improve from experience without being explicitly programmed. In the video, the Raspberry Pi uses machine learning algorithms to train and recognize human faces, demonstrating the accessibility of this technology.

💡Microprocessor

A microprocessor is a small computer processor that integrates the functions of a computer's central processing unit (CPU) on a single integrated circuit. In the video, the Raspberry Pi's microprocessor is highlighted for its role in processing the facial recognition tasks, emphasizing the computational power needed for such applications.

💡Camera Module

The camera module mentioned in the script refers to the official Raspberry Pi camera module, which is used to capture images or video. In the context of the video, it is essential for capturing the facial images required for training the face recognition system.

💡Training Model

In machine learning, a training model refers to the process of teaching an algorithm to make predictions or decisions based on input data. In the video, the script describes how the Raspberry Pi is trained to recognize individual faces using a set of images, which is a fundamental step in the facial recognition process.

💡GPIO Pins

GPIO stands for General Purpose Input/Output and refers to a group of pins on a Raspberry Pi that can be used to control or read signals from external devices. In the video, the script explains how GPIO pins can be used to send signals to control a servo motor when a known face is recognized.

💡Servo

A servo is a type of motor that includes a closed-loop system for precise control of position or speed. In the video, the Raspberry Pi is programmed to activate a servo motor when it recognizes the user's face, demonstrating a practical application of the facial recognition system.

Highlights

Using Raspberry Pi and open source software like OpenCV and the Python face recognition package to create a facial recognition system.

Raspberry Pi's open source nature makes it an excellent platform for real-time computer vision and machine learning projects.

The tutorial demonstrates how to train the Raspberry Pi to recognize a specific face using the official camera module.

The face recognition system uses bounding boxes to detect and identify faces in real-time.

List of required components for setting up the facial recognition system, including the Raspberry Pi 4 and official camera module.

Instructions on enabling the camera interface in the Raspberry Pi configuration menu.

Using the 'headshots_pycam.py' script to take photos of faces for training the model.

Creating a folder with the user's name to store the captured face images for training.

Running the 'train_model.py' script to analyze the dataset and train the model to recognize faces.

The trained model can identify known faces and write the person's name next to the detected face in real-time.

Demonstration of the live face recognition system using the Raspberry Pi camera and the trained model.

The system can differentiate between known and unknown faces, labeling them accordingly.

Exploring the potential of using the Raspberry Pi's GPIO pins to control external devices like servos based on face recognition.

Adding code to the 'facial_rec.py' script to activate a servo when a known face is detected.

The servo moves when the Raspberry Pi recognizes the user's face, demonstrating the practical application of the system.

The tutorial credits the open source communities behind OpenCV and the face recognition package for their contributions to the project.

A call to action for viewers to explore the potential of the software for their own projects, highlighting the limitless applications.

Transcripts

play00:00

hey gang team here at crow electronics

play00:01

and today we're making our raspberry pi

play00:03

recognize who we are by our face

play00:07

[Music]

play00:11

open source software and raspberry pi's

play00:13

go together hand in hand

play00:14

the two excellent examples of this are

play00:16

opencv which provides a huge

play00:18

free resource to solve real-time

play00:20

computer vision problems

play00:21

and the python face recognition package

play00:24

which computes

play00:25

bounding boxes around a face in real

play00:27

time

play00:28

these are the two systems that we will

play00:29

use to make this all come together

play00:32

machine learning has never been more

play00:34

accessible i will show you exactly how

play00:35

to have your raspberry pi microprocessor

play00:37

be able to spot human faces

play00:39

how to train it to know your face and to

play00:42

run code

play00:43

so that it will successfully identify

play00:45

you when it sees you

play00:46

then i'll take it another step and show

play00:48

you how you can use your face to control

play00:50

the servo which is attached to

play00:52

the raspberry pi

play00:56

before me on the table is everything you

play00:58

need to get this system

play00:59

up and running really fast starting off

play01:01

you're going to want a raspberry pi

play01:03

official camera

play01:04

module version 2. you can also use the

play01:06

raspberry pi high quality camera

play01:08

a micro sd card a official raspberry pi

play01:10

power supply

play01:12

a hdmi cord and monitor to connect to a

play01:14

mouse and keyboard

play01:16

and for this i'm using a raspberry pi 4

play01:18

model b as the extra computing power

play01:20

oomph that the raspberry pi provides is

play01:23

invaluable

play01:24

you're also going to want some way to

play01:25

connect the micro sd card

play01:27

to your computer so you can flash it

play01:32

so we're going to get started with all

play01:34

the packages installed already

play01:36

to follow along at this point go to the

play01:37

article to get the steps to install the

play01:39

packages on your setup

play01:40

once you power up the raspberry pi

play01:41

you're going to see this familiar

play01:42

background booted up

play01:44

now first let's open up the raspberry pi

play01:46

configuration menu

play01:48

found by using the top left menu

play01:50

scrolling over preferences

play01:51

and make sure that the camera found

play01:53

under the interfaces tab

play01:54

is enabled if you had to enable this

play01:57

setting go ahead and reset the raspberry

play01:59

pi so that the changes can take

play02:00

effect now open up the file explorer

play02:03

which is the folder button on the top

play02:04

left of the screen

play02:05

jump into the folder located in the home

play02:08

pi directory

play02:09

facial recognition and then look for the

play02:11

python code called headshots

play02:13

underscore pycam.py this python code

play02:16

will let us take some photos

play02:18

of our faces using the official

play02:20

raspberry pi camera right click

play02:22

and open up that python script with

play02:24

either funny or genie

play02:26

both are just python language

play02:27

interpreter softwares and alter the line

play02:29

of code here

play02:30

with your name in my case timmy

play02:34

then save this script next go back into

play02:37

the folder structure and open up

play02:39

the photos folder here you're going to

play02:41

add another folder with your name

play02:43

this folder is then going to be the

play02:44

location where the photo files will end

play02:47

up then jump back into the python editor

play02:50

where we had

play02:50

saved that python code and run it this

play02:53

will open up a little window and a

play02:55

terminal window

play02:56

which you can use to save images of your

play02:58

face press the spacebar key to take an

play03:00

image

play03:01

take around 10 and then the q key to

play03:03

close the window once you've done so

play03:05

provide a couple of different angles of

play03:07

your face so it can determine your

play03:08

dimensions

play03:09

better once you close the software

play03:11

you're going to be able to see the

play03:12

images of your face

play03:13

stored in the folder you created for

play03:15

your name you can add other faces using

play03:17

this same method too

play03:20

with all that sorted we can get into the

play03:22

machine learning step

play03:24

the pictures we took will now be used by

play03:25

the python code train

play03:27

underscore model dot py any pictures in

play03:30

the dataset folder location will be

play03:32

analyzed by this code when we run this

play03:34

program

play03:35

so open up a new terminal using the

play03:37

black console button on the top left

play03:39

and type the following pressing enter

play03:41

after each line cd

play03:42

space facial underscore recognition this

play03:45

will get us into the right folder

play03:47

and then python space train underscore

play03:49

model dot py

play03:51

which is going to run our desired code

play03:53

this will start the training process

play03:54

which you can see occurring for each

play03:56

image

play03:57

that i took of my face

play04:02

then with that completed the raspberry

play04:04

pi 4 model b will have learned what your

play04:06

face looks like

play04:07

so let's give it a go to run the

play04:09

identification code that will identify

play04:11

faces and when it finds a train face

play04:13

will write their name next to it

play04:14

start by opening up a new terminal just

play04:17

the same as before

play04:18

then type the following and press enter

play04:20

after each step

play04:22

cd facial underscore recognition and

play04:25

then

play04:25

python facial underscore req dot

play04:29

py once you press enter it's going to

play04:31

take around 5 seconds to boot up and run

play04:33

then you're going to see a small window

play04:35

pop up with a live stream of the

play04:37

raspberry pi camera

play04:38

aim the camera at your face and if it

play04:40

puts a yellow box around your head

play04:42

and names you correctly you have done it

play04:44

the raspberry pi camera is now searching

play04:46

live for faces

play04:47

it will also determine if it's a known

play04:49

or an unknown face if it's unknown it's

play04:51

going to write

play04:52

unknown next to it and if it's a face of

play04:54

the name of the person that it knows

play04:55

it's going to write that person's name

play04:57

next to it

play04:58

this example code is awesome and lets

play05:00

you experiment to see

play05:01

when the software can or cannot track

play05:03

your face i find if you tip your head to

play05:05

the side a couple of degrees it's going

play05:07

to completely disable the facial

play05:08

recognition and

play05:10

if you cover your nose as well it

play05:12

struggles close the terminal window or

play05:14

press ctrl c

play05:15

on the keyboard to stop it running

play05:18

[Music]

play05:20

so we can do many things with this now

play05:22

simply to start we can now jump into the

play05:24

folders with the python code and alter

play05:25

just a couple of lines

play05:26

in that code in the facial underscore

play05:29

rec dot py

play05:30

so that every time a known face is seen

play05:32

it's going to send out signals via the

play05:34

gpio pins of the raspberry pi

play05:37

these general purpose input and output

play05:39

pins can be used to control an almost

play05:41

endless amount of sensors and mechanisms

play05:43

so

play05:44

for this i'm going to get a servo to

play05:46

rotate when the raspberry pi system sees

play05:49

my

play05:49

face if it sees an unknown face or no

play05:52

face at all

play05:52

it's not going to activate this servo

play05:55

all this

play05:56

by adding just six lines of code to the

play05:58

script

play05:59

all the code i'll be adding here is

play06:01

completely explained in the guide

play06:02

controlling standard servers with

play06:04

raspberry pi

play06:05

linked down below so hopefully you can

play06:07

see everything what i'm going to do is

play06:09

hide my face from the camera by putting

play06:11

my thumb just in front of it

play06:13

the server you're going to be able to

play06:14

see from the top and when i show up my

play06:16

face

play06:17

you're going to see the server move you

play06:18

can see it's active

play06:22

see down here

play06:26

it's red because my skin is pink

play06:30

and now i'm going to show my face

play06:33

boom straight away as soon as it saw my

play06:35

face

play06:36

nice huge thanks go to the opencv

play06:39

and facial recognition package teams

play06:42

that work on the amazing machine

play06:43

learning software

play06:44

that we have running on this raspberry

play06:46

pi both

play06:47

are really good open source software

play06:49

also a huge thank you goes to carolyn

play06:51

dunn

play06:52

who created the majority of the amazing

play06:54

software which makes these two systems

play06:56

work together

play06:56

so well there's just so much potential

play06:59

with this software to take projects to

play07:01

amazing places

play07:02

so that's it for today until next time

play07:05

stay cozy

Rate This

5.0 / 5 (0 votes)

相关标签
Face RecognitionRaspberry PiMachine LearningPythonOpenCVDIY ElectronicsTech TutorialServo ControlOpen SourceComputer Vision
您是否需要英文摘要?