rectified_focal_length_utility.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # @file rectified_focal_length_utility.cc
4 #
5 # Copyright 2013-2025
6 # Carnegie Robotics, LLC
7 # 4501 Hatfield Street, Pittsburgh, PA 15201
8 # http://www.carnegierobotics.com
9 #
10 # All rights reserved.
11 #
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions are met:
14 # * Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # * Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # * Neither the name of the Carnegie Robotics, LLC nor the
20 # names of its contributors may be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 # DISCLAIMED. IN NO EVENT SHALL CARNEGIE ROBOTICS, LLC BE LIABLE FOR ANY
27 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34 # Significant history (date, user, job code, action):
35 # 2025-02-08, malvarado@carnegierobotics.com, IRAD, Created file.
36 #
37 
38 import argparse
39 
40 import libmultisense as lms
41 
42 def update_calibration(cal, new_focal_length):
43  print("Updating focal length from", cal.left.P[0][0], "to", new_focal_length)
44 
45  cal.left.P[0][0] = new_focal_length
46  cal.left.P[1][1] = new_focal_length
47 
48  right_tx = cal.right.P[0][3] / cal.right.P[0][0]
49  cal.right.P[0][0] = new_focal_length
50  cal.right.P[1][1] = new_focal_length
51  cal.right.P[0][3] = new_focal_length * right_tx
52 
53  if cal.aux:
54  aux_tx = cal.aux.P[0][3] / cal.aux.P[0][0]
55  aux_ty = cal.aux.P[1][3] / cal.aux.P[1][1]
56 
57  cal.aux.P[0][0] = new_focal_length
58  cal.aux.P[1][1] = new_focal_length
59  cal.aux.P[0][3] = new_focal_length * aux_tx
60  cal.aux.P[1][3] = new_focal_length * aux_ty
61 
62  return cal;
63 
64 def main(args):
65  channel_config = lms.ChannelConfig()
66  channel_config.ip_address = args.ip_address
67  channel_config.mtu = args.mtu
68 
69  with lms.Channel.create(channel_config) as channel:
70  if not channel:
71  print("Invalid channel")
72  exit(1)
73 
74  current_calibration = channel.get_calibration();
75 
76  new_calibration = update_calibration(current_calibration, args.rectified_focal_length)
77 
78  if args.set:
79  if channel.set_calibration(new_calibration) != lms.Status.OK:
80  print("Failed to set the updated calibration")
81  exit(1)
82 
83 if __name__ == '__main__':
84  parser = argparse.ArgumentParser("LibMultiSense save image utility")
85  parser.add_argument("-a", "--ip_address", default="10.66.171.21", help="The IPv4 address of the MultiSense.")
86  parser.add_argument("-m", "--mtu", type=int, default=1500, help="The MTU to use to communicate with the camera.")
87  parser.add_argument("-r", "--rectified-focal-length", type=float, required=True, help="The new rectified focal length")
88  parser.add_argument("-s", "--set", action="store_true", help="Write the new calibration to camera")
89  main(parser.parse_args())
rectified_focal_length_utility.update_calibration
def update_calibration(cal, new_focal_length)
Definition: rectified_focal_length_utility.py:42
rectified_focal_length_utility.main
def main(args)
Definition: rectified_focal_length_utility.py:64


multisense_lib
Author(s):
autogenerated on Thu Apr 17 2025 02:49:09