-
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: marshal DetectionResult (#1089)
* feat: marshal DetectionResult * refactor: init list if null
- Loading branch information
Showing
17 changed files
with
320 additions
and
12 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Marshal/NativeCategory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Mediapipe | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal readonly struct NativeCategory | ||
{ | ||
public readonly int index; | ||
public readonly float score; | ||
private readonly IntPtr _categoryName; | ||
private readonly IntPtr _displayName; | ||
|
||
public string categoryName => Marshal.PtrToStringAnsi(_categoryName); | ||
public string displayName => Marshal.PtrToStringAnsi(_displayName); | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
internal readonly struct NativeCategories | ||
{ | ||
private readonly IntPtr _categories; | ||
public readonly uint categoriesCount; | ||
|
||
public ReadOnlySpan<NativeCategory> AsReadOnlySpan() | ||
{ | ||
unsafe | ||
{ | ||
return new ReadOnlySpan<NativeCategory>((NativeCategory*)_categories, (int)categoriesCount); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Marshal/NativeCategory.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Marshal/NativeDetectionResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Mediapipe | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal readonly struct NativeDetection | ||
{ | ||
private readonly IntPtr _categories; | ||
|
||
public readonly uint categoriesCount; | ||
|
||
public readonly NativeRect boundingBox; | ||
|
||
private readonly IntPtr _keypoints; | ||
|
||
public readonly uint keypointsCount; | ||
|
||
public ReadOnlySpan<NativeCategory> categories | ||
{ | ||
get | ||
{ | ||
unsafe | ||
{ | ||
return new ReadOnlySpan<NativeCategory>((NativeCategory*)_categories, (int)categoriesCount); | ||
} | ||
} | ||
} | ||
|
||
public ReadOnlySpan<NativeNormalizedKeypoint> keypoints | ||
{ | ||
get | ||
{ | ||
unsafe | ||
{ | ||
return new ReadOnlySpan<NativeNormalizedKeypoint>((NativeNormalizedKeypoint*)_keypoints, (int)keypointsCount); | ||
} | ||
} | ||
} | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
internal readonly struct NativeDetectionResult | ||
{ | ||
private readonly IntPtr _detections; | ||
public readonly uint detectionsCount; | ||
|
||
public ReadOnlySpan<NativeDetection> AsReadOnlySpan() | ||
{ | ||
unsafe | ||
{ | ||
return new ReadOnlySpan<NativeDetection>((NativeDetection*)_detections, (int)detectionsCount); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
UnsafeNativeMethods.mp_tasks_c_components_containers_CppCloseDetectionResult(this); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Marshal/NativeDetectionResult.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Marshal/NativeKeypoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Mediapipe | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal readonly struct NativeNormalizedKeypoint | ||
{ | ||
public readonly float x; | ||
public readonly float y; | ||
private readonly IntPtr _label; | ||
public readonly float score; | ||
public readonly bool hasScore; | ||
|
||
public string label => Marshal.PtrToStringAnsi(_label); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Marshal/NativeKeypoint.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Marshal/NativeRect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2023 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace Mediapipe | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal readonly struct NativeRect | ||
{ | ||
public readonly int left; | ||
public readonly int top; | ||
public readonly int bottom; | ||
public readonly int right; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
internal readonly struct NativeRectF | ||
{ | ||
public readonly float left; | ||
public readonly float top; | ||
public readonly float bottom; | ||
public readonly float right; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/com.github.homuler.mediapipe/Runtime/Scripts/Marshal/NativeRect.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.