MediaPipe_Face_Detection

MediaPipe Face Detection

Face detection is a computer vision technique that involves identifying and locating human faces within an image or video. The goal of face detection is to detect the presence of faces and draw bounding boxes around them, without necessarily identifying specific facial features or landmarks.

mit
Object Detection
PyTorch
English
by @AIOZNetwork
3

Last updated: 20 days ago


Generic badge Generic badge

MediaPipe Face Detection

Summary

Introduction

Face Detection using the MediaPipe library is an advanced technology that enables accurate and efficient detection of human faces in images or videos. MediaPipe provides a comprehensive set of tools and algorithms for real-time multimedia processing, and Face Detection leverages these capabilities to identify and locate faces within visual data.

By utilizing the MediaPipe library, Face Detection offers robust and reliable face detection capabilities that can handle various real-world scenarios, including different lighting conditions, diverse facial appearances, and complex backgrounds. The model is trained on large-scale datasets, making it capable of detecting faces with high accuracy and speed.

Parameters

Inputs

  • input - (image -.png|.jpg|.jpeg): The input of the model is an image containing objects that are human faces and need to be identified.
  • model - (text): The input to the model allows users to select the model used for processing: Short-range model (best for faces within 2 meters) and Full-range model (best for faces within 5 meters)
  • confidence - (number): This is the value used to determine whether an object is considered a face or not. The threshold value can be adjusted to increase or decrease the detection accuracy. The threshold value is usually between 0 and 1.

Output

  • output - (image -.png): The output of the model is to detect and locate human faces within the image frame, typically represented as bounding boxes.

Examples

inputmodelconfidenceoutput
Short-range model (best for faces within 2 meters)0.85

Usage for developers

Please find below the details to track the information and access the code for processing the model on our platform.

Requirements

python~=3.10
torch~=2.0.0
mediapipe
opencv-python

Code based on AIOZ structure

import mediapipe as mp
import cv2

...
def do_ai_task(
        input: Union[str, Path],
        model: Union[str, Path],
        model_storage_directory: Union[str, Path],
        device: Literal["cpu", "cuda", "gpu"] = "cpu",
        *args, **kwargs) -> Any:
        
        image = cv2.imread(input)
        with mp_face_detection.FaceDetection(
                model_selection=model,
                min_detection_confidence=confidence
        ) as face_detection:
            results = face_detection.process(image)

        res = image[:, :, ::-1].copy()
        if results.detections is not None:
            for detection in results.detections:
                mp_drawing.draw_detection(res, detection)
        cv2.imwrite("output.png", res[:, :, ::-1])
        
        output_image = open("output.png", "rb")  # io.BufferedReader
    return output_image

Reference

This repository is based on and inspired by Hysts's work. We sincerely appreciate their generosity in sharing the code.

License

We respect and comply with the terms of the author's license cited in the Reference section.