Leçon 1, Chapitre 1
En cours

Détecteur expressions faciales en python

Yann KIDSHAKER 17 mars 2025

Face Expression Detector Overview

In this project, we will make a script that detects the face using the camera and reports the expression of the faces detected on the stage.

Emotion

Face Detection

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.

The method of face detection in pictures is complicated because, well, human faces are widely different from one another! They can have different poses, expressions, positions, orientation, skin color, have glasses or facial hair or not, etc. Then are also differences in camera gain, lighting conditions, and image resolution.

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

face detection

Let’s Code!

The code is pretty simple, let’s get straight into it, follow the below steps:

  1. Open Pictoblox and choose the Python (beta) coding interface. Now, select the Tobi.py file from the Project Files section and by default, the syntax will be written in sprite as an object.
    sprite = Sprite('Tobi')
  2. Now create an object named fd to get access to the Face Detection extension and its methods.
    fd = FaceDetection()
  3. Next, we will use the various face detection function to turn on the video, enable the bounding box, and set the threshold.
    fd.video("on", 0) #to turn on video with 0% transparency
    fd.enablebox() #to enable bounding box
    fd.setthreshold(0.4) #to set the threshold at 0.4
  4. Now we will code to check the condition to get the expression of the face detected and if none is detected then print “No face detected”. We will use an if-else conditional statement under a while loop. To check if the count of face detected is more than 0 then Tobi sprite will say the expression detected.
while True:
  fd.analysecamera()
  
  if fd.count() > 0:
    sprite.say(fd.expression())
    
  else:
    sprite.say("No Face Detected")
  1. Here is the complete code:
sprite = Sprite('Tobi') 

fd = FaceDetection() 

fd.video("on", 0) 
fd.enablebox() 
fd.setthreshold(0.4)

while True: 
  fd.analysecamera() 
  if fd.count() > 0: 
    sprite.say(fd.expression())
  else: 
    sprite.say("No Face Detected")

Assignment

Before you move on to the next lesson, a small assignment awaits you!

You must upload the PictoBlox program you created in this activity to the website. Submitting the assignment is a must in order to receive the certificate after completing the course.

Follow the steps below to upload your assignment:

  1. Click on Browse.
  2. Search and Select your saved Project file(.sb3) and Click Open.
  3. Click on Upload to submit the assignment.
evive Alert
The file type allowed is the SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.

Good luck!