rename mediagraph to detector
This commit is contained in:
parent
51ec5928dc
commit
0a0ecbb93c
103
src/bindings.rs
103
src/bindings.rs
|
@ -72,71 +72,120 @@ fn bindgen_test_layout_mediagraph_Landmark() {
|
|||
)
|
||||
);
|
||||
}
|
||||
pub const mediagraph_GraphType_POSE: mediagraph_GraphType = 0;
|
||||
pub const mediagraph_GraphType_HANDS: mediagraph_GraphType = 1;
|
||||
pub const mediagraph_GraphType_FACE: mediagraph_GraphType = 2;
|
||||
pub type mediagraph_GraphType = ::std::os::raw::c_uint;
|
||||
pub const mediagraph_DetectorType_POSE: mediagraph_DetectorType = 0;
|
||||
pub const mediagraph_DetectorType_HANDS: mediagraph_DetectorType = 1;
|
||||
pub const mediagraph_DetectorType_FACE: mediagraph_DetectorType = 2;
|
||||
pub type mediagraph_DetectorType = ::std::os::raw::c_uint;
|
||||
#[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)]
|
||||
#[derive(Debug)]
|
||||
pub struct mediagraph_Mediagraph {
|
||||
pub vtable_: *const mediagraph_Mediagraph__bindgen_vtable,
|
||||
pub m_graph_type: mediagraph_GraphType,
|
||||
pub struct mediagraph_Detector {
|
||||
pub vtable_: *const mediagraph_Detector__bindgen_vtable,
|
||||
pub m_graph_type: mediagraph_DetectorType,
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_mediagraph_Mediagraph() {
|
||||
fn bindgen_test_layout_mediagraph_Detector() {
|
||||
assert_eq!(
|
||||
::std::mem::size_of::<mediagraph_Mediagraph>(),
|
||||
::std::mem::size_of::<mediagraph_Detector>(),
|
||||
16usize,
|
||||
concat!("Size of: ", stringify!(mediagraph_Mediagraph))
|
||||
concat!("Size of: ", stringify!(mediagraph_Detector))
|
||||
);
|
||||
assert_eq!(
|
||||
::std::mem::align_of::<mediagraph_Mediagraph>(),
|
||||
::std::mem::align_of::<mediagraph_Detector>(),
|
||||
8usize,
|
||||
concat!("Alignment of ", stringify!(mediagraph_Mediagraph))
|
||||
concat!("Alignment of ", stringify!(mediagraph_Detector))
|
||||
);
|
||||
assert_eq!(
|
||||
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,
|
||||
concat!(
|
||||
"Offset of field: ",
|
||||
stringify!(mediagraph_Mediagraph),
|
||||
stringify!(mediagraph_Detector),
|
||||
"::",
|
||||
stringify!(m_graph_type)
|
||||
)
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
#[link_name = "\u{1}__ZN10mediagraph10Mediagraph6CreateENS_9GraphTypeEPKcS3_"]
|
||||
pub fn mediagraph_Mediagraph_Create(
|
||||
graph_type: mediagraph_GraphType,
|
||||
#[link_name = "\u{1}__ZN10mediagraph8Detector6CreateENS_12DetectorTypeEPKcS3_"]
|
||||
pub fn mediagraph_Detector_Create(
|
||||
t: mediagraph_DetectorType,
|
||||
graph_config: *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]
|
||||
pub unsafe fn Create(
|
||||
graph_type: mediagraph_GraphType,
|
||||
t: mediagraph_DetectorType,
|
||||
graph_config: *const ::std::os::raw::c_char,
|
||||
output_node: *const ::std::os::raw::c_char,
|
||||
) -> *mut mediagraph_Mediagraph {
|
||||
mediagraph_Mediagraph_Create(graph_type, graph_config, output_node)
|
||||
) -> *mut mediagraph_Detector {
|
||||
mediagraph_Detector_Create(t, graph_config, output_node)
|
||||
}
|
||||
}
|
||||
extern "C" {
|
||||
#[link_name = "\u{1}__ZN10mediagraph10MediagraphD1Ev"]
|
||||
pub fn mediagraph_Mediagraph_Mediagraph_destructor(this: *mut mediagraph_Mediagraph);
|
||||
#[link_name = "\u{1}__ZN10mediagraph8DetectorD1Ev"]
|
||||
pub fn mediagraph_Detector_Detector_destructor(this: *mut mediagraph_Detector);
|
||||
}
|
||||
extern "C" {
|
||||
#[link_name = "\u{1}__ZN10mediagraph10Mediagraph7ProcessEPhii"]
|
||||
pub fn mediagraph_Mediagraph_Process(
|
||||
#[link_name = "\u{1}__ZN10mediagraph8Detector7ProcessEPhii"]
|
||||
pub fn mediagraph_Detector_Process(
|
||||
this: *mut ::std::os::raw::c_void,
|
||||
data: *mut u8,
|
||||
width: ::std::os::raw::c_int,
|
||||
height: ::std::os::raw::c_int,
|
||||
) -> *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;
|
||||
}
|
||||
|
|
40
src/lib.rs
40
src/lib.rs
|
@ -19,14 +19,14 @@ mod bindings;
|
|||
use bindings::*;
|
||||
|
||||
/// The C++ mediagraph graph type.
|
||||
pub type GraphType = mediagraph_GraphType;
|
||||
pub type DetectorType = mediagraph_DetectorType;
|
||||
|
||||
/// The C++ mediagraph landmark type.
|
||||
pub type Landmark = mediagraph_Landmark;
|
||||
|
||||
pub const FACE_GRAPH_TYPE: GraphType = mediagraph_GraphType_FACE;
|
||||
pub const HANDS_GRAPH_TYPE: GraphType = mediagraph_GraphType_HANDS;
|
||||
pub const POSE_GRAPH_TYPE: GraphType = mediagraph_GraphType_POSE;
|
||||
pub const FACE_GRAPH_TYPE: DetectorType = mediagraph_DetectorType_FACE;
|
||||
pub const HANDS_GRAPH_TYPE: DetectorType = mediagraph_DetectorType_HANDS;
|
||||
pub const POSE_GRAPH_TYPE: DetectorType = mediagraph_DetectorType_POSE;
|
||||
|
||||
impl Default for Landmark {
|
||||
fn default() -> Self {
|
||||
|
@ -74,20 +74,20 @@ impl Default for FaceMesh {
|
|||
}
|
||||
}
|
||||
|
||||
/// Graph calculator which interacts with the C++ library.
|
||||
pub struct Mediagraph {
|
||||
graph: *mut mediagraph_Mediagraph,
|
||||
/// Detector calculator which interacts with the C++ library.
|
||||
pub struct Detector {
|
||||
graph: *mut mediagraph_Detector,
|
||||
num_landmarks: u32,
|
||||
}
|
||||
|
||||
impl Mediagraph {
|
||||
impl Detector {
|
||||
/// 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 output_node = CString::new(output_node).expect("CString::new failed");
|
||||
|
||||
let graph: *mut mediagraph_Mediagraph = unsafe {
|
||||
mediagraph_Mediagraph::Create(graph_type, graph_config.as_ptr(), output_node.as_ptr())
|
||||
let graph: *mut mediagraph_Detector = unsafe {
|
||||
mediagraph_Detector::Create(graph_type, graph_config.as_ptr(), output_node.as_ptr())
|
||||
};
|
||||
|
||||
let num_landmarks = match graph_type {
|
||||
|
@ -107,7 +107,7 @@ impl Mediagraph {
|
|||
pub fn process(&mut self, input: &Mat) -> &[Landmark] {
|
||||
let mut data = input.clone();
|
||||
let raw_landmarks = unsafe {
|
||||
mediagraph_Mediagraph_Process(
|
||||
mediagraph_Detector_Process(
|
||||
self.graph as *mut std::ffi::c_void,
|
||||
data.data_mut(),
|
||||
data.cols(),
|
||||
|
@ -123,10 +123,10 @@ impl Mediagraph {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for Mediagraph {
|
||||
impl Drop for Detector {
|
||||
fn drop(&mut self) {
|
||||
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 detection_con: f32, // 0.5
|
||||
pub track_con: f32, // 0.5
|
||||
graph: Mediagraph,
|
||||
graph: Detector,
|
||||
}
|
||||
|
||||
impl PoseDetector {
|
||||
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,
|
||||
include_str!("pose_tracking_cpu.txt"),
|
||||
"pose_landmarks",
|
||||
|
@ -227,7 +227,7 @@ pub mod face_mesh {
|
|||
pub max_faces: usize, // 2
|
||||
pub min_detection_con: f32, // 0.5
|
||||
pub min_track_con: f32, // 0.5
|
||||
graph: Mediagraph,
|
||||
graph: Detector,
|
||||
}
|
||||
|
||||
impl FaceMeshDetector {
|
||||
|
@ -237,7 +237,7 @@ pub mod face_mesh {
|
|||
min_detection_con: f32,
|
||||
min_track_con: f32,
|
||||
) -> Self {
|
||||
let graph = Mediagraph::new(
|
||||
let graph = Detector::new(
|
||||
FACE_GRAPH_TYPE,
|
||||
include_str!("face_mesh_desktop_live.txt"),
|
||||
"multi_face_landmarks",
|
||||
|
@ -307,12 +307,12 @@ pub mod hands {
|
|||
pub max_hands: usize,
|
||||
pub detection_con: f32, // 0.5
|
||||
pub min_track_con: f32, // 0.5
|
||||
graph: Mediagraph,
|
||||
graph: Detector,
|
||||
}
|
||||
|
||||
impl HandDetector {
|
||||
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,
|
||||
include_str!("hand_tracking_desktop_live.txt"),
|
||||
"hand_landmarks",
|
||||
|
|
Loading…
Reference in New Issue
Block a user