forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR IntelRealSense#9435 from Andrew: restructure C# tutorials & add lo…
…ad-json
- Loading branch information
Showing
48 changed files
with
798 additions
and
6 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
wrappers/csharp/Intel.RealSense/Devices/SerializableDevice.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,47 @@ | ||
// 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.Collections; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
|
||
|
||
public class SerializableDevice : Device | ||
{ | ||
internal SerializableDevice(IntPtr dev) | ||
: base(dev) | ||
{ } | ||
|
||
public static SerializableDevice FromDevice(Device dev) | ||
{ | ||
return Device.Create<SerializableDevice>(dev.Handle); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets JSON and applies advanced-mode controls | ||
/// </summary> | ||
/// <value>Serialize JSON content</value> | ||
public string JsonConfiguration | ||
{ | ||
get | ||
{ | ||
object error; | ||
IntPtr buffer = NativeMethods.rs2_serialize_json(Handle, out error); | ||
int size = NativeMethods.rs2_get_raw_data_size(buffer, out error); | ||
IntPtr data = NativeMethods.rs2_get_raw_data(buffer, out error); | ||
var str = Marshal.PtrToStringAnsi(data, size); | ||
NativeMethods.rs2_delete_raw_data(buffer); | ||
return str; | ||
} | ||
|
||
set | ||
{ | ||
object error; | ||
NativeMethods.rs2_load_json(Handle, value, (uint)value.Length, out error); | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
116 changes: 116 additions & 0 deletions
116
wrappers/csharp/tutorial/load-json/ADP_TestLoadSettingsJson.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,116 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Intel.RealSense | ||
{ | ||
class ADP_TestLoadSettingsJson | ||
{ | ||
|
||
public bool LoadSettingsJson(Device device) | ||
{ | ||
var deviceName = device.Info[CameraInfo.Name]; | ||
var usbType = device.Info[CameraInfo.UsbTypeDescriptor]; | ||
string[] deviceNameParts = deviceName.Split(" ".ToCharArray()); | ||
var model = deviceNameParts.Last().Trim(); | ||
|
||
|
||
SerializableDevice ser = null; | ||
Console.WriteLine($"Device model: '{model}'"); | ||
|
||
var jsonFileName = $"ADP_{model}_TEST_JSON_USB{usbType}.json"; | ||
var jsonPath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "JsonConfigs", jsonFileName); | ||
Console.WriteLine($"Searching for a json test file: '{jsonFileName}'"); | ||
if (!File.Exists(jsonPath)) | ||
{ | ||
Console.WriteLine($"File not found, so no settings data will be loaded into a camera. Exiting..."); | ||
return false; | ||
} | ||
|
||
Console.WriteLine($"Json test file found: {jsonPath}. Loading it..."); | ||
Console.WriteLine($"Loading by using of SerialiazableDevice..."); | ||
ser = SerializableDevice.FromDevice(device); | ||
try | ||
{ | ||
ser.JsonConfiguration = File.ReadAllText(jsonPath); | ||
Console.WriteLine($"Loaded"); | ||
Console.WriteLine(ser.JsonConfiguration); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Failed to load json file: {ex.Message}"); | ||
return false; | ||
} | ||
|
||
// check for manual options setting | ||
var sensors = device.QuerySensors(); | ||
var depthSensor = sensors[0]; | ||
var colorSensor = sensors[1]; | ||
Console.WriteLine($"\nManulally read options:"); | ||
Console.WriteLine($"--------------------------------------------------"); | ||
Console.WriteLine($"DEPTH OPTIONS:"); | ||
Console.WriteLine($"================"); | ||
Console.WriteLine($"Total count: {depthSensor.Options.Count()}\n"); | ||
for (int i = 0; i < depthSensor.Options.Count(); i++) | ||
{ | ||
// there may be some exceptions when trying to get some options, even when going through by index. So using this relatively safe method to iterate all the options, even unacceptible | ||
try | ||
{ | ||
var opt = depthSensor.Options.Skip(i).Take(1).FirstOrDefault(); | ||
if (opt != null) | ||
{ | ||
Console.WriteLine($"{opt.Key}: {opt.Value}"); | ||
|
||
} | ||
} | ||
catch (Exception) | ||
{ | ||
Console.WriteLine($"Error getting option №{i}"); | ||
} | ||
} | ||
Console.WriteLine($"\nCOLOR OPTIONS:"); | ||
Console.WriteLine($"================"); | ||
Console.WriteLine($"Total count: {colorSensor.Options.Count()}\n"); | ||
for (int i = 0; i < colorSensor.Options.Count(); i++) | ||
{ | ||
// there may be some exceptions when trying to get some options, even when going through by index. So using this relatively safe method to iterate all the options, even unacceptible | ||
try | ||
{ | ||
var opt = colorSensor.Options.Skip(i).Take(1).FirstOrDefault(); | ||
if (opt != null) | ||
{ | ||
Console.WriteLine($"{opt.Key}: {opt.Value}"); | ||
if (opt.Key.ToString() == "Brightness") // check if we can set value to option. We take brightness for example | ||
{ | ||
var newValue = opt.Value + 1; | ||
Console.Write($"\nCheck if we can set option manually: {opt.Key}: from {opt.Value} to {newValue}..."); | ||
opt.Value = newValue; | ||
|
||
var optionsJson = Regex.Replace(ser.JsonConfiguration, @" ", ""); | ||
// if we can read brightness from json settings (not all cameras returns all params), use it | ||
if (optionsJson.IndexOf("controls-color-brightness") > 0) | ||
{ | ||
var shouldBe = $"\"controls-color-brightness\":\"{newValue}\""; | ||
Console.Write($"new value set: {optionsJson.IndexOf(shouldBe) > 0}\n\n"); | ||
} | ||
else // else just reread value from option - it's getter will get it from device | ||
{ | ||
Console.Write($"new value set: {opt.Value == newValue}\n\n"); // opt.Value getter will read value from device | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Error read option №{i}: {ex.Message}"); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
} |
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,34 @@ | ||
cmake_minimum_required( VERSION 3.8.0 ) | ||
|
||
project(cs-tutorial-load-json) | ||
|
||
add_executable(${PROJECT_NAME} | ||
Program.cs | ||
Window.xaml | ||
Window.xaml.cs | ||
ADP_TestLoadSettingsJson.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 | ||
) | ||
|
||
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory | ||
${CMAKE_CURRENT_SOURCE_DIR}/JsonConfigs $<TARGET_FILE_DIR:${PROJECT_NAME}>/JsonConfigs) | ||
|
95 changes: 95 additions & 0 deletions
95
wrappers/csharp/tutorial/load-json/JsonConfigs/ADP_D415_TEST_JSON_USB2.1.json
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,95 @@ | ||
{ | ||
"aux-param-autoexposure-setpoint": "400", | ||
"aux-param-colorcorrection1": "0.461914", | ||
"aux-param-colorcorrection10": "-0.553711", | ||
"aux-param-colorcorrection11": "-0.553711", | ||
"aux-param-colorcorrection12": "0.0458984", | ||
"aux-param-colorcorrection2": "0.540039", | ||
"aux-param-colorcorrection3": "0.540039", | ||
"aux-param-colorcorrection4": "0.208008", | ||
"aux-param-colorcorrection5": "-0.332031", | ||
"aux-param-colorcorrection6": "-0.212891", | ||
"aux-param-colorcorrection7": "-0.212891", | ||
"aux-param-colorcorrection8": "0.68457", | ||
"aux-param-colorcorrection9": "0.930664", | ||
"aux-param-depthclampmax": "65536", | ||
"aux-param-depthclampmin": "0", | ||
"aux-param-disparityshift": "0", | ||
"controls-autoexposure-auto": "True", | ||
"controls-autoexposure-manual": "33000", | ||
"controls-color-autoexposure-auto": "True", | ||
"controls-color-autoexposure-manual": "156", | ||
"controls-color-backlight-compensation": "0", | ||
"controls-color-brightness": "-54", | ||
"controls-color-contrast": "50", | ||
"controls-color-gain": "64", | ||
"controls-color-gamma": "300", | ||
"controls-color-hue": "0", | ||
"controls-color-power-line-frequency": "3", | ||
"controls-color-saturation": "64", | ||
"controls-color-sharpness": "50", | ||
"controls-color-white-balance-auto": "True", | ||
"controls-color-white-balance-manual": "4600", | ||
"controls-depth-gain": "16", | ||
"controls-depth-white-balance-auto": "False", | ||
"controls-laserpower": "150", | ||
"controls-laserstate": "on", | ||
"ignoreSAD": "0", | ||
"param-amplitude-factor": "0", | ||
"param-autoexposure-setpoint": "400", | ||
"param-censusenablereg-udiameter": "9", | ||
"param-censusenablereg-vdiameter": "9", | ||
"param-censususize": "9", | ||
"param-censusvsize": "9", | ||
"param-depthclampmax": "65536", | ||
"param-depthclampmin": "0", | ||
"param-depthunits": "1000", | ||
"param-disableraucolor": "0", | ||
"param-disablesadcolor": "0", | ||
"param-disablesadnormalize": "0", | ||
"param-disablesloleftcolor": "0", | ||
"param-disableslorightcolor": "0", | ||
"param-disparitymode": "0", | ||
"param-disparityshift": "0", | ||
"param-lambdaad": "800", | ||
"param-lambdacensus": "26", | ||
"param-leftrightthreshold": "24", | ||
"param-maxscorethreshb": "2047", | ||
"param-medianthreshold": "500", | ||
"param-minscorethresha": "1", | ||
"param-neighborthresh": "7", | ||
"param-raumine": "1", | ||
"param-rauminn": "1", | ||
"param-rauminnssum": "3", | ||
"param-raumins": "1", | ||
"param-rauminw": "1", | ||
"param-rauminwesum": "3", | ||
"param-regioncolorthresholdb": "0.0499022", | ||
"param-regioncolorthresholdg": "0.0499022", | ||
"param-regioncolorthresholdr": "0.0499022", | ||
"param-regionshrinku": "3", | ||
"param-regionshrinkv": "1", | ||
"param-robbinsmonrodecrement": "10", | ||
"param-robbinsmonroincrement": "10", | ||
"param-rsmdiffthreshold": "4", | ||
"param-rsmrauslodiffthreshold": "1", | ||
"param-rsmremovethreshold": "0.375", | ||
"param-scanlineedgetaub": "72", | ||
"param-scanlineedgetaug": "72", | ||
"param-scanlineedgetaur": "72", | ||
"param-scanlinep1": "60", | ||
"param-scanlinep1onediscon": "105", | ||
"param-scanlinep1twodiscon": "70", | ||
"param-scanlinep2": "342", | ||
"param-scanlinep2onediscon": "190", | ||
"param-scanlinep2twodiscon": "130", | ||
"param-secondpeakdelta": "325", | ||
"param-texturecountthresh": "0", | ||
"param-texturedifferencethresh": "0", | ||
"param-usersm": "1", | ||
"param-zunits": "1000", | ||
"stream-depth-format": "Z16", | ||
"stream-fps": "15", | ||
"stream-height": "480", | ||
"stream-width": "640" | ||
} |
Oops, something went wrong.