-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7915 from mengyui/csharp-on-chip-calibration-support
On-chip calibration support in csharp wrapper
- Loading branch information
Showing
4 changed files
with
145 additions
and
35 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
wrappers/csharp/Intel.RealSense/Devices/AutoCalibratedDevice.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,70 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2017 Intel Corporation. All Rights Reserved. | ||
|
||
namespace Intel.RealSense | ||
{ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
public class AutoCalibratedDevice : CalibratedDevice | ||
{ | ||
internal AutoCalibratedDevice(IntPtr dev) | ||
: base(dev) | ||
{ } | ||
public static AutoCalibratedDevice FromDevice(Device dev) | ||
{ | ||
object error; | ||
if (NativeMethods.rs2_is_device_extendable_to(dev.Handle, Extension.AutoCalibratedDevice, out error) == 0) | ||
{ | ||
throw new ArgumentException($"Device does not support {nameof(Extension.AutoCalibratedDevice)}"); | ||
} | ||
|
||
return Device.Create<AutoCalibratedDevice>(dev.Handle); | ||
} | ||
|
||
public byte[] RunOnChipCalibration(string json, out float health, int timeout_ms) | ||
{ | ||
object error; | ||
IntPtr rawDataBuffer = NativeMethods.rs2_run_on_chip_calibration(Handle, json, json.Length, out health, null, 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[] CalibrationTable | ||
{ | ||
get | ||
{ | ||
object error; | ||
IntPtr rawDataBuffer = NativeMethods.rs2_get_calibration_table(Handle, out error); | ||
return GetByteArrayFromRawDataObject(rawDataBuffer); | ||
} | ||
set | ||
{ | ||
IntPtr rawCalibrationTable = Marshal.AllocHGlobal(value.Length); | ||
Marshal.Copy(value, 0, rawCalibrationTable, value.Length); | ||
object error; | ||
NativeMethods.rs2_set_calibration_table(Handle, rawCalibrationTable, value.Length, out error); | ||
Marshal.FreeHGlobal(rawCalibrationTable); | ||
} | ||
} | ||
|
||
byte[] GetByteArrayFromRawDataObject(IntPtr raw) | ||
{ | ||
object error; | ||
var start = NativeMethods.rs2_get_raw_data(raw, out error); | ||
var size = NativeMethods.rs2_get_raw_data_size(raw, out error); | ||
|
||
byte[] managedBytes = new byte[size]; | ||
Marshal.Copy(start, managedBytes, 0, size); | ||
|
||
NativeMethods.rs2_delete_raw_data(raw); | ||
return managedBytes; | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
wrappers/csharp/Intel.RealSense/Devices/CalibratedDevice.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,31 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2017 Intel Corporation. All Rights Reserved. | ||
|
||
namespace Intel.RealSense | ||
{ | ||
using System; | ||
|
||
public class CalibratedDevice : Device | ||
{ | ||
internal CalibratedDevice(IntPtr dev) | ||
: base(dev) | ||
{ } | ||
|
||
public static CalibratedDevice FromDevice(Device dev) | ||
{ | ||
return Device.Create<CalibratedDevice>(dev.Handle); ; | ||
} | ||
|
||
public void WriteCalibration() | ||
{ | ||
object error; | ||
NativeMethods.rs2_write_calibration(Handle, out error); | ||
} | ||
|
||
public void reset_to_factory_calibration() | ||
{ | ||
object error; | ||
NativeMethods.rs2_reset_to_factory_calibration(Handle, out error); | ||
} | ||
} | ||
} |
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