AI Vision with PictoBlox, lesson 6 of 15
Who's at the door? Face recognition
Introduction
Face detection finds a face. Face recognition goes one step further: it works out whose face it is. That's how a phone knows it's you and not your brother.
In this lesson you'll build a pretend smart doorbell. It learns the faces of people in your family, then greets each one by name, and says "Stranger!" for anyone it doesn't know.
The model measures the face (eyes, nose, jaw) and finds the closest learned face: Asha. Door opens!
Working principle
- Add class as (name) from (camera) takes a photo of the face in front of the camera and saves it under a name. Each person is one class.
- Do face matching on (camera) looks at the face in front of the camera and compares it with every saved class.
- Get class of face detected reports the name of the closest match.
- Is class detected (name)? is a true/false block for one person.
- Reset class deletes every saved face.
- The saved faces are stored inside your project file, so only save faces of people who said yes.
What you'll need
- PictoBlox with the Face Detection extension
- A webcam
- Two or three family members who have agreed to take part
Working in real life
Step 1: ask first. Faces are personal. Ask each person: "Can I save your face in my project? I'll delete it when we're done." Only add people who say yes.
- Add the Face Detection extension and make a sprite called Doorbell (a door or a bell from the sprite library).
- Build the training scripts below. Each key saves a face for one person. Press each key three or four times while that person looks at the camera, turning their head a little each time.
- Build the doorbell script. Click the green flag and let each person walk up to the camera.
Code
Training (one script per person; change the key and the name):
when [a] key pressed
add class as [Amma] from [camera]
say [Saved Amma] for (1) seconds
when [b] key pressed
add class as [Papa] from [camera]
say [Saved Papa] for (1) seconds
when [r] key pressed
reset class
say [All faces deleted] for (2) secondsThe doorbell:
when green flag clicked
turn [on] video on stage with (0) % transparency
forever
analyse image from [camera]
if <(get # faces) > (0)> then
do face matching on [camera]
say (join [Welcome home, ] (get class of face detected))
else
say [Nobody at the door]
end
wait (1) seconds
endIf someone who isn't saved walks up, the model still picks the closest match. Try it: does it call a visitor by the wrong name? Real smart doorbells only accept a match when it is very close, and they are trained with many more photos.
Try it
- Play a different sound for each person.
- Make the doorbell say "Stranger!" when is class detected (Amma) and is class detected (Papa) are both false.
- When you've finished, press r to delete the faces, and save your project.
Check what you learnt
What's the difference between face detection and face recognition?
Before saving someone's face in your project you should…
A stranger walks up, and the doorbell says 'Welcome home, Papa'. Why?
Conclusion
- Face recognition compares a face with saved faces and picks the closest match.
- Each person you teach it is called a class, and a few photos from different angles make it more reliable.
- Faces are personal data: ask before saving one, and delete it when you're done.
What next?
Now let the computer see your whole body: Catch the stars: body pose detection.

