Table of Contents

Automatic Door Unlocking System Using Face Recognition

door unlock using face detection
Project Description
Learn how to make a touch-free security system based on face recognition technology that unlocks a door if it matches your face using PictoBlox.

Introduction

In the time of this pandemic, everything is turning contact-less. Today, we are going to make a touch-free security system based on face recognition technology that unlocks a door if it matches your face with one of those fed into the system?

We are going to make the door in PictoBlox unlock using the Face Detection in PictoBlox- a Scratch-based graphical programming software for kids. You can download it from here.

Let’s begin.

Prerequisites

You’ll need the following things to make the make your own logo quiz:

  1. A laptop or a computer with a camera
  2. The latest version of PictoBlox, which you can download from here.
  3. A good Internet connection

Setting Up the Project

Open PictoBlox.

To work with the latest AI and ML extension you need to keep two things in mind.

  1. That your computer is connected to the Internet 
  2. You need to log in to PictoBlox.

Click on the Add Extension button and choose Face Detection extension.

Face-detection Extension

Also, we will use Tobi as our assistant, thus, we will make him speak. Thus, let’s add the text-to-speech extension to make Tobi talk.Text-to-Speech Extension

Setting Up the Stage for Automatic Door Unlocking System

  1. Let’s first add the main element of the project, the door. We will use the door as the backdrop. Click here to download them.
  2. Now, go to Choose a Backdrop button and click on Upload Backdrop.
  3. Upload all the images of the door as it gives us the visual that the door is opening or closing.
  4. Wait for a  little while till they are imported.
  5. Now that we have all the door images uploaded to the project. You can remove the plain backdrop.
  6. Make sure that you have selected the first costume of the door, if not will look for the same in the future. Door Backdrop
  7. Now, let’s move Tobi to the bottom left corner.
  8. Let’s add a small button using the ball in our case.
  9. Thus, click on the Choose a Sprite button and choose the ball sprite from the library. You may choose the color of your choice. Also, let’s place it next to the door and reduce its size.Ball Sprite

The final setup will look like this.Door Unlocking System Using Face Detection Setup

Storing the Face into the System

Let’s begin by writing the script to feed our face into the memory.

  1. Thus, click on Tobi’s sprite.
  2. Place when space key pressed block from the Events palette, and choose space from the drop-down.
  3. Now, we need Tobi to instruct the user to look into the camera.
  4. Thus, place a say block from the Looks palette, and write “Please look into the camera” in the space given.
  5. To make Tobi say it out loud, place speak block from the text-to-speech palette and write the same in it.
  6. Now, we need to turn the cameras on, thus from the Artificial Intelligence palette, place the turn on video on stage with 0 % transparency block.
  7. We need the camera to analyze, thus add a wait block from the Controls palette and write 3 in the space given.
  8. Let’s ask the user to wait for a little while.
  9. Duplicate the pair of say and speak blocks and write Analysing in both spaces.
  10. In this case, we will add the user image as the class.
  11. Thus, place add class 1 as from camera and write the user name into the space given.
  12. Next, we want Tobi to assure the user that the face was stored. Thus, again use the say and speak block for the same and write Face in both the space given.
  13. Finally, after the face is stored, we need to turn the camera off, thus from the Artificial Intelligence palette, place the turn on video on stage with 0 % transparency block and choose off from the drop-down.

The final script will look like this:Storing the Face

Making Tobi Conversate

