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.
Working with PictoBlox
As the title of the tutorial itself suggests, we will be making this project in PictoBlox- a scratch based graphical programming software. Follow these steps and make your own expression recognition machine.
Setting up the Software
As you like to be up-to-date, so does the software. To use the face detection extension of PictoBlox, you need to update PictoBlox to its latest version. You can download it from here.
Adding Up the Extension
Now that we have the latest version, let’s add the Face Recognition.
- First, select the board as evive.
- Next, click on the add extension button
- Once clicked you will be able to see all the extension available,
- Select Face Detection
You will notice new blocks are being added under the same extension
Please remember that this extension requires an Internet connection in order to process images. Also, wait till models get loaded it might take a few moments to load.
What will you need
- A pc/laptop with a camera.
- Internet connection.
- A webcam.
Writing the Script in PictoBlox
Now, that everything is ready. let’s start writing the script.
Before we begin, let’s add our sprite into the project first.
- Click on add sprite button
- Add the square box sprite
- You can delete The Tobi sprit, simply right click on it and select delete from the drop-down.
Completing the script
Now select the Square box sprite to write the script.
- First, drag and drop the when flag clicked hat block to execute the program every time the green flag is clicked.
- Next, to turn the camera ON, use turn ON video on stage with 0% transparency block.
- Next, we need to recognize the image. Thus, we now need to process the image projected on the stage. We will use the analyse image from () block and as we are using a camera on stage, we will choose the stage option from the drop-down
- Once the image is recognized, you can have all the data obtained from the image stored in the memory which you can use later on when and where required.
- Next, we need to add an outline to be marked around the face. Thus, in order to show that the face is recognized, we will move our square box to the location of our recognized face. We will be using go to x () and y () block from the Motion Palette for the same.
- Next, to move the box around the face, we need the X and Y position of the face. Thus, we will use the get () of face () block from the face detection palette, this block contains all the details including the size and the location of the face.
- Drop each in the white spaces of the go to x () and y () block and select x-position from the first drop-down and y-position from the second drop-down.
- Now that we have recognized the face and located its position it’s now time to recognize the expression of the face.
- We need the square box sprite to say out the expression of the face, thus drag and drop say () for () seconds block below the go to x () y () block.
- 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.
You can download the script from here.
If you wish to learn how to recognize the expression of multiple faces or how to use artificial intelligence and machine learning with PictoBlox, you can try out our artificial intelligence for kids course. Visit the link here to know more about the course.