Skip to content

zihaomu/mediapipe_cmake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MediaPipe CMake

License CMake C++ Platform

A high-performance, CMake-based reimplementation of Google MediaPipe for edge devices

Features β€’ Demo β€’ Quick Start β€’ Performance β€’ Documentation


🎯 Overview

MediaPipe is an excellent framework containing many AI model engineering implementations for edge environments. However, the official MediaPipe only supports Bazel build system, which is incompatible with CMake - the commonly used build system in edge computing.

MediaPipe CMake reimplements MediaPipe from scratch using CMake, providing developers with:

  • βœ… CMake Build System - Easy integration with existing CMake projects
  • βœ… Enhanced Performance - Up to 40% faster than official implementation (using MNN backend)
  • βœ… Pure C++ Implementation - No overhead, optimized for production
  • βœ… Multi-Platform Support - Linux and Android (ARM32/ARM64)
  • βœ… Powered by OpenCV_lite - Lightweight inference engine with MNN backend

✨ Features

This project focuses on reproducing MediaPipe's Vision capabilities with the following components:

Category Feature Models Status
πŸ‘€ Face Face Detection BlazeFace βœ…
πŸ‘€ Face Face Landmarks 468/478 points βœ…
πŸ‘€ Face Face Blendshapes - 🚧 WIP
πŸ–οΈ Hand Hand Detection - βœ…
πŸ–οΈ Hand Hand Landmarks 21 points 3D βœ…
🧍 Pose Pose Detection - βœ…
🧍 Pose Pose Landmarks 33 points 3D βœ…
🧍 Holistic Holistic Tracking Face + Hand + Pose βœ…
πŸ‘οΈ Iris Iris Tracking Eye + Iris βœ…
🎨 Segmentation Selfie Segmentation - βœ…
🎨 Segmentation Hair Segmentation - βœ…
🎨 Segmentation Interactive Segmentation - βœ…

🎬 Demo

This project faithfully reproduces the complete MediaPipe processing pipeline. Below are visual demonstrations of each capability:

Face Detection & Landmarks

Face Detection Face 3D Landmarks (468/478 points)

3D landmark was show by Open3D, and the script can be found at './viz_face_by_open3d.py'

Hand Landmarks

Hand 3D Landmarks (21 points)

3D landmark was show by Open3D, and the script can be found at './viz_hand_by_open3d.py'

Pose Landmarks

Pose 3D Landmarks (33 points)

3D landmark was show by Open3D, and the script can be found at './viz_pose_by_open3d.py'

Iris Tracking

Iris & Eye Tracking

Interactive Segmentation

Interactive Segmentation

πŸš€ Performance

Compared to the official MediaPipe implementation:

  • Face Landmarks: ~40% faster
  • CPU Optimized: MNN backend significantly outperforms TFLite on CPU
  • Memory Efficient: Pure C++ with minimal overhead
  • Production Ready: Optimized for real-time edge deployment, C and C++ API

πŸš€ Quick Start

Prerequisites

  • CMake 3.10 or higher
  • C++14 compatible compiler
  • Git

Building from Source

Step 1: Clone Repositories

# Clone opencv_lite (dependency)
git clone https://github.com/zihaomu/opencv_lite.git

# Clone this project
git clone https://github.com/zihaomu/mediapipe_cmake.git

Step 2: Build opencv_lite

The opencv_lite library includes integrated MNN backend for inference.

cd opencv_lite
mkdir build && cd build
cmake ..
make -j$(nproc)

Step 3: Configure MediaPipe CMake

Edit mediapipe_cmake/CMakeLists.txt and set your opencv_lite build path:

# Line 15 in CMakeLists.txt
set(OpenCV_DIR "/path/to/your/opencv_lite/build")

Step 4: Build MediaPipe CMake

cd mediapipe_cmake
mkdir build && cd build
cmake ..
make -j$(nproc)

Step 5: Run Demo

# Example: Face landmark demo
./face_landmarker/face_landmarker_demo

# Example: Hand landmark demo
./hand_landmarker/hand_landmark_demo

# Example: Pose landmark demo
./pose_landmarker/pose_landmark_demo

Building for Android

Compile OpenCV lite for android platform, please reference How to compile opencv-lite on android.

For Android ARM64:

bash build_android_arm64.sh

For Android ARM32:

bash build_android_arm32.sh

Android Setup Requirements:

Organize your opencv_lite Android libraries as follows:

lib/
β”œβ”€β”€ arm64-v8a/
β”‚   β”œβ”€β”€ libMNN.so
β”‚   β”œβ”€β”€ libopencv_core.so
β”‚   β”œβ”€β”€ libopencv_dnn.so
β”‚   └── libopencv_imgproc.so
β”œβ”€β”€ armeabi-v7a/
β”‚   β”œβ”€β”€ libMNN.so
β”‚   β”œβ”€β”€ libopencv_core.so
β”‚   β”œβ”€β”€ libopencv_dnn.so
β”‚   └── libopencv_imgproc.so
└── include/opencv2/

πŸ“š Documentation

Each module includes detailed documentation:

C API Support

Several modules provide C API for easier integration:

  • face_landmark_c_api.h
  • hand_landmark_c_api.h
  • pose_landmark_c_api.h

Visualization Tools

Python visualization scripts using Open3D:

πŸ—ΊοΈ Roadmap

  • Add face blendshapes support
  • Support MNN backend for selfie segmenter
  • Enhanced smoothing strategies for pose landmarks
  • Optimize holistic tracker performance
  • Flutter pose landmark demo
  • 3D object detection
  • Detailed reproduction guides for each AI capability
  • Add a all-in-one SDK module, unified interface, C/C++.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“§ Contact

For questions and support, please open an issue on GitHub.


If you find this project helpful, please consider giving it a ⭐!

About

Try to reproduce mediapipe with OpenCV_lite and MNN.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published