Face Detection

Face DetectionRoutine Experiment EffectCode ExplanationCode structureImport related dependency classesCustom face detection classPerforming face detectionA brief introduction to face detection algorithmsCommon application scenariosAlgorithm Overview

 

Routine Experiment Effect

In this section, we will learn how to use K230 to implement face detection.

The code in this section is in [Source code/07.Face/01.face_detection.py]

After connecting to the IDE, run the example code in this section and aim the K230 at the face. You can see that the positions of all faces are framed in the middle of the screen.

image-20250210120145878

Serial port output function has been added

After detecting a face, the following serial output will be sent

$x,y,w,h#

The '$' represents the beginning of the data, and the '#' represents the end of the data.

x, y, w, h are the positions of the face detection frame (resolution is 640*480)

Code Explanation

Code structure

Import related dependency classes

Custom face detection class

Performing face detection

A brief introduction to face detection algorithms

Common application scenarios

Face detection is also the basis for subsequent face recognition, face key point recognition and other functions.

Camera App

Image Processing

Statistical analysis

Camera Control

Algorithm Overview

Common face detection algorithms can be roughly classified into the following two types:

  1. Viola-Jones algorithm (classic method)

    • Face pattern recognition using Haar features
    • Using integral graph to accelerate feature calculation
    • Building a strong classifier using AdaBoost
    • Using cascade classifiers to improve efficiency
  2. Deep learning based methods

    • CNN convolutional neural network extracts features
    • Multi-scale detection to handle faces of different sizes
    • Anchor box predicts the face position
    • Confidence score determines whether it is a face

In the example, we use a method based on deep learning. We first use a pre-trained deep learning model (.kmodel file), and then set 4200 anchor boxes in the code to predict the face position.

In the post-processing step, we filter the detection results using a confidence threshold (confidence_threshold) and then use non-maximum suppression (NMS) to eliminate overlapping boxes.

The example code is optimized for the Yabo Intelligent K230 hardware platform and uses the nncase runtime library to run the deep learning model.