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.
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.
- A PC/Laptop with a working camera/webcam
- PictoBlox Software
- Internet Connectivity
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.
- 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.
Setting Up the Stage
- Add the Square Box sprite and delete the Tobi Sprite.
- Make the following script to hide the Square Box and turn on the camera feed.
- 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.
- 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.
Detecting every face in the image
- Make a new variable called Face.
- 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.
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.
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.
You can download the entire code from here.
- Your script is now complete. Click the green flag to start the script.
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.