update readme and docs

This commit is contained in:
Jules Youngberg 2022-06-12 17:25:42 -07:00
parent e7b7211a1f
commit 29ac9c99de
2 changed files with 23 additions and 8 deletions

View File

@ -1,8 +1,9 @@
# mediapipe-rs # mediapipe-rs
Rust and mediapipe. Simple rust bindings for mediapipe.
Mediapipe is a framework for building AI-powered computer vision and augmented reality applications. It provides high level libraries exposing some of its solutions for common problems. This package makes some of these solutions available in Rust. In order to use it we must build a custom mediapipe C++ library. Forked from: https://github.com/angular-rust/ux-mediapipe 🙏
And heavily based on this example: https://github.com/asprecic/mediapipe-qt-integration-example 🤌
## requirements ## requirements
@ -10,7 +11,9 @@ Mediapipe is a framework for building AI-powered computer vision and augmented r
## setup ## setup
Clone the modified Mediapipe repo: Mediapipe is a framework for building AI-powered computer vision applications. It provides high level libraries exposing some of its solutions for common problems. This package makes some of these solutions available in Rust. In order to use it we must build a custom mediapipe C++ library.
Clone the modified Mediapipe repo.
```shell ```shell
git clone https://github.com/julesyoungberg/mediapipe.git git clone https://github.com/julesyoungberg/mediapipe.git

View File

@ -5,10 +5,9 @@
#![allow(improper_ctypes)] #![allow(improper_ctypes)]
#![allow(deref_nullptr)] #![allow(deref_nullptr)]
// ------------------------------------------------------------------------------------------------- //! This library brings Google's Mediapipe to Rust.
// LINKING
// -------------------------------------------------------------------------------------------------
// LINKING
#[link(name = "mediagraph")] #[link(name = "mediagraph")]
extern "C" {} extern "C" {}
@ -17,7 +16,7 @@ use std::ffi::CString;
mod bindings; mod bindings;
pub use bindings::*; use bindings::*;
type GraphType = mediagraph_GraphType; type GraphType = mediagraph_GraphType;
pub type Landmark = mediagraph_Landmark; pub type Landmark = mediagraph_Landmark;
@ -34,6 +33,8 @@ impl Default for Landmark {
} }
} }
/// Represents a detected pose, as 33 landmarks.
/// Landmark names are in [pose::PoseLandmark].
pub struct Pose { pub struct Pose {
pub data: [Landmark; 33], pub data: [Landmark; 33],
} }
@ -46,6 +47,8 @@ impl Default for Pose {
} }
} }
/// Represents a detected hand, as 21 landmarks.
/// Landmark names are in [hands::HandLandmark]
pub struct Hand { pub struct Hand {
pub data: [Landmark; 21], pub data: [Landmark; 21],
} }
@ -58,6 +61,7 @@ impl Default for Hand {
} }
} }
/// Represents a detected face mesh, as 478 landmarks.
pub struct FaceMesh { pub struct FaceMesh {
pub data: [Landmark; 478], pub data: [Landmark; 478],
} }
@ -70,7 +74,7 @@ impl Default for FaceMesh {
} }
} }
struct Mediagraph { pub struct Mediagraph {
graph: *mut mediagraph_Mediagraph, graph: *mut mediagraph_Mediagraph,
num_landmarks: u32, num_landmarks: u32,
} }
@ -117,8 +121,10 @@ impl Mediagraph {
} }
pub mod pose { pub mod pose {
//! Pose detection utilities.
use super::*; use super::*;
/// Pose landmark indices.
pub enum PoseLandmark { pub enum PoseLandmark {
NOSE = 0, NOSE = 0,
LEFT_EYE_INNER = 1, LEFT_EYE_INNER = 1,
@ -180,6 +186,7 @@ pub mod pose {
} }
} }
/// Processes the input frame, returns a pose if detected.
pub fn process(&mut self, input: &Mat) -> Option<Pose> { pub fn process(&mut self, input: &Mat) -> Option<Pose> {
let landmarks = self.graph.process(input); let landmarks = self.graph.process(input);
@ -201,6 +208,7 @@ pub mod pose {
} }
pub mod face_mesh { pub mod face_mesh {
//! Face mesh utilities.
use super::*; use super::*;
pub struct FaceMeshDetector { pub struct FaceMeshDetector {
@ -233,6 +241,7 @@ pub mod face_mesh {
} }
} }
/// Processes the input frame, returns a face mesh if detected.
pub fn process(&mut self, input: &Mat) -> Option<FaceMesh> { pub fn process(&mut self, input: &Mat) -> Option<FaceMesh> {
let landmarks = self.graph.process(input); let landmarks = self.graph.process(input);
@ -254,8 +263,10 @@ pub mod face_mesh {
} }
pub mod hands { pub mod hands {
//! Hand detection utilities.
use super::*; use super::*;
/// Hand landmark indices.
pub enum HandLandmark { pub enum HandLandmark {
WRIST = 0, WRIST = 0,
THUMB_CMC = 1, THUMB_CMC = 1,
@ -305,6 +316,7 @@ pub mod hands {
} }
} }
/// Processes the input frame, returns a tuple of hands if detected.
pub fn process(&mut self, input: &Mat) -> Option<[Hand; 2]> { pub fn process(&mut self, input: &Mat) -> Option<[Hand; 2]> {
let landmarks = self.graph.process(input); let landmarks = self.graph.process(input);