depth_auto_calibration_example.py
Go to the documentation of this file.
1 ## License: Apache 2.0. See LICENSE file in root directory.
2 ## Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #####################################################
5 ## auto calibration ##
6 #####################################################
7 
8 # First import the library
9 import pyrealsense2 as rs
10 import sys, getopt
11 def read_parameters(argv):
12  opts, args = getopt.getopt(argv, "i:", ["ifile="])
13  jcnt = ''
14  size = 0
15 
16  if len(opts) > 0:
17  json_file = opts[0][1]
18  file_object = open(json_file)
19  jcnt = file_object.read()
20  size = len(jcnt)
21 
22  return size, jcnt
23 
24 def main(argv):
25 
26  size, file_cnt = read_parameters(argv)
27 
28  pipeline = rs.pipeline()
29  config = rs.config()
30 
31  # Get device product line for setting a supporting resolution
32  pipeline_wrapper = rs.pipeline_wrapper(pipeline)
33  pipeline_profile = config.resolve(pipeline_wrapper)
34  device = pipeline_profile.get_device()
35 
36  auto_calibrated_device = rs.auto_calibrated_device(device)
37 
38  if not auto_calibrated_device:
39  print("The connected device does not support auto calibration")
40  return
41 
42 
43  config.enable_stream(rs.stream.depth, 256, 144, rs.format.z16, 90)
44  conf = pipeline.start(config)
45  calib_dev = rs.auto_calibrated_device(conf.get_device())
46 
47  def on_chip_calib_cb(progress):
48  print(". ")
49 
50  while True:
51  try:
52  operation = input("Please select what the operation you want to do\nc - on chip calibration\nt - tare calibration\ng - get the active calibration\nw - write new calibration\ne - exit\n")
53 
54  if operation == 'c':
55  print("Starting on chip calibration")
56  new_calib, health = calib_dev.run_on_chip_calibration(file_cnt, on_chip_calib_cb, 5000)
57  print("Calibration completed")
58  print("health factor = ", health)
59 
60  if operation == 't':
61  print("Starting tare calibration")
62  ground_truth = float(input("Please enter ground truth in mm\n"))
63  new_calib, health = calib_dev.run_tare_calibration(ground_truth, file_cnt, on_chip_calib_cb, 5000)
64  print("Calibration completed")
65  print("health factor = ", health)
66 
67  if operation == 'g':
68  calib = calib_dev.get_calibration_table()
69  print("Calibration", calib)
70 
71  if operation == 'w':
72  print("Writing the new calibration")
73  calib_dev.set_calibration_table(new_calib)
74  calib_dev.write_calibration()
75 
76  if operation == 'e':
77  pipeline.stop()
78  return
79 
80  print("Done\n")
81  except Exception as e:
82  print(e)
83  except:
84  print("A different Error")
85 
86 
87 
88 
89 if __name__ == "__main__":
90  main(sys.argv[1:])
static std::string print(const transformation &tf)


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