Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

If you don’t want to miss my updates, remember to check the public account in the upper right corner and set it as a star, take down the stars and give them to me.

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi
Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

When it comes to computer vision and face recognition, the first reaction is definitely to use OpenCV. Now with the latest MATLAB library, it can also be easily accomplished:

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

(Source: hackster.io) To implement the above face recognition function, the required software and hardware are also very simple:

Hardware: Raspberry Pi 3 model B, Raspberry Pi camera module
Software: MATLAB
Next, I will demonstrate step by step how to use MATLAB to achieve face recognition on Raspberry Pi:

About MATLAB, many people may think that it is a course in college, but in fact, many data researchers and artificial intelligence scientists use MATLAB. Although it may take some time to get started, once you get into it, you will find that MATLAB can basically accomplish all tasks. With the built-in tool library and related software support of MATLAB, you will be immersed and unable to extricate yourself. MATLAB even supports generating runnable software code for Raspberry Pi, which is a major wish for Raspberry Pi enthusiasts.

1

Installation

Before starting, make sure that MATLAB software is installed on your computer. I won’t go into detail about the installation of MATLAB, please solve it yourself.

Then, we need to install the relevant tool packages in MATLAB, the installation steps are:

1) Open MATLAB and select Add-Ons->Get Add-Ons

2) Search for ‘MATLAB Raspberry Pi support package’ -> install

3) Accept the terms

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi
After the installation is complete, click ‘Run now’ to open the configuration assistant.
Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

2

Configure Raspberry Pi to work with MATLAB

The principle of collaboration between MATLAB and Raspberry Pi is that MATLAB sends commands to Raspberry Pi while Raspberry Pi acts as a server in the project, interpreting and executing the received commands.

The development board setup assistant will guide you step by step to configure and install the image system designed for MATLAB on Raspberry Pi (Raspbian Image). Then the setup assistant will help you configure the image system step by step based on the selected network options.
Select Raspberry Pi model:

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Select ‘Setup hardware with Mathworks Raspbian image’

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Download the deep learning image file

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Find the downloaded image file and unzip it:

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Verify the image file

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

3

Burn the image

Find a memory card, connect it to the computer with a card reader, and start burning the image file.(Note: The MAC version of MATLAB cannot burn images. Friends using MAC can use ‘BalenaEtcher’ to burn the image.)

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

After burning the image, the next step is to establish a connection between MATLAB and Raspberry Pi.
There are four ways to connect Raspberry Pi and MATLAB:
1) Connect via LAN
2) Connect via wireless
3) Direct Ethernet connection
4) Manually configure network settings
Select ‘connect to wireless network.’ Fill in the wireless SSID and password.Note that Raspberry Pi and PC need to be connected to the same wireless network.
Select to obtain IP address automatically and click next.

01

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

02

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

03

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

04

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi
Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Swipe to view steps

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi
In general, MATLAB will set up the network connection on Raspberry Pi, but sometimes you also need to configure the Raspberry Pi’s WIFI network connection yourself.
Connect a mouse, keyboard, and HDMI display to Raspberry Pi.
Insert the burned SD card.
Connect the 5v power supply.
Connect the camera module to the Ethernet port of Raspberry Pi via the MIPI-CSI cable.
Click ‘next’ on MATLAB to verify the connection.

If the connection is successful, ‘test hardware connection successful’ will appear.Otherwise, ensure that your Raspberry Pi and PC are in the same network environment.

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

4

Transmit commands and control Raspberry Pi

If the test connection passes, you can now control Raspberry Pi through MATLAB.

In the MATLAB command window, enter:
‘mypi=raspi’
Then the relevant information of the Raspberry Pi development board will be feedback, including digital pins, number of LEDs, SPI channels, I2C channels, and rates in the MATLAB workspace.
Test whether the command is effective, enter in the command window:
writeLED(mypi,’led0’,1)
writeLED(mypi,’led0’,0)
To control the switch of the ‘ACT’ LED light on Raspberry Pi.
Connect the camera, enter in the command window
cam=cameraboard(mypi,’Resolution’,’1280×720’)
Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

5

Run the face recognition program

Clear the test connection channel, enter in the MATLAB command window:

