rename mediagraph to detector

This commit is contained in:
Jules Youngberg 2022-06-12 22:12:19 -07:00
parent 51ec5928dc
commit 0a0ecbb93c
2 changed files with 96 additions and 47 deletions

View File

@ -72,71 +72,120 @@ fn bindgen_test_layout_mediagraph_Landmark() {
) )
); );
} }
pub const mediagraph_GraphType_POSE: mediagraph_GraphType = 0; pub const mediagraph_DetectorType_POSE: mediagraph_DetectorType = 0;
pub const mediagraph_GraphType_HANDS: mediagraph_GraphType = 1; pub const mediagraph_DetectorType_HANDS: mediagraph_DetectorType = 1;
pub const mediagraph_GraphType_FACE: mediagraph_GraphType = 2; pub const mediagraph_DetectorType_FACE: mediagraph_DetectorType = 2;
pub type mediagraph_GraphType = ::std::os::raw::c_uint; pub type mediagraph_DetectorType = ::std::os::raw::c_uint;
#[repr(C)] #[repr(C)]
pub struct mediagraph_Mediagraph__bindgen_vtable(::std::os::raw::c_void); pub struct mediagraph_Detector__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct mediagraph_Mediagraph { pub struct mediagraph_Detector {
pub vtable_: *const mediagraph_Mediagraph__bindgen_vtable, pub vtable_: *const mediagraph_Detector__bindgen_vtable,
pub m_graph_type: mediagraph_GraphType, pub m_graph_type: mediagraph_DetectorType,
} }
#[test] #[test]
fn bindgen_test_layout_mediagraph_Mediagraph() { fn bindgen_test_layout_mediagraph_Detector() {
assert_eq!( assert_eq!(
::std::mem::size_of::<mediagraph_Mediagraph>(), ::std::mem::size_of::<mediagraph_Detector>(),
16usize, 16usize,
concat!("Size of: ", stringify!(mediagraph_Mediagraph)) concat!("Size of: ", stringify!(mediagraph_Detector))
); );
assert_eq!( assert_eq!(
::std::mem::align_of::<mediagraph_Mediagraph>(), ::std::mem::align_of::<mediagraph_Detector>(),
8usize, 8usize,
concat!("Alignment of ", stringify!(mediagraph_Mediagraph)) concat!("Alignment of ", stringify!(mediagraph_Detector))
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<mediagraph_Mediagraph>())).m_graph_type as *const _ as usize &(*(::std::ptr::null::<mediagraph_Detector>())).m_graph_type as *const _ as usize
}, },
8usize, 8usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
stringify!(mediagraph_Mediagraph), stringify!(mediagraph_Detector),
"::", "::",
stringify!(m_graph_type) stringify!(m_graph_type)
) )
); );
} }
extern "C" { extern "C" {
#[link_name = "\u{1}__ZN10mediagraph10Mediagraph6CreateENS_9GraphTypeEPKcS3_"] #[link_name = "\u{1}__ZN10mediagraph8Detector6CreateENS_12DetectorTypeEPKcS3_"]
pub fn mediagraph_Mediagraph_Create( pub fn mediagraph_Detector_Create(
graph_type: mediagraph_GraphType, t: mediagraph_DetectorType,
graph_config: *const ::std::os::raw::c_char, graph_config: *const ::std::os::raw::c_char,
output_node: *const ::std::os::raw::c_char, output_node: *const ::std::os::raw::c_char,
) -> *mut mediagraph_Mediagraph; ) -> *mut mediagraph_Detector;
} }
impl mediagraph_Mediagraph { impl mediagraph_Detector {
#[inline] #[inline]
pub unsafe fn Create( pub unsafe fn Create(
graph_type: mediagraph_GraphType, t: mediagraph_DetectorType,
graph_config: *const ::std::os::raw::c_char, graph_config: *const ::std::os::raw::c_char,
output_node: *const ::std::os::raw::c_char, output_node: *const ::std::os::raw::c_char,
) -> *mut mediagraph_Mediagraph { ) -> *mut mediagraph_Detector {
mediagraph_Mediagraph_Create(graph_type, graph_config, output_node) mediagraph_Detector_Create(t, graph_config, output_node)
} }
} }
extern "C" { extern "C" {
#[link_name = "\u{1}__ZN10mediagraph10MediagraphD1Ev"] #[link_name = "\u{1}__ZN10mediagraph8DetectorD1Ev"]
pub fn mediagraph_Mediagraph_Mediagraph_destructor(this: *mut mediagraph_Mediagraph); pub fn mediagraph_Detector_Detector_destructor(this: *mut mediagraph_Detector);
} }
extern "C" { extern "C" {
#[link_name = "\u{1}__ZN10mediagraph10Mediagraph7ProcessEPhii"] #[link_name = "\u{1}__ZN10mediagraph8Detector7ProcessEPhii"]
pub fn mediagraph_Mediagraph_Process( pub fn mediagraph_Detector_Process(
this: *mut ::std::os::raw::c_void, this: *mut ::std::os::raw::c_void,
data: *mut u8, data: *mut u8,
width: ::std::os::raw::c_int, width: ::std::os::raw::c_int,
height: ::std::os::raw::c_int, height: ::std::os::raw::c_int,
) -> *mut mediagraph_Landmark; ) -> *mut mediagraph_Landmark;
} }
#[repr(C)]
pub struct mediagraph_Effect__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug)]
pub struct mediagraph_Effect {
pub vtable_: *const mediagraph_Effect__bindgen_vtable,
}
#[test]
fn bindgen_test_layout_mediagraph_Effect() {
assert_eq!(
::std::mem::size_of::<mediagraph_Effect>(),
8usize,
concat!("Size of: ", stringify!(mediagraph_Effect))
);
assert_eq!(
::std::mem::align_of::<mediagraph_Effect>(),
8usize,
concat!("Alignment of ", stringify!(mediagraph_Effect))
);
}
extern "C" {
#[link_name = "\u{1}__ZN10mediagraph6Effect6CreateEPKcS2_"]
pub fn mediagraph_Effect_Create(
graph_config: *const ::std::os::raw::c_char,
output_node: *const ::std::os::raw::c_char,
) -> *mut mediagraph_Effect;
}
impl mediagraph_Effect {
#[inline]
pub unsafe fn Create(
graph_config: *const ::std::os::raw::c_char,
output_node: *const ::std::os::raw::c_char,
) -> *mut mediagraph_Effect {
mediagraph_Effect_Create(graph_config, output_node)
}
}
extern "C" {
#[link_name = "\u{1}__ZN10mediagraph6EffectD1Ev"]
pub fn mediagraph_Effect_Effect_destructor(this: *mut mediagraph_Effect);
}
extern "C" {
#[link_name = "\u{1}__ZN10mediagraph6Effect7ProcessEPhii"]
pub fn mediagraph_Effect_Process(
this: *mut ::std::os::raw::c_void,
data: *mut u8,
width: ::std::os::raw::c_int,
height: ::std::os::raw::c_int,
) -> *mut u8;
}

