From f074059bd363f08a871212672eef9229dbbe7fad Mon Sep 17 00:00:00 2001 From: Speykious Date: Sat, 15 Jan 2022 07:27:03 +0100 Subject: [PATCH] Port `InstantMotionTracking` --- .../Graphs/InstantMotionTracking/Anchor3d.cs | 22 ++++++++++++ .../InstantMotionTracking/Anchor3dVector.cs | 35 +++++++++++++++++++ .../Graphs/InstantMotionTracking.cs | 25 +++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 Mediapipe.Net/Graphs/InstantMotionTracking/Anchor3d.cs create mode 100644 Mediapipe.Net/Graphs/InstantMotionTracking/Anchor3dVector.cs create mode 100644 Mediapipe.Net/Native/UnsafeNativeMethods/Graphs/InstantMotionTracking.cs diff --git a/Mediapipe.Net/Graphs/InstantMotionTracking/Anchor3d.cs b/Mediapipe.Net/Graphs/InstantMotionTracking/Anchor3d.cs new file mode 100644 index 0000000..fa67b73 --- /dev/null +++ b/Mediapipe.Net/Graphs/InstantMotionTracking/Anchor3d.cs @@ -0,0 +1,22 @@ +// Copyright (c) homuler and Vignette +// This file is part of MediaPipe.NET. +// MediaPipe.NET is licensed under the MIT License. See LICENSE for details. + +using System.Runtime.InteropServices; + +namespace Mediapipe.Net.Graphs.InstantMotionTracking +{ + [StructLayout(LayoutKind.Sequential)] + public struct Anchor3d + { + public float X; + public float Y; + public float Z; + public int StickerId; + + public override string ToString() + { + return $"({X}, {Y}, {Z}), #{StickerId}"; + } + } +} diff --git a/Mediapipe.Net/Graphs/InstantMotionTracking/Anchor3dVector.cs b/Mediapipe.Net/Graphs/InstantMotionTracking/Anchor3dVector.cs new file mode 100644 index 0000000..b435352 --- /dev/null +++ b/Mediapipe.Net/Graphs/InstantMotionTracking/Anchor3dVector.cs @@ -0,0 +1,35 @@ +// Copyright (c) homuler and Vignette +// This file is part of MediaPipe.NET. +// MediaPipe.NET is licensed under the MIT License. See LICENSE for details. + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using Mediapipe.Net.Native; + +namespace Mediapipe.Net.Graphs.InstantMotionTracking +{ + [StructLayout(LayoutKind.Sequential)] + internal struct Anchor3dVector + { + public IntPtr Data; + public int Size; + + public void Dispose() => UnsafeNativeMethods.mp_Anchor3dArray__delete(Data); + + public List ToList() + { + var anchors = new List(Size); + + unsafe + { + var anchorPtr = (Anchor3d*)Data; + + for (var i = 0; i < Size; i++) + anchors.Add(Marshal.PtrToStructure((IntPtr)anchorPtr++)); + } + + return anchors; + } + } +} diff --git a/Mediapipe.Net/Native/UnsafeNativeMethods/Graphs/InstantMotionTracking.cs b/Mediapipe.Net/Native/UnsafeNativeMethods/Graphs/InstantMotionTracking.cs new file mode 100644 index 0000000..3aa1625 --- /dev/null +++ b/Mediapipe.Net/Native/UnsafeNativeMethods/Graphs/InstantMotionTracking.cs @@ -0,0 +1,25 @@ +// Copyright (c) homuler and Vignette +// This file is part of MediaPipe.NET. +// MediaPipe.NET is licensed under the MIT License. See LICENSE for details. + +using System; +using System.Runtime.InteropServices; +using Mediapipe.Net.Graphs.InstantMotionTracking; + +namespace Mediapipe.Net.Native +{ + internal partial class UnsafeNativeMethods : NativeMethods + { + [DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)] + public static extern MpReturnCode mp__MakeAnchor3dVectorPacket__PA_i(Anchor3d[] value, int size, out IntPtr packet); + + [DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)] + public static extern MpReturnCode mp__MakeAnchor3dVectorPacket_At__PA_i_Rt(Anchor3d[] value, int size, IntPtr timestamp, out IntPtr packet); + + [DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)] + public static extern void mp_Anchor3dArray__delete(IntPtr anchorVectorData); + + [DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)] + public static extern MpReturnCode mp_Packet__GetAnchor3dVector(IntPtr packet, out Anchor3dVector anchorVector); + } +}