Now, let’s start with writing the script for introducing Tobi to the users.

  1. To execute the program every time the green flag is clicked, place a when flag clicked hat block from the Events palette.
  2. Now, we first do not need to open the camera, thus from the Artificial Intelligence palette, place the turn on video on stage with 0 % transparency block and choose off from the drop-down.
  3. Next, from the text-to-speech palette, place a set voice to block and choose tenor from the drop-down.
  4. Now, to make sure that the door is closed, we need to make it as the default backdrop. Thus, from the looks palette, place a switch backdrop to block and choose door_1 from the drop-down.
  5. Now, let’s make Tobi conversate.
  6. Place a say block from the Looks palette, and write Hello! I am Tobi in the space given.
  7. To make Tobi say it out loud, place speak block from the text-to-speech palette and write the same in it.
  8. To make the door as if it is closed every time the user clicks on green flag, go the backdrop, drag and drop when flag clicked hat block.
  9. Place switch backdrop block from the Looks palette and choose door_1 from the drop-down.
  10. We will make the entire face recongition and the door sequence happen, when we press the blue button. Thus, let’s instruct our users the same.
  11. Duplicate the above two blocks and write Please press the blue button to access the door in both the space given.

The complete script looks like this:Making Tobi Conversate

Unlocking the Door Using Face Detection

Now, let’s write the script for what happens when the button is clicked.

  1. Thus, go to the ball sprite. You can rename it if you want.
  2. When this sprite is clicked, we need to broadcast the message that the user is trying to access the door.
  3. Thus, place when this sprite clicked hat block from the Events palette.
  4. And the broadcast block. Write Door Access as the new message in the drop-down of the broadcast block.

Now, that the button is pressed, let’s make the script for what happens to the door.

  1. Thus, go back to the Tobi Sprite.
  2. Drag and drop the broadcast message hat block and choose Door Access from the drop-down.
  3. Let us make Tobi guide the user to look into the camera, thus place the say and the speak block and write “Please look into the camera” in both the spaces given.
  4. Now, let’s turn the camera ON. Thus, place the turn on video on stage with 0 % transparency block.
  5. We need the camera to analyze, thus add a wait block from the Controls palette and write 3 in the space given.
  6. Let’s ask the user to wait for a little while.
  7. Duplicate the pair of say and speak block and write Analysing in both the spaces given.
  8. Now, to match up the face with the one stored in the class, place the do face matching on camera block from the Artificial Intelligence palette.
  9. Now, if the face is matched, we need Tobi to say that the face matched and the door to open.
  10. Thus, place an if-else block from the Events palette.
  11. Place is 1 class detected from the Artificial Intelligence palette.
  12. Now, to make the Tobi say that the face Matched and we are welcome to the house, place a pair of say and speak block and write Face matched! Welcome to the house! In both the spaces given.
  13. You can make Tobi say your name too if you want to.
  14. Now, to make the Door open. Place a repeat block and write 12 in the space given.
  15. Place the next backdrop block from the Looks palette.
  16. To make the backdrop change visible place a wait of 0.1 seconds.
  17. Now, what if the faces does not match. We’ll make Tobi say that the Face dint match and ask the user to contact the owner again.
  18. Thus, into the else arm place say and speak block and write “Face didn’t match, Please contact the owner or try again.” in both the spaces.
  19. Also, we need to turn the camera OFF, thus from the Artificial Intelligence palette, place the turn on video on stage with 0 % transparency block and choose off from the drop-down.

With this, your script is ready.Unlocking Door Using Face Detection

Conclusion

In this project, we learned about unlocking a door using a Faces detection model in PictoBlox. We required a laptop or an available computer, the latest version of PictoBlox Extension, and a good internet connection to store and match user’s face into the system. We used the door backdrop to make it more realistic. In the end, we wrote the scripts for making Tobi conversate, storing and matching the face, and unlocking the door accordingly. With this project, kids and learners will have a better understanding of Face Detection and how to use the applications.

Project Downloads - Code and Files

Explore Related Projects by STEMpedia

Learn how to make a self-driving car using PictoBlox and the Recognition Card Extension. Create a stage resembling a street and program John the instructor to guide the user through selecting lanes and recognizing number cards.
Learn how to create a virtual doctor using Natural Language Processing (NLP) in PictoBlox. Train the text data for diseases and build a text classifier.
Learn how to make a face recognition-based attendance system using micro: bit in PictoBlox AI. Track attendance by scanning faces and storing data in Excel.

Explore Community Projects