View File

@ -19,14 +19,14 @@ mod bindings;
use bindings::*; use bindings::*;
/// The C++ mediagraph graph type. /// The C++ mediagraph graph type.
pub type GraphType = mediagraph_GraphType; pub type DetectorType = mediagraph_DetectorType;
/// The C++ mediagraph landmark type. /// The C++ mediagraph landmark type.
pub type Landmark = mediagraph_Landmark; pub type Landmark = mediagraph_Landmark;
pub const FACE_GRAPH_TYPE: GraphType = mediagraph_GraphType_FACE; pub const FACE_GRAPH_TYPE: DetectorType = mediagraph_DetectorType_FACE;
pub const HANDS_GRAPH_TYPE: GraphType = mediagraph_GraphType_HANDS; pub const HANDS_GRAPH_TYPE: DetectorType = mediagraph_DetectorType_HANDS;
pub const POSE_GRAPH_TYPE: GraphType = mediagraph_GraphType_POSE; pub const POSE_GRAPH_TYPE: DetectorType = mediagraph_DetectorType_POSE;
impl Default for Landmark { impl Default for Landmark {
fn default() -> Self { fn default() -> Self {
@ -74,20 +74,20 @@ impl Default for FaceMesh {
} }
} }
/// Graph calculator which interacts with the C++ library. /// Detector calculator which interacts with the C++ library.
pub struct Mediagraph { pub struct Detector {
graph: *mut mediagraph_Mediagraph, graph: *mut mediagraph_Detector,
num_landmarks: u32, num_landmarks: u32,
} }
impl Mediagraph { impl Detector {
/// Creates a new Mediagraph with the given config. /// Creates a new Mediagraph with the given config.
pub fn new(graph_type: GraphType, graph_config: &str, output_node: &str) -> Self { pub fn new(graph_type: DetectorType, graph_config: &str, output_node: &str) -> Self {
let graph_config = CString::new(graph_config).expect("CString::new failed"); let graph_config = CString::new(graph_config).expect("CString::new failed");
let output_node = CString::new(output_node).expect("CString::new failed"); let output_node = CString::new(output_node).expect("CString::new failed");
let graph: *mut mediagraph_Mediagraph = unsafe { let graph: *mut mediagraph_Detector = unsafe {
mediagraph_Mediagraph::Create(graph_type, graph_config.as_ptr(), output_node.as_ptr()) mediagraph_Detector::Create(graph_type, graph_config.as_ptr(), output_node.as_ptr())
}; };
let num_landmarks = match graph_type { let num_landmarks = match graph_type {
@ -107,7 +107,7 @@ impl Mediagraph {
pub fn process(&mut self, input: &Mat) -> &[Landmark] { pub fn process(&mut self, input: &Mat) -> &[Landmark] {
let mut data = input.clone(); let mut data = input.clone();
let raw_landmarks = unsafe { let raw_landmarks = unsafe {
mediagraph_Mediagraph_Process( mediagraph_Detector_Process(
self.graph as *mut std::ffi::c_void, self.graph as *mut std::ffi::c_void,
data.data_mut(), data.data_mut(),
data.cols(), data.cols(),
@ -123,10 +123,10 @@ impl Mediagraph {
} }
} }
impl Drop for Mediagraph { impl Drop for Detector {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
mediagraph_Mediagraph_Mediagraph_destructor(self.graph); mediagraph_Detector_Detector_destructor(self.graph);
} }
} }
} }
@ -177,12 +177,12 @@ pub mod pose {
pub smooth: bool, // true, pub smooth: bool, // true,
pub detection_con: f32, // 0.5 pub detection_con: f32, // 0.5
pub track_con: f32, // 0.5 pub track_con: f32, // 0.5
graph: Mediagraph, graph: Detector,
} }
impl PoseDetector { impl PoseDetector {
pub fn new(mode: bool, smooth: bool, detection_con: f32, track_con: f32) -> Self { pub fn new(mode: bool, smooth: bool, detection_con: f32, track_con: f32) -> Self {
let graph = Mediagraph::new( let graph = Detector::new(
POSE_GRAPH_TYPE, POSE_GRAPH_TYPE,
include_str!("pose_tracking_cpu.txt"), include_str!("pose_tracking_cpu.txt"),
"pose_landmarks", "pose_landmarks",
@ -227,7 +227,7 @@ pub mod face_mesh {
pub max_faces: usize, // 2 pub max_faces: usize, // 2
pub min_detection_con: f32, // 0.5 pub min_detection_con: f32, // 0.5
pub min_track_con: f32, // 0.5 pub min_track_con: f32, // 0.5
graph: Mediagraph, graph: Detector,
} }
impl FaceMeshDetector { impl FaceMeshDetector {
@ -237,7 +237,7 @@ pub mod face_mesh {
min_detection_con: f32, min_detection_con: f32,
min_track_con: f32, min_track_con: f32,
) -> Self { ) -> Self {
let graph = Mediagraph::new( let graph = Detector::new(
FACE_GRAPH_TYPE, FACE_GRAPH_TYPE,
include_str!("face_mesh_desktop_live.txt"), include_str!("face_mesh_desktop_live.txt"),
"multi_face_landmarks", "multi_face_landmarks",
@ -307,12 +307,12 @@ pub mod hands {
pub max_hands: usize, pub max_hands: usize,
pub detection_con: f32, // 0.5 pub detection_con: f32, // 0.5
pub min_track_con: f32, // 0.5 pub min_track_con: f32, // 0.5
graph: Mediagraph, graph: Detector,
} }
impl HandDetector { impl HandDetector {
pub fn new(mode: bool, max_hands: usize, detection_con: f32, min_track_con: f32) -> Self { pub fn new(mode: bool, max_hands: usize, detection_con: f32, min_track_con: f32) -> Self {
let graph = Mediagraph::new( let graph = Detector::new(
HANDS_GRAPH_TYPE, HANDS_GRAPH_TYPE,
include_str!("hand_tracking_desktop_live.txt"), include_str!("hand_tracking_desktop_live.txt"),
"hand_landmarks", "hand_landmarks",