Clear
Point the Raspberry Pi camera at the face, create a new MATLAB script file, copy the code into the script file and name it facedetection.m. Make sure the current workspace is in the folder with the script file.

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Open and run the facedetection.m program. This will open the ‘Figure-1’ window and start automatically detecting and recognizing faces. To stop, just click pause.
Next, you can also use the command fD=vision.CascadeObjectDetector to recognize noses, eyes, and ears. Of course, other objects such as cars, signs, and water bottles can also be recognized.

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Code used:
%% set up your raspberry pi hardwareperipherals accessmypi = raspi();myCam = cameraboard(mypi)%% Image acquisition & plottingmySnap = snapshot(myCam)imshow(mySnap)hold on%% Detect face and insert a rectangle around thefacefD = vision.CascadeObjectDetector(); %% fromcomputer vision toolboxbbox = step(fD, mySnap);imageOut = insertObjectAnnotation(mySnap,'rectangle', bbox, 'Face');imshow(imageOut);%% Repeat in a loop to make it look like facedetection in videoflag = 1;while flagclearvars -except mypi myCam flagmySnap = snapshot(myCam);imshow(mySnap);hold onfD = vision.CascadeObjectDetector();bbox = step(fD, mySnap);imageOut = insertObjectAnnotation(mySnap, 'rectangle',bbox, 'Face');imshow(imageOut);title('Detected Face');drawnow %% refreshes the image window afterevery loopend
The above is the complete process of using MATLAB and Raspberry Pi to achieve face recognition. If you have a Raspberry Pi, you might as well give it a try.
Currently, computer vision for face recognition still mostly uses OpenCV, the Darwin project practical training camp season 4: Computer Vision OpenCV is open! Every Monday/Wednesday, updates will be synchronized on the Darwin official website and Bilibili, if you want to quickly get started with OpenCV for computer vision, be sure to follow along~~
Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi
Click to follow the course
END
Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

More practical project recommendations:

STM32 IoT Smart Home Project

Raspberry Pi + Compute Stick 2 Real-time Face Recognition Project

Building a Cloud Computing Platform for Embedded Development Boards

STM32 Implementing the Simplest Air Mouse

Arduino Rubik’s Cube Robot

STM32 Version of “AI Soul Painter”

STM32 Electronic Photo Album Production

STM32 + DDS Homemade Signal Generator

Using Raspberry Pi and Web Interface to Remotely Control Appliances

STM32 “Cloud” Music Player

Raspberry Pi Remote Monitoring

Design of Glow Tube Clock Based on STM32

Homemade FPGA Minimum System Board (PCB can be directly made)

Raspberry Pi 4 Builds NAS, Making Hard Drives Easily Networked

ESP32 Car Software and Hardware Practical Sharing

Only 79 lines of code to complete creative gesture recognition

IoT + Electronic Ink Screen can create a custom display

Build a value of thousands of exploration robots for dozens of dollars

Glasses-free 3D holographic display, visual persistence POV project

DIY Gesture Recognition Module

Practical small designs that can be DIYed from scratch

Raspberry Pi creates a smart doorbell + smart door lock that can video

Strange! My development board can play games automatically

Homemade ventilator

ESP8266 + Zigbee Networking to Transform Wall Switches

Wireless Home Monitoring System

DIY Bionic Arm, a tool to free your hands

Handmade Air Purifier, all design materials open source

Tech Toy: Remotely Controlled Bluetooth Cannon

Create the LittleBee Monitoring System with ST Sensors, Let Bees “Speak”

Homemade Cat Petting Device

STM32 + Raspberry Pi Implementing 6s Rubik’s Cube Robot

Blind Modification of Drone Controller, DIY “Foam” Drone

Recommended Reading:

Project Sharing | Electric Competition Series | Artificial Intelligence | Postgraduate Entrance Examination
Essential Knowledge Points | Graduation Project | Switch Power Supply | Job Seeking
We are Nimo, the founder of Darwin, a girl who only talks about technology and not flirting. The Darwin online education platform aims to serve professionals in the electronics industry, providing skill training videos covering popular topics in various sub-fields, such as embedded systems, FPGA, artificial intelligence, etc. It customizes layered learning content for different groups, such as commonly used knowledge points, disassembly assessments, electric competitions/intelligent vehicles/postgraduate entrance exams, etc. Welcome to follow.
Official website: www.darwinlearns.com
Bilibili: Darwin
QQ Group: Group 1: 786258064 (full)
Group 2: 1057755357
Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Like, watch, and share three times in a rowStep-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Step-by-Step Guide to Face Recognition Using MATLAB and Raspberry Pi

Leave a Comment

×