Skip to content

Commit f6cb4ef

Browse files
committed
[Feature] Sync csharp apis with newly added c apis && demo (open-mmlab#1718)
* sync c api to c# * fix typo * add pose tracker c# demo * udpate gitignore * remove print * fix lint * update rotated detection api * update rotated detection demo * rename pose_tracking -> pose_tracker * use input size as default
1 parent 50bd7e9 commit f6cb4ef

File tree

17 files changed

+1146
-1
lines changed

17 files changed

+1146
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,6 @@ service/snpe/grpc_cpp_plugin
166166
csrc/mmdeploy/preprocess/elena/json
167167
csrc/mmdeploy/preprocess/elena/cpu_kernel/*
168168
csrc/mmdeploy/preprocess/elena/cuda_kernel/*
169+
170+
# c#
171+
demo/csharp/*/Properties
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
namespace MMDeploy
2+
{
3+
/// <summary>
4+
/// Context.
5+
/// </summary>
6+
public class Context : DisposableObject
7+
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="Context"/> class.
10+
/// </summary>
11+
public Context()
12+
{
13+
ThrowException(NativeMethods.mmdeploy_context_create(out _handle));
14+
}
15+
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="Context"/> class with device.
18+
/// </summary>
19+
/// <param name="device">device.</param>
20+
public Context(Device device) : this()
21+
{
22+
Add(device);
23+
}
24+
25+
/// <summary>
26+
/// Add model to the context.
27+
/// </summary>
28+
/// <param name="name">name.</param>
29+
/// <param name="model">model.</param>
30+
public void Add(string name, Model model)
31+
{
32+
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.MODEL, name, model));
33+
}
34+
35+
/// <summary>
36+
/// Add scheduler to the context.
37+
/// </summary>
38+
/// <param name="name">name.</param>
39+
/// <param name="scheduler">scheduler.</param>
40+
public void Add(string name, Scheduler scheduler)
41+
{
42+
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.SCHEDULER, name, scheduler));
43+
}
44+
45+
/// <summary>
46+
/// Add device to the context.
47+
/// </summary>
48+
/// <param name="device">device.</param>
49+
public void Add(Device device)
50+
{
51+
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.DEVICE, "", device));
52+
}
53+
54+
/// <summary>
55+
/// Add profiler to the context.
56+
/// </summary>
57+
/// <param name="profiler">profiler.</param>
58+
public void Add(Profiler profiler)
59+
{
60+
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.PROFILER, "", profiler));
61+
}
62+
63+
/// <inheritdoc/>
64+
protected override void ReleaseHandle()
65+
{
66+
NativeMethods.mmdeploy_model_destroy(_handle);
67+
}
68+
}
69+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace MMDeploy
2+
{
3+
/// <summary>
4+
/// Device.
5+
/// </summary>
6+
public class Device : DisposableObject
7+
{
8+
private readonly string _name;
9+
private readonly int _index;
10+
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="Device"/> class.
13+
/// </summary>
14+
/// <param name="name">device name.</param>
15+
/// <param name="index">device index.</param>
16+
public Device(string name, int index = 0)
17+
{
18+
this._name = name;
19+
this._index = index;
20+
ThrowException(NativeMethods.mmdeploy_device_create(name, index, out _handle));
21+
}
22+
23+
/// <summary>
24+
/// Gets device name.
25+
/// </summary>
26+
public string Name { get => _name; }
27+
28+
/// <summary>
29+
/// Gets device index.
30+
/// </summary>
31+
public int Index { get => _index; }
32+
33+
/// <inheritdoc/>
34+
protected override void ReleaseHandle()
35+
{
36+
NativeMethods.mmdeploy_device_destroy(_handle);
37+
}
38+
}
39+
}

csrc/mmdeploy/apis/csharp/MMDeploy/APIs/DisposableObject.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,11 @@ protected static void ThrowException(int result)
9292
throw new Exception(result.ToString());
9393
}
9494
}
95+
96+
/// <summary>
97+
/// Gets internal handle.
98+
/// </summary>
99+
/// <param name="obj">instance.</param>
100+
public static implicit operator IntPtr(DisposableObject obj) => obj._handle;
95101
}
96102
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace MMDeploy
2+
{
3+
/// <summary>
4+
/// model.
5+
/// </summary>
6+
public class Model : DisposableObject
7+
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="Model"/> class.
10+
/// </summary>
11+
/// <param name="modelPath">model path.</param>
12+
public Model(string modelPath)
13+
{
14+
ThrowException(NativeMethods.mmdeploy_model_create_by_path(modelPath, out _handle));
15+
}
16+
17+
/// <inheritdoc/>
18+
protected override void ReleaseHandle()
19+
{
20+
NativeMethods.mmdeploy_model_destroy(_handle);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)