Port InstantMotionTracking

This commit is contained in:
Speykious
2022-01-15 07:27:03 +01:00
parent feb19f3127
commit f074059bd3
3 changed files with 82 additions and 0 deletions

View File

@ -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}";
}
}
}

View File

@ -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<Anchor3d> ToList()
{
var anchors = new List<Anchor3d>(Size);
unsafe
{
var anchorPtr = (Anchor3d*)Data;
for (var i = 0; i < Size; i++)
anchors.Add(Marshal.PtrToStructure<Anchor3d>((IntPtr)anchorPtr++));
}
return anchors;
}
}
}

View File

@ -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);
}
}