Age, Gender and Emotion Detection: Face Recognition – AI in PictoBlox

Gender, Emotion, Age Detector in Scratch
Description
Learn to make a script in PictoBlox that detects faces in an image and reports the age, gender and emotion of each face. Follow this tutorial to understand the concept of face detection, how it works, and the requirements for making a facial recognition script.

In today’s world, Face recognition is widely used everywhere from the face unlock feature of a smartphone to smile detection in digital cameras to detect faces in real-time for surveillance or even to tag people in pictures over social media platforms like Facebook. Hence, in this tutorial, we will make a script in PictoBlox that detects the face using the camera and reports the age, gender, and emotion of the person.

Face Detection

Before we let’s understand what Face detection is and how it works.

In the past few years, face recognition has become one of the most promising applications of computer vision. Face detection can be considered to be a substantial part of face recognition operations.

Face detection is the action of locating human faces in an image and optionally returning different kinds of face-related data.

How Facial Recognition Works?

First, a face is analyzed from a captured image, its geometrical properties, size, and position are obtained. Then a structure is generated that forms a pattern that is later stored in a database. Once stored, the user’s facial record is compared with the biometric features of each face that is scanned and allows adding new templates to make the recognition more effective. If the image matches a search, the system will alert us that a match has been found.

Face Detection

Requirements:

Making Script in PictoBlox

Now, we know what Face detection is and how it works. So, Let’s make a script in PictoBlox that detects the face using the camera and reports the age, gender, and emotion of the person.

Before making a script make sure your device has connected to the Internet. Because we are going to use the Artificial Intelligence extension of PictoBlox and it will work only if your device is connected to the internet.

Let’s Begin!

  • Create a new project in PictoBlox.
  • Select evive as your board from the Board tab in the menu bar.
  • Next, click on the Add Extension button and add Artificial Intelligence extension.AI Extension of PictoBlox (Scratch)

Setting Up the Stage

  • Add the Square Box sprite and delete the Tobi Sprite.Adding New Sprite
  • Make the following script to hide the Square Box and turn on the camera feed.Face Detector Script
  • The stage is set. Click the green flag to get the camera feed on the stage.

Recognizing the Image

  • Below the previous script, add a wait block and then snap the image recognization block. 
  • Select face details from the first dropdown and set the feed as the stage from the second dropdown.
  • Now, Your script will look like the following script.Face Detector Script
  • Click on the Green flag to run and test the script.
  • Drag and drop the recognized face count block to the scripting area and click on it. It will report to you the number of faces detected.Recognizing face counts Recognizing face counts

Detecting every face in the image

  • Make a new variable called Face.Making variables
  • We will continue with the previous script, set the initial value of the Face variable as 0.
  • Now we use a loop and change value of Face by 1 until the value of Face becomes equal to the faces in the recognized image.Face Detector Script

Displaying Square Box around the faces

  • Now, we will bound the faces by showing the Square Box around them, Hence the box should point towards the face and its parameter i.e. size, coordinates should be as per the face.
  • To do so, add the few more block as shown in the following script.Face Detector Script

Reporting the Age, Gender, and Emotion

And last but not least.

  • Add three more blocks to display Age, Gender, and Emotion and a hide block to disappear the box in the end.
  • Complete the script as shown below.Face Detector ScriptYou can download the entire code from here.
  • Your script is now complete. Click the green flag to start the script.Gender, Emotion, Age Detector in Scratch

Hope you enjoyed the tutorial, we also developed an online course on Artificial Intelligence covering all detailed concepts for smart kids like you. So for what you are what for? Enroll now and get yourself certified.

Conclusion

In this lesson, we learned how to make a script in PictoBlox that detects the face using the camera and reports the age, gender, and emotion of the person. We went through the concept of face detection, how it works, and the requirements for making a facial recognition script. We then made a script that detects the faces in the image and displays the age, gender, and emotion of each face. We also learned how to show a square box around the face and how to change the parameters of the box according to the face. 

Table of Contents