LOADING IN JSON WITH PYTHON
| Camera Model | {D400 } | | Operating System & Version | {Linux (Ubuntu 14/16/17) | | Kernel Version (Linux Only) | (e.g. 4.14.13) |
I tried executing the following python example
DS5_product_ids = ["0AD1", "0AD2", "0AD3", "0AD4", "0AD5", "0AF6", "0AFE", "0AFF", "0B00", "0B01", "0B03", "0B07"]
def find_device_that_supports_advanced_mode() :
ctx = rs.context()
ds5_dev = rs.device()
devices = ctx.query_devices();
for dev in devices:
if dev.supports(rs.camera_info.product_id) and str(dev.get_info(rs.camera_info.product_id)) in DS5_product_ids:
if dev.supports(rs.camera_info.name):
print("Found device that supports advanced mode:", dev.get_info(rs.camera_info.name))
return dev
raise Exception("No device that supports advanced mode was found")
try:
dev = find_device_that_supports_advanced_mode()
advnc_mode = rs.rs400_advanced_mode(dev)
print("Advanced mode is", "enabled" if advnc_mode.is_enabled() else "disabled")
# Loop until we successfully enable advanced mode
while not advnc_mode.is_enabled():
print("Trying to enable advanced mode...")
advnc_mode.toggle_advanced_mode(True)
# At this point the device will disconnect and re-connect.
print("Sleeping for 5 seconds...")
time.sleep(5)
# The 'dev' object will become invalid and we need to initialize it again
dev = find_device_that_supports_advanced_mode()
advnc_mode = rs.rs400_advanced_mode(dev)
print("Advanced mode is", "enabled" if advnc_mode.is_enabled() else "disabled")
# Get each control's current value
print("Depth Control: '\n'", advnc_mode.get_depth_control())
print("RSM: /n", advnc_mode.get_rsm())
print("RAU Support Vector Control: /n", advnc_mode.get_rau_support_vector_control())
print("Color Control: /n", advnc_mode.get_color_control())
print("RAU Thresholds Control: /n", advnc_mode.get_rau_thresholds_control())
print("SLO Color Thresholds Control: /n", advnc_mode.get_slo_color_thresholds_control())
print("SLO Penalty Control: /n", advnc_mode.get_slo_penalty_control())
print("HDAD: /n", advnc_mode.get_hdad())
print("Color Correction: /n", advnc_mode.get_color_correction())
print("Depth Table: /n", advnc_mode.get_depth_table())
print("Auto Exposure Control: /n", advnc_mode.get_ae_control())
print("Census: /n", advnc_mode.get_census())
#To get the minimum and maximum value of each control use the mode value:
query_min_values_mode = 1
query_max_values_mode = 2
current_std_depth_control_group = advnc_mode.get_depth_control()
min_std_depth_control_group = advnc_mode.get_depth_control(query_min_values_mode)
max_std_depth_control_group = advnc_mode.get_depth_control(query_max_values_mode)
print("Depth Control Min Values: \n ", min_std_depth_control_group)
print("Depth Control Max Values: \n ", max_std_depth_control_group)
# Set some control with a new (median) value
current_std_depth_control_group.scoreThreshA = int((max_std_depth_control_group.scoreThreshA - min_std_depth_control_group.scoreThreshA) / 2)
advnc_mode.set_depth_control(current_std_depth_control_group)
print("After Setting new value, Depth Control: \n", advnc_mode.get_depth_control())
# Serialize all controls to a Json string
serialized_string = advnc_mode.serialize_json()
print("Controls as JSON: \n", serialized_string)
as_json_object = json.loads(serialized_string)
# We can also load controls from a json string
# The C++ JSON parser requires double-quotes for the json object so we need
# to replace the single quote of the pythonic json to double-quotes
json_string = str(as_json_object).replace("'", '\"')
**advnc_mode.load_json(json_string)**
except Exception as e:
print(e)
pass
And I get the following error:
parse error - unexpected 'u'; expected string literal
Any thoughts on how to fix this?
Here is the full output of the example:
('Found device that supports advanced mode:', u'Intel RealSense D415') ('Advanced mode is', 'enabled') ("Depth Control: '\n'", minusDecrement: 10, deepSeaMedianThreshold: 500, scoreThreshA: 511, scoreThreshB: 2047, textureDifferenceThreshold: 0, textureCountThreshold: 0, deepSeaSecondPeakThreshold: 325, deepSeaNeighborThreshold: 7, lrAgreeThreshold: 24) ('RSM: /n', rsmBypass: 0, diffThresh: 4, sloRauDiffThresh: 1, removeThresh: 63) ('RAU Support Vector Control: /n', minWest: 1, minEast: 1, minWEsum: 3, minNorth: 1, minSouth: 1, minNSsum: 3, uShrink: 3, vShrink: 1) ('Color Control: /n', disableSADColor: 0, disableRAUColor: 0, disableSLORightColor: 0, disableSLOLeftColor: 0, disableSADNormalize: 0) ('RAU Thresholds Control: /n', rauDiffThresholdRed: 51, rauDiffThresholdGreen: 51, rauDiffThresholdBlue: 51) ('SLO Color Thresholds Control: /n', diffThresholdRed: 72, diffThresholdGreen: 72, diffThresholdBlue: 72) ('SLO Penalty Control: /n', sloK1Penalty: 60, sloK2Penalty: 342, sloK1PenaltyMod1: 105, sloK2PenaltyMod1: 190, sloK1PenaltyMod2: 70, sloK2PenaltyMod2: 130) ('HDAD: /n', lambdaCensus: 26, lambdaAD: 800, ignoreSAD: 0) ('Color Correction: /n', colorCorrection1: 0.461914, colorCorrection2: 0.540039, colorCorrection3: 0.540039, colorCorrection4: 0.208008, colorCorrection5: -0.332031, colorCorrection6: -0.212891, colorCorrection7: -0.212891, colorCorrection8: 0.68457, colorCorrection9: 0.930664, colorCorrection10: -0.553711, colorCorrection11: -0.553711, colorCorrection12: 0.0458984) ('Depth Table: /n', depthUnits: 1000, depthClampMin: 0, depthClampMax: 65536, disparityMode: 0, disparityShift: 0) ('Auto Exposure Control: /n', Mean Intensity Set Point: 400) ('Census: /n', uDiameter: 9, vDiameter: 9) ('Depth Control Min Values: \n ', minusDecrement: 0, deepSeaMedianThreshold: 0, scoreThreshA: 0, scoreThreshB: 0, textureDifferenceThreshold: 0, textureCountThreshold: 0, deepSeaSecondPeakThreshold: 0, deepSeaNeighborThreshold: 0, lrAgreeThreshold: 0) ('Depth Control Max Values: \n ', minusDecrement: 255, deepSeaMedianThreshold: 1023, scoreThreshA: 1023, scoreThreshB: 4095, textureDifferenceThreshold: 4095, textureCountThreshold: 1023, deepSeaSecondPeakThreshold: 1023, deepSeaNeighborThreshold: 1023, lrAgreeThreshold: 2047) ('After Setting new value, Depth Control: \n', minusDecrement: 10, deepSeaMedianThreshold: 500, scoreThreshA: 511, scoreThreshB: 2047, textureDifferenceThreshold: 0, textureCountThreshold: 0, deepSeaSecondPeakThreshold: 325, deepSeaNeighborThreshold: 7, lrAgreeThreshold: 24) ('Controls as JSON: \n', u'{\n "aux-param-autoexposure-setpoint": "400",\n "aux-param-colorcorrection1": "0.461914",\n "aux-param-colorcorrection10": "-0.553711",\n "aux-param-colorcorrection11": "-0.553711",\n "aux-param-colorcorrection12": "0.0458984",\n "aux-param-colorcorrection2": "0.540039",\n "aux-param-colorcorrection3": "0.540039",\n "aux-param-colorcorrection4": "0.208008",\n "aux-param-colorcorrection5": "-0.332031",\n "aux-param-colorcorrection6": "-0.212891",\n "aux-param-colorcorrection7": "-0.212891",\n "aux-param-colorcorrection8": "0.68457",\n "aux-param-colorcorrection9": "0.930664",\n "aux-param-depthclampmax": "65536",\n "aux-param-depthclampmin": "0",\n "aux-param-disparityshift": "0",\n "controls-autoexposure-auto": "True",\n "controls-autoexposure-manual": "33000",\n "controls-color-autoexposure-auto": "True",\n "controls-color-autoexposure-manual": "166",\n "controls-color-backlight-compensation": "0",\n "controls-color-brightness": "0",\n "controls-color-contrast": "50",\n "controls-color-gain": "64",\n "controls-color-gamma": "300",\n "controls-color-hue": "0",\n "controls-color-power-line-frequency": "3",\n "controls-color-saturation": "64",\n "controls-color-sharpness": "50",\n "controls-color-white-balance-auto": "True",\n "controls-color-white-balance-manual": "4600",\n "controls-depth-gain": "16",\n "controls-depth-white-balance-auto": "False",\n "controls-laserpower": "150",\n "controls-laserstate": "on",\n "ignoreSAD": "0",\n "param-autoexposure-setpoint": "400",\n "param-censusenablereg-udiameter": "9",\n "param-censusenablereg-vdiameter": "9",\n "param-censususize": "9",\n "param-censusvsize": "9",\n "param-depthclampmax": "65536",\n "param-depthclampmin": "0",\n "param-depthunits": "1000",\n "param-disableraucolor": "0",\n "param-disablesadcolor": "0",\n "param-disablesadnormalize": "0",\n "param-disablesloleftcolor": "0",\n "param-disableslorightcolor": "0",\n "param-disparitymode": "0",\n "param-disparityshift": "0",\n "param-lambdaad": "800",\n "param-lambdacensus": "26",\n "param-leftrightthreshold": "24",\n "param-maxscorethreshb": "2047",\n "param-medianthreshold": "500",\n "param-minscorethresha": "511",\n "param-neighborthresh": "7",\n "param-raumine": "1",\n "param-rauminn": "1",\n "param-rauminnssum": "3",\n "param-raumins": "1",\n "param-rauminw": "1",\n "param-rauminwesum": "3",\n "param-regioncolorthresholdb": "0.0499022",\n "param-regioncolorthresholdg": "0.0499022",\n "param-regioncolorthresholdr": "0.0499022",\n "param-regionshrinku": "3",\n "param-regionshrinkv": "1",\n "param-robbinsmonrodecrement": "10",\n "param-robbinsmonroincrement": "10",\n "param-rsmdiffthreshold": "4",\n "param-rsmrauslodiffthreshold": "1",\n "param-rsmremovethreshold": "0.375",\n "param-scanlineedgetaub": "72",\n "param-scanlineedgetaug": "72",\n "param-scanlineedgetaur": "72",\n "param-scanlinep1": "60",\n "param-scanlinep1onediscon": "105",\n "param-scanlinep1twodiscon": "70",\n "param-scanlinep2": "342",\n "param-scanlinep2onediscon": "190",\n "param-scanlinep2twodiscon": "130",\n "param-secondpeakdelta": "325",\n "param-texturecountthresh": "0",\n "param-texturedifferencethresh": "0",\n "param-usersm": "1",\n "param-zunits": "1000"\n}') parse error - unexpected 'u'; expected string literal
Never mind, this is fixed simply by switching to python3