python-rs400-advanced-mode-example.py
Go to the documentation of this file.
1 ## License: Apache 2.0. See LICENSE file in root directory.
2 ## Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #####################################################
5 ## rs400 advanced mode tutorial ##
6 #####################################################
7 
8 # First import the library
9 import pyrealsense2 as rs
10 import time
11 import json
12 
13 DS5_product_ids = ["0AD1", "0AD2", "0AD3", "0AD4", "0AD5", "0AF6", "0AFE", "0AFF", "0B00", "0B01", "0B03", "0B07", "0B3A", "0B5C"]
14 
16  ctx = rs.context()
17  ds5_dev = rs.device()
18  devices = ctx.query_devices();
19  for dev in devices:
20  if dev.supports(rs.camera_info.product_id) and str(dev.get_info(rs.camera_info.product_id)) in DS5_product_ids:
21  if dev.supports(rs.camera_info.name):
22  print("Found device that supports advanced mode:", dev.get_info(rs.camera_info.name))
23  return dev
24  raise Exception("No D400 product line device that supports advanced mode was found")
25 
26 try:
28  advnc_mode = rs.rs400_advanced_mode(dev)
29  print("Advanced mode is", "enabled" if advnc_mode.is_enabled() else "disabled")
30 
31  # Loop until we successfully enable advanced mode
32  while not advnc_mode.is_enabled():
33  print("Trying to enable advanced mode...")
34  advnc_mode.toggle_advanced_mode(True)
35  # At this point the device will disconnect and re-connect.
36  print("Sleeping for 5 seconds...")
37  time.sleep(5)
38  # The 'dev' object will become invalid and we need to initialize it again
40  advnc_mode = rs.rs400_advanced_mode(dev)
41  print("Advanced mode is", "enabled" if advnc_mode.is_enabled() else "disabled")
42 
43  # Get each control's current value
44  print("Depth Control: \n", advnc_mode.get_depth_control())
45  print("RSM: \n", advnc_mode.get_rsm())
46  print("RAU Support Vector Control: \n", advnc_mode.get_rau_support_vector_control())
47  print("Color Control: \n", advnc_mode.get_color_control())
48  print("RAU Thresholds Control: \n", advnc_mode.get_rau_thresholds_control())
49  print("SLO Color Thresholds Control: \n", advnc_mode.get_slo_color_thresholds_control())
50  print("SLO Penalty Control: \n", advnc_mode.get_slo_penalty_control())
51  print("HDAD: \n", advnc_mode.get_hdad())
52  print("Color Correction: \n", advnc_mode.get_color_correction())
53  print("Depth Table: \n", advnc_mode.get_depth_table())
54  print("Auto Exposure Control: \n", advnc_mode.get_ae_control())
55  print("Census: \n", advnc_mode.get_census())
56 
57  #To get the minimum and maximum value of each control use the mode value:
58  query_min_values_mode = 1
59  query_max_values_mode = 2
60  current_std_depth_control_group = advnc_mode.get_depth_control()
61  min_std_depth_control_group = advnc_mode.get_depth_control(query_min_values_mode)
62  max_std_depth_control_group = advnc_mode.get_depth_control(query_max_values_mode)
63  print("Depth Control Min Values: \n ", min_std_depth_control_group)
64  print("Depth Control Max Values: \n ", max_std_depth_control_group)
65 
66  # Set some control with a new (median) value
67  current_std_depth_control_group.scoreThreshA = int((max_std_depth_control_group.scoreThreshA - min_std_depth_control_group.scoreThreshA) / 2)
68  advnc_mode.set_depth_control(current_std_depth_control_group)
69  print("After Setting new value, Depth Control: \n", advnc_mode.get_depth_control())
70 
71  # Serialize all controls to a Json string
72  serialized_string = advnc_mode.serialize_json()
73  print("Controls as JSON: \n", serialized_string)
74  as_json_object = json.loads(serialized_string)
75 
76  # We can also load controls from a json string
77  # For Python 2, the values in 'as_json_object' dict need to be converted from unicode object to utf-8
78  if type(next(iter(as_json_object))) != str:
79  as_json_object = {k.encode('utf-8'): v.encode("utf-8") for k, v in as_json_object.items()}
80  # The C++ JSON parser requires double-quotes for the json object so we need
81  # to replace the single quote of the pythonic json to double-quotes
82  json_string = str(as_json_object).replace("'", '\"')
83  advnc_mode.load_json(json_string)
84 
85 except Exception as e:
86  print(e)
87  pass
static std::string print(const transformation &tf)
void next(auto_any_t cur, type2type< T, C > *)
Definition: foreach.hpp:757


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39