c# D400 Series Visual Presets
.net C # How to load the default JSON file?
{ "aux-param-autoexposure-setpoint": "1536", "aux-param-colorcorrection1": "0.298828", "aux-param-colorcorrection10": "0", "aux-param-colorcorrection11": "0", "aux-param-colorcorrection12": "0", "aux-param-colorcorrection2": "0.293945", "aux-param-colorcorrection3": "0.293945", "aux-param-colorcorrection4": "0.114258", "aux-param-colorcorrection5": "0", "aux-param-colorcorrection6": "0", "aux-param-colorcorrection7": "0", "aux-param-colorcorrection8": "0", "aux-param-colorcorrection9": "0", "aux-param-depthclampmax": "65536", "aux-param-depthclampmin": "0", "aux-param-disparityshift": "50", "controls-autoexposure-auto": "True", "controls-autoexposure-manual": "8500", "controls-color-autoexposure-auto": "True", "controls-color-autoexposure-manual": "156", "controls-color-backlight-compensation": "0", "controls-color-brightness": "0", "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-laserpower": "360", "controls-laserstate": "on", "ignoreSAD": "0", "param-autoexposure-setpoint": "1536", "param-censusenablereg-udiameter": "9", "param-censusenablereg-vdiameter": "9", "param-censususize": "9", "param-censusvsize": "9", "param-depthclampmax": "65536", "param-depthclampmin": "0", "param-depthunits": "100", "param-disableraucolor": "0", "param-disablesadcolor": "0", "param-disablesadnormalize": "0", "param-disablesloleftcolor": "0", "param-disableslorightcolor": "0", "param-disparitymode": "0", "param-disparityshift": "50", "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": "100", "stream-depth-format": "Z16", "stream-fps": "6", "stream-height": "720", "stream-width": "1280" }
Hi @laolaolulu
var pipeline = new Pipeline();
var profile = pipeline.Start();
var adv = AdvancedDevice.FromDevice(profile.Device);
adv.JsonConfiguration = File.ReadAllText("1.json");
The exception thrown: "System. AccessViolationException" (in OpenCvSharp. dll) Unhandled exceptions of the "System.AccessViolationException" type occur in OpenCvSharp.dll Attempt to read or write to protected memory. This usually indicates that other memory is corrupted.

I don't think this is related to the SDK. My best guess is that by switching from explicit Config (the commented out code) to the new code snippet, your app got a different resolution from before, resulting in over/under-flow in OpenCvSharp.dll. Can this be the case?
The program does nothing else, as long as it executes this (var adv = AdvancedDevice. FromDevice (profile. Device);) the code program exits immediately or throws System. AccessViolationException:" I couldn't find the PDB file of Intel. RealSense. dll.

I've given up using JSON files. I need to set up Disparity Shift, Laser Power... How should c# be set? Sorry, realsense has too little information about. net.
@dorodnic
I found something unusual.

Hallo @dorodnic
I also discovered something similar to the above. It seems to be some setting in the json file which is causing an access violation exception randomly within the first 5 seconds of running the camera?
I just tried to load the HighDensityPreset via a Json file I created through the RealSense viewer. Everything runs fine for around 5 seconds and then you get an access violation. It seems to have more chance of happening if I'm dragging a movable button to get pixel values to use in a measurement.
This doesn't happen without the preset loaded. Some setting must be causing instability?
Hi @KarlAbson We will try to reproduce and look into that.
Hi @dorodnic
That would be great! Thanks very much. Would it help if I sent you the sample project? It's not quite finished, could do with some improvement but I was going to send you the measuring project in C# anyway.
[Realsense Customer Engineering Team Comment] Hi @KarlAbson, @laolaolulu,
I can reproduce the similar crash issue if a json file loaded. By the way, which librealsense version do you use?
Hi @RealSense-Customer-Engineering
Great. Thanks for looking into it. I'm using 2.16.5.
Hi,
I can also reproduce the same issue. In my case with 2.17.0 librealsense version. When disposing device I also receive a System.AccessViolationException. If I don't dispose it, when I try to load a Json again I receive again a System.AccessViolationException. It looks like Json settings get device corrupted.
If I don't load any Json file, it works fine.
Hi all ! I have a similar bug when trying to load presets config stored in a json file in my C# script (running in Unity). Is there another "manual" way to set parameter values ? Thanks
Hi @OlivierHoel,
You can refer to #3088 to set the options in C#.
Thanks for the link but apparently the enum values listed in Intel.RealSense.Option only gives you access to the "standard" parameters and not the "advanced" ones (e.g. disparity shift). I couldn't find a way to set the 92 params present in my json config file (exported from the realsense viewer).
@ogoshen, any info to support the advanced parameters?
Advanced mode commands API is yet available in C# (STDepthControlGroup, STRsm, etc.)
The various functions (rs2_set_depth_control, rs2_set_rsm...) are present in NativeMethod.cs but not yet exposed through the public API of AdvancedDevice.
A PR would be more than welcome here...
In the meanwhile I can suggest getting the above fixes for AdvancedDevice, and using JSON de/serialization for getting and setting those parameters.
This is fixed. Please refer to the release note.