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:
- A laptop or a computer with a camera
- The latest version of PictoBlox, which you can download from here.
- 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.
- That your computer is connected to the Internet
- You need to log in to PictoBlox.
Click on the Add Extension button and choose 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.
Setting Up the Stage for Automatic Door Unlocking System
- 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.
- Now, go to Choose a Backdrop button and click on Upload Backdrop.
- Upload all the images of the door as it gives us the visual that the door is opening or closing.
- Wait for a little while till they are imported.
- Now that we have all the door images uploaded to the project. You can remove the plain backdrop.
- Make sure that you have selected the first costume of the door, if not will look for the same in the future.
- Now, let’s move Tobi to the bottom left corner.
- Let’s add a small button using the ball in our case.
- 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.
The final setup will look like this.
Storing the Face into the System
Let’s begin by writing the script to feed our face into the memory.
- Thus, click on Tobi’s sprite.
- Place when space key pressed block from the Events palette, and choose space from the drop-down.
- Now, we need Tobi to instruct the user to look into the camera.
- Thus, place a say block from the Looks palette, and write “Please look into the camera” in the space given.
- To make Tobi say it out loud, place speak block from the text-to-speech palette and write the same in it.
- 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.
- We need the camera to analyze, thus add a wait block from the Controls palette and write 3 in the space given.
- Let’s ask the user to wait for a little while.
- Duplicate the pair of say and speak blocks and write Analysing in both spaces.
- In this case, we will add the user image as the class.
- Thus, place add class 1 as from camera and write the user name into the space given.
- 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.
- 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:
Making Tobi Conversate
Now, let’s start with writing the script for introducing Tobi to the users.
- To execute the program every time the green flag is clicked, place a when flag clicked hat block from the Events palette.
- 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.
- Next, from the text-to-speech palette, place a set voice to block and choose tenor from the drop-down.
- 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.
- Now, let’s make Tobi conversate.
- Place a say block from the Looks palette, and write Hello! I am Tobi in the space given.
- To make Tobi say it out loud, place speak block from the text-to-speech palette and write the same in it.
- 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.
- Place switch backdrop block from the Looks palette and choose door_1 from the drop-down.
- 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.
- 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:
Unlocking the Door Using Face Detection
Now, let’s write the script for what happens when the button is clicked.
- Thus, go to the ball sprite. You can rename it if you want.
- When this sprite is clicked, we need to broadcast the message that the user is trying to access the door.
- Thus, place when this sprite clicked hat block from the Events palette.
- 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.
- Thus, go back to the Tobi Sprite.
- Drag and drop the broadcast message hat block and choose Door Access from the drop-down.
- 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.
- Now, let’s turn the camera ON. Thus, place the turn on video on stage with 0 % transparency block.
- We need the camera to analyze, thus add a wait block from the Controls palette and write 3 in the space given.
- Let’s ask the user to wait for a little while.
- Duplicate the pair of say and speak block and write Analysing in both the spaces given.
- 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.
- Now, if the face is matched, we need Tobi to say that the face matched and the door to open.
- Thus, place an if-else block from the Events palette.
- Place is 1 class detected from the Artificial Intelligence palette.
- 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.
- You can make Tobi say your name too if you want to.
- Now, to make the Door open. Place a repeat block and write 12 in the space given.
- Place the next backdrop block from the Looks palette.
- To make the backdrop change visible place a wait of 0.1 seconds.
- 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.
- 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.
- 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.
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.