Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D400 Calibration extensions in C# #9256

Merged
merged 11 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion wrappers/csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ add_subdirectory(cs-tutorial-1-depth)
add_subdirectory(cs-tutorial-2-capture)
add_subdirectory(cs-tutorial-3-processing)
add_subdirectory(cs-tutorial-4-software-dev)
add_subdirectory(cs-tutorial-5-pose)
add_subdirectory(cs-tutorial-5-pose)
add_subdirectory(cs-tutorial-8-D400-on-chip-calibration)
22 changes: 22 additions & 0 deletions wrappers/csharp/Intel.RealSense/Devices/AutoCalibratedDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,35 @@ public byte[] RunOnChipCalibration(string json, out float health, int timeout_ms
return GetByteArrayFromRawDataObject(rawDataBuffer);
}

public byte[] RunOnChipCalibration(string json, out float health, ProgressCallback cb, int timeout_ms)
{
object error;
rs2_update_progress_callback cb2 = (float progress, IntPtr u) =>
{
cb((IntPtr)progress);
};
IntPtr rawDataBuffer = NativeMethods.rs2_run_on_chip_calibration(Handle, json, json.Length, out health, cb2, IntPtr.Zero, timeout_ms, out error);
return GetByteArrayFromRawDataObject(rawDataBuffer);
}

public byte[] RunTareCalibration(float ground_truth_mm, string json, int timeout_ms)
{
object error;
IntPtr rawDataBuffer = NativeMethods.rs2_run_tare_calibration(Handle, ground_truth_mm, json, json.Length, null, IntPtr.Zero, timeout_ms, out error);
return GetByteArrayFromRawDataObject(rawDataBuffer);
}

public byte[] RunTareCalibration(float ground_truth_mm, string json, ProgressCallback cb, int timeout_ms)
{
object error;
rs2_update_progress_callback cb2 = (float progress, IntPtr u) =>
{
cb((IntPtr)progress);
};
IntPtr rawDataBuffer = NativeMethods.rs2_run_tare_calibration(Handle, ground_truth_mm, json, json.Length, cb2, IntPtr.Zero, timeout_ms, out error);
return GetByteArrayFromRawDataObject(rawDataBuffer);
}

public byte[] CalibrationTable
{
get
Expand Down
47 changes: 23 additions & 24 deletions wrappers/csharp/Intel.RealSense/Sensors/Sensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public class Sensor : Base.RefCountedPooledObject, IOptions

internal override void Initialize()
{
lock (tableLock)
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
{
if (refCountTable.Contains(Handle))
refCount = refCountTable[Handle] as Base.RefCount;
else
{
refCount = new Base.RefCount();
refCountTable[Handle] = refCount;
}
Retain();
lock (tableLock)
{
if (refCountTable.Contains(Handle))
refCount = refCountTable[Handle] as Base.RefCount;
else
{
refCount = new Base.RefCount();
refCountTable[Handle] = refCount;
}
Retain();
}
Info = new InfoCollection(NativeMethods.rs2_supports_sensor_info, NativeMethods.rs2_get_sensor_info, Handle);
Options = new OptionsList(Handle);
Expand All @@ -53,7 +53,6 @@ internal static T Create<T>(IntPtr ptr)
public static T Create<T>(Sensor other)
where T : Sensor
{
object error;
return ObjectPool.Get<T>(other.Handle);
}

Expand All @@ -65,24 +64,24 @@ internal Sensor(IntPtr sensor)

protected override void Dispose(bool disposing)
{
if (m_instance.IsInvalid)
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
{
return;
if (m_instance.IsInvalid)
{
return;
}

//m_queue.Dispose();
(Options as OptionsList).Dispose();

lock (tableLock)
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
{
IntPtr localHandle = Handle;
System.Diagnostics.Debug.Assert(refCountTable.Contains(localHandle));
base.Dispose(disposing);
if (refCount.count == 0)
{
refCountTable.Remove(localHandle);
lock (tableLock)
{
IntPtr localHandle = Handle;
System.Diagnostics.Debug.Assert(refCountTable.Contains(localHandle));

base.Dispose(disposing);

if (refCount.count == 0)
{
refCountTable.Remove(localHandle);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions wrappers/csharp/Intel.RealSense/Types/Delegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace Intel.RealSense
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void rs2_devices_changed_callback(IntPtr removed, IntPtr added, IntPtr user_data);

public delegate void ProgressCallback(IntPtr progress);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void rs2_update_progress_callback(float progress, IntPtr user_data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required( VERSION 3.8.0 )

project(cs-tutorial-8-D400-on-chip-calibration)

add_executable(${PROJECT_NAME}
Program.cs
Window.xaml
Window.xaml.cs
ExampleAutocalibrateDevice.cs
Properties/AssemblyInfo.cs
)

set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v${DOTNET_VERSION_EXAMPLES}")
# set_property(TARGET ${PROJECT_NAME} PROPERTY WIN32_EXECUTABLE TRUE)

add_dependencies(${PROJECT_NAME} Intel.RealSense)

set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES
"System"
"System.Xaml"
"PresentationCore"
"PresentationFramework"
"WindowsBase"
)

set_target_properties (${PROJECT_NAME} PROPERTIES
FOLDER Wrappers/csharp
)
Loading