librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

c# D400 Series Visual Presets

Open laolaolulu opened this issue 7 years ago • 18 comments

.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" }

laolaolulu avatar Dec 06 '18 08:12 laolaolulu

Hi @laolaolulu

var pipeline = new Pipeline();
var profile = pipeline.Start();
var adv = AdvancedDevice.FromDevice(profile.Device);
adv.JsonConfiguration = File.ReadAllText("1.json");

dorodnic avatar Dec 06 '18 09:12 dorodnic

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.

tim 20181206181832 tim 20181206181713

laolaolulu avatar Dec 06 '18 10:12 laolaolulu

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?

dorodnic avatar Dec 06 '18 13:12 dorodnic

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.

tim 20181207093421

laolaolulu avatar Dec 07 '18 01:12 laolaolulu

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

laolaolulu avatar Dec 07 '18 02:12 laolaolulu

I found something unusual. tim 20181207105040

laolaolulu avatar Dec 07 '18 02:12 laolaolulu

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?

ThunderChild-001 avatar Dec 10 '18 16:12 ThunderChild-001

Hi @KarlAbson We will try to reproduce and look into that.

dorodnic avatar Dec 11 '18 07:12 dorodnic

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.

ThunderChild-001 avatar Dec 11 '18 08:12 ThunderChild-001

[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.

ThunderChild-001 avatar Dec 11 '18 15:12 ThunderChild-001

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.

amatabuena avatar Jan 10 '19 16:01 amatabuena

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

OlivierHoel avatar Feb 22 '19 02:02 OlivierHoel


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).

OlivierHoel avatar Feb 25 '19 21:02 OlivierHoel


@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.

ogoshen avatar Feb 28 '19 07:02 ogoshen


This is fixed. Please refer to the release note.