forked from Spartronics4915/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepth_auto_calibration_example.py
80 lines (60 loc) · 2.46 KB
/
depth_auto_calibration_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
## License: Apache 2.0. See LICENSE file in root directory.
## Copyright(c) 2019 Intel Corporation. All Rights Reserved.
#####################################################
## auto calibration ##
#####################################################
# First import the library
import pyrealsense2 as rs
import sys, getopt
def read_parameters(argv):
opts, args = getopt.getopt(argv, "i:", ["ifile="])
jcnt = ''
size = 0
if len(opts) > 0:
json_file = opts[0][1]
file_object = open(json_file)
jcnt = file_object.read()
size = len(jcnt)
return size, jcnt
def main(argv):
size, file_cnt = read_parameters(argv)
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 256, 144, rs.format.z16, 90)
conf = pipeline.start(config)
calib_dev = rs.auto_calibrated_device(conf.get_device())
def on_chip_calib_cb(progress):
print(". ")
while True:
try:
input = raw_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")
if input == 'c':
print("Starting on chip calibration")
new_calib, health = calib_dev.run_on_chip_calibration(5000, file_cnt, on_chip_calib_cb)
print("Calibration completed")
print("health factor = ", health)
if input == 't':
print("Starting tare calibration")
ground_truth = float(raw_input("Please enter ground truth in mm\n"))
new_calib, health = calib_dev.run_tare_calibration(ground_truth, 5000, file_cnt, on_chip_calib_cb)
print("Calibration completed")
print("health factor = ", health)
if input == 'g':
calib = calib_dev.get_calibration_table()
print("Calibration", calib)
if input == 'w':
print("Writing the new calibration")
calib_dev.set_calibration_table(new_calib)
calib_dev.write_calibration()
if input == 'e':
pipeline.stop()
return
print("Done\n")
except Exception as e:
pipeline.stop()
print(e)
except:
pipeline.stop()
print("A different Error")
if __name__ == "__main__":
main(sys.argv[1:])