Face Detection

Extension Description
Detects and recognizes human faces with face landmark detections.

Introduction

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

Face Detection in PictoBlox

PictoBlox uses feature-based detection to detect faces. Face landmarks are a set of easy-to-find points on a face, such as the pupils or the tip of the nose. By default, there are 68 predefined landmark points. The following image shows all landmark points:

Face Landmarks

Users can detect facial expressions using machine learning and algorithms to see emotions and recognize 6 basic facial or universal expressions in human faces. It does this by analyzing faces in images or video through cameras.

Face Recognition in PictoBlox

Face recognition systems allow programs to identify a person by analyzing the face landmarks of her/his face in a digital image.

PictoBlox allows you to run face recognition using the following process:

  1. When a face is analyzed, its geometrical properties, size, and position are obtained.
  2. A structure is generated that forms a pattern that is later stored in a database.
  3. 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.
  4. If the image matches a search, the system will alert us that a match has been found.

Face Detection

Accessing Face Detection in Block Coding

Following is the process to add Face Detection capability to the PictoBlox Project.

  1. Open PictoBlox and create a new file.
  2. Select the coding environment as Block Coding.
  3. Next, click on the Add Extension button and add the Face Detection extension.
  4. The face detection models will be downloaded, which may take a few seconds to load.
    Downloading Models
  5. Once downloaded you will get a message saying “Model loaded successfully”.
  6. You can find the face detection blocks available in the project.

Accessing Face Detection in Python Coding

Following is the process to add Face Detection capability to the PictoBlox Project.

  1. Open PictoBlox and create a new file.
  2. Select the coding environment as Python Coding.
  3. Next, click on the Add Modules/Libraries button and add the Face Detection extension.
  4. To access the library functions, you have to add the object declaration.
    fd = FaceDetection()

Python Functions

The function is used to control the state of the camera.
Syntax: video(video_state = “on”, transparency = 1)
The function enables the automatic display of the box on face detection on the stage.
Syntax: enablebox()
The function disables the automatic display of the box on face detection on the stage.
Syntax: disablebox()
This function is used to set the threshold for the confidence (accuracy) of face detection, 0 being low confidence and 1 being high confidence.
Syntax: setthreshold(threshold = 0.5)
This function is used to analyze the image received as input from the camera, for faces.
Syntax: analysecamera()
This function is used to analyze the image received as input from the stage, for faces.
Syntax: analysestage()
This function displays the total number of faces detected in the camera feed or the stage.
Syntax: count()
This function is used to get the expression of the analyzed face. The parameter can be used to select the identifying number of the face whose expression is to be analyzed.
Syntax: expression(face = 1)
This function is used to check whether the expression of the face number specified in the argument is equal to the specified expression. Like is the face 1 happy?
Syntax: isexpression(face = 1, expression = “happy”)
This function returns the x position of the face detected. You can specify the face for which the value is needed. The position is mapped with the stage coordinates.
Syntax: x(face = 1)
This function returns the y position of the face detected. You can specify the face for which the value is needed. The position is mapped with the stage coordinates.
Syntax: y(face = 1)
This function returns the width of the face detected. You can specify the face for which the value is needed. The position is mapped with the stage coordinates.
Syntax: width(face = 1)
This function returns the height of the face detected. You can specify the face for which the value is needed. The position is mapped with the stage coordinates.
Syntax: height(face = 1)
The function returns the x position of the specified landmark point of the specified face with respect to the stage.
Syntax: landmarksx(face = 1, landmark = 1)
The function returns the y position of the specified landmark point of the specified face with respect to the stage.
Syntax: landmarksy(face = 1, landmark = 1)
The function allows the user to add a particular face into the database from the camera feed. The user can specify the name of the face with the argument as well. This addition of the face in the database is also stored inside the PictoBlox file while saving.
Syntax: addclassfromcamera(label_number = 1, label_name = “Jarvis”)
The function allows the user to add a particular face to the database from the stage. The user can specify the name of the face with the argument as well. This addition of the face in the database is also stored inside the PictoBlox file while saving.
Syntax: addclassfromstage(label_number = 1, label_name = “Jarvis”)
The function deletes all the stored databases of the images for face recognition. 
Syntax: deleteallclass()
This function is used to match the input image from the camera with the stored classes previously stored in the database. 
Syntax: recognisefromcamera()
This function is used to match the input image from the stage with the stored classes previously stored in the database. 
Syntax: recognisefromstage()
This function is used to check if the input image belongs to one of the classes previously defined. The class to be checked with can be set using the argument as label_number.
Syntax: isclassdetected(label_number = 1)
This function is used to get the class of the input face detected from the analysis. The identifying number of the face being analyzed can be set using the argument.
Syntax: getclassname(face = 1)
All articles loaded
No more articles to load

Python Coding Examples

PictoBlox Blocks

Turn () video on stage with () % transparency block controls the control the camera feed on the stage.
The function enables or disables the automatic display of the box on face detection on the stage.
This block is used to set the threshold for the confidence (accuracy) of face detection, 0 being low confidence and 1 being high confidence. With the threshold value, you can set the level of confidence required for face detection.
The block analyses the image and saves the face information locally, which can be accessed using other blocks similar to computer vision.
Once you have analyzed the images, you can use the get # faces block to get the number of faces recognized in the image.
The get expression of face () block reports the recognized expression of the selected face. If the face selected is not detected, then it reports NULL.
The is expression of face () () block checks whether the selected face has a particular emotion or not. If the emotion matches, then the block returns true; else, false.
The get () of face () block reports the following attributes of the face: x position, y position, width and height.
The get () position of () face () block reports the x and y position of the selected landmark of the selected face.
The get () position of landmark () of the face () block reports the x and y position of the selected landmark (number from 1 to 68) of the selected face.
The function allows the user to add a particular face into the database from the camera or stage. The user can specify the name of the face with the argument as well. This addition of the face in the database is also stored inside the PictoBlox file while saving.
The block deletes all the stored databases of the images for face recognition.
This block is used to match the input image from the camera or stage feed with the stored classes previously stored in the database. The block also stores all the face data in PictoBlox for access by other blocks.
This block is used to check if the input image belongs to one of the classes previously defined. The class to be checked with can be set using the drop down menu.
This block is used to get the class of the input face detected from the analysis. 
All articles loaded
No more articles to load

Block Coding Examples

Table of Contents