Face detector using the BlazeFace Mediapipe model (with both CPU and TPU delegates) written in C++;
- Plain C/C++ implementation with minimal dependencies (Tensorflow Lite + OpenCV)
- Google MediaPipe models without the Mediapipe framework
- Support for Coral Edge TPU (not supported when using the ROS2 binding)
- Runs on ARM as well (Tested on RPI 3,4 and 5)
- ROS2 support
This library offers support for:
- Face detection
- Face ROI (Region of interest) detection
- 2D Landmarks of the Left eye, Right Eye, Nose tip, Mouth, Left eye tragion and Right eye tragion
This is some example code for face detection:
#define MODEL_PATH FACE_DETECTOR_MODEL_DIR "/CPU/face_detection.tflite"
...
/* Initialize face detector library */
CLFML::FaceDetection::FaceDetector det;
/* Load model and initialize inference runtime */
det.load_model(MODEL_PATH);
/* Load image into model and do inference! */
det.load_image(cam_frame);
/* Get face_detected value */
const int face_detected = det.detected(); // returns -1 for no face and 0 for face detected!
This is some example code for capturing the region of interest:
#define MODEL_PATH FACE_DETECTOR_MODEL_DIR "/CPU/face_detection.tflite"
...
/* Initialize face detector library */
CLFML::FaceDetection::FaceDetector det;
/* Load model and initialize inference runtime */
det.load_model(MODEL_PATH);
/* Load image into model and do inference! */
det.load_image(cam_frame);
/* Get the face roi rectangle */
cv::Rect face_roi = det.get_face_roi();
For a full example showcasing both these API functions see the example code in example/face_roi_demo/demo.cpp.
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)
- Clone this repo
- Run:
cmake . -B build -G Ninja
- Let CMake generate and run:
cd build && ninja
- After building you can run (linux & mac):
./face_roi_demo
or (if using windows)
face_roi_demo.exe
- Make sure you got:
- The newest libedgetpu library installed (based on TF 2.16.1); If not sure compile it from source!
- libusb-1.0-0-dev package or installed (only when using Linux)\
- When using Linux your udev configured correctly (is done automatically when compiling from source!)
- Clone this repo
- Run:
cmake . -B build -G Ninja -DFACE_DETECTOR_ENABLE_CORAL_TPU=ON
or add this block to your settings.json in vscode:
"cmake.configureSettings": {
"FACE_DETECTOR_ENABLE_CORAL_TPU": "ON"
}
- Let CMake generate and run:
cd build && ninja
- After building you can run (linux & mac):
./face_roi_demo
or (if using windows)
face_roi_demo.exe
Add this to your top-level CMakeLists file:
include(FetchContent)
FetchContent_Declare(
face_detector
GIT_REPOSITORY https://github.com/CLFML/Face_Detector.Cpp
GIT_TAG main
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/Face_Detector.Cpp
)
FetchContent_MakeAvailable(face_detector)
...
target_link_libraries(YOUR_EXECUTABLE CLFML::face_detector)
Or manually clone this repo and add the library to your project using:
add_subdirectory(Face_Detector.Cpp)
...
target_link_libraries(YOUR_EXECUTABLE CLFML::face_detector)
Before using this library you will need the following packages installed:
- OpenCV
- ROS2
- ROS CV bridge
- Working C++ compiler (GCC, Clang, MSVC (2017 or Higher))
- CMake
- Clone this repo:
git clone https://github.com/CLFML/Face_Detector.Cpp.git
- Source your ROS2 installation:
source /opt/ros/jazzy/setup.bash
- Install the dependencies:
rosdep install --from-paths src -y --ignore-src
- Build the package:
colcon build --packages-select face_detector
- Set up the environment:
source install/setup.bash
- Run the camera node:
ros2 run v4l2_camera v4l2_camera_node
- In another terminal, run the face detector node (don’t forget to source the setup script):
ros2 run face_detector face_detector_node
- In yet another terminal, run the viewer:
ros2 run face_detector face_detector_viewer
See our wiki...
- Add language bindings for Python, C# and Java
- Add support for MakeFiles and Bazel
- Add Unit-tests
- Add ROS2 package TPU support
- If needed to crunch ROS2 latency: Do not use nodes, put plugins in a container
This work is licensed under the Apache 2.0 license.