Skip to content

Face mesh generator using the BlazeFace Mediapipe model with a CPU delegate written in C++

License

Notifications You must be signed in to change notification settings

CLFML/Face_Mesh.Cpp

Repository files navigation

Face Mesh.Cpp

Face mesh generator using the Face Mesh Mediapipe model with a CPU delegate written in C++

  • Plain C/C++ implementation with minimal dependencies (Tensorflow Lite + OpenCV)
  • Google MediaPipe models without the MediaPipe framework
  • Runs on ARM

API Features

This library offers support for:

  • 3D Face Landmarking (468 points)

3D Face Landmarking

This is some example code for face landmarking:

/* Create instance of FaceMesh detector */
CLFML::FaceMesh::FaceMesh mesh_det;

/* Initialize model interpreter */
mesh_det.load_model(CFML_FACE_MESH_CPU_MODEL_PATH);

/* Load the image into the model and run inference */
mesh_det.load_image(cam_frame);

/* Get the 3D Face landmarks */
std::array<cv::Point3f, CLFML::FaceMesh::NUM_OF_FACE_MESH_POINTS> face_mesh_keypoints = mesh_det.get_face_mesh_points();

Example code

For a full example showcasing both these API functions see the example code in example/face_mesh_demo/demo.cpp.

Building with CMake

Before using this library you will need the following packages installed:

  • OpenCV
  • Working C++ compiler (GCC, Clang, MSVC (2017 or Higher))
  • CMake
  • Ninja (Optional, but preferred)

Running the examples (CPU)

  1. Clone this repo
  2. Run:
cmake . -B build -G Ninja
  1. Let CMake generate and run:
cd build && ninja
  1. After building you can run (linux & mac):
./face_mesh_demo

or (if using windows)

face_mesh_demo.exe

Using it in your project as library

Add this to your top-level CMakeLists file:

include(FetchContent)

FetchContent_Declare(
    face_mesh.cpp
    GIT_REPOSITORY https://github.com/CLFML/Face_Mesh.Cpp
    GIT_TAG main
    # Put the Face_Mesh lib into lib/ folder
    SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/Face_Mesh.Cpp
)
FetchContent_MakeAvailable(face_mesh.cpp)
...
target_link_libraries(YOUR_EXECUTABLE CLFML::face_mesh)

Or manually clone this repo and add the library to your project using:

add_subdirectory(Face_Mesh.Cpp)
...
target_link_libraries(YOUR_EXECUTABLE CLFML::face_mesh)

Building a ROS2 package with Colcon

Before using this library you will need the following packages installed:

  • OpenCV
  • ROS2
  • ROS CV bridge
  • Working C++ compiler (GCC or Clang)
  • CMake

Running the examples (Ubuntu, CPU)

  1. Clone this repo:
git clone https://github.com/CLFML/Face_Mesh.Cpp.git
  1. Source your ROS2 installation:
source /opt/ros/jazzy/setup.bash
  1. Install the dependencies:
rosdep install --from-paths src -y --ignore-src
  1. Build the package:
colcon build --packages-select face_mesh
  1. Set up the environment:
source install/setup.bash
  1. Run the camera node:
ros2 run v4l2_camera v4l2_camera_node
  1. In another terminal, run the nodes
ros2 launch example/ros2/launch.py

Aditional documentation

See our wiki...

Todo

  • Add language bindings for Python, C# and Java
  • Add support for MakeFiles and Bazel
  • Add Unit-tests
  • Add support for the Face Mesh V2 model

License

This work is licensed under the Apache 2.0 license.

The face_mesh model is also licensed under the Apache 2.0 license.

About

Face mesh generator using the BlazeFace Mediapipe model with a CPU delegate written in C++

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published