Introduction: Expression Recognizer Using Face Detection in PictoBlox- a Scratch Based Graphical Programming Software

About: STEMpedia is a place bringing project-making tools at one place- kits, online courses, coding platforms, controller app and tons of free learning resources.

With the age of AI ahead us, nowadays the face detection software is used in almost every field from mobile devices to snap chat face filters to various security applications. Now that you can learn and make projects on AI using PictoBlox, will be using the face detection extension of the PictoBlox that helps you recognize faces, their age, expressions, gender, location, and many other features. In this tutorial, we will be making a script to recognize the expressions/emotion of the human face. You can download PictoBlox from here.

Ready. Set. Code.

Register here for free webinar on Artificial Intelligence for Kids.


Prerequisites are:

  • A PC/Laptop with a Working camera/webcam
  • PictoBlox Software
  • Good Internet Connectivity

Step 1: Setting Up the Software

Now that we have the latest version, let’s begin by adding the Face Recognition Extension.

  • First, select the board as evive.
  • Next, click on the Add extension button.
  • Once clicked you will be able to see all the extensions available.
  • Select Face Detection Detection.

Step 2: Setting Up the Stage

Let’s add our sprite into the project first.

  1. Click on add sprite button (Fig 1)
  2. Add the square box sprite
  3. You can delete The Tobi sprit, simply right click on it and select delete from the drop-down.

Step 3: Writing the Script to Detect Expressions in PictoBlox.

Now select the Square box sprite to write the script.

  1. First, use the when flag clicked hat block to execute the program every time the green flag is clicked.
  2. Next, we will turn the camera ON, using turn ON video on stage with 0% transparency block.

  3. Next, to recognize to process the image projected on the stage. We will use the analyse image from () block.

  4. Once the image is recognized, you can have all the data obtained from the image stored in the memory which we can use later on when and where required.
  5. Next, we will move our square box to the location of our recognized face using go to x () and y () block.
  6. Now, to detect the location of the face, we will use the get () of face () block from the face detection palette.

  7. We need the square box sprite to say out the expression of the face, thus drag and drop say () for () seconds block.

  8. Now, to recognize the expression we use get expression of face() block into the space given of the say block. This block gathers all the information of the face like age, gender, and expression.Finally, if you wish to run the script forever, use the forever block from the Controls Palette. The complete script looks like.

Step 4: Conclusion

Click on the green flag button and wait for the script to recognize and display the emotion of a person on the stage.