-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFlip_Camera_Config_File.py
More file actions
61 lines (45 loc) · 2.32 KB
/
Copy pathFlip_Camera_Config_File.py
File metadata and controls
61 lines (45 loc) · 2.32 KB
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
# Copyright (C) 2026: Arizona Board of Regents on Behalf of the University of Arizona
#
# Script to flip a camera configuration file, rotating the entire system by 180 degrees
# around the camera's origin. This is useful when a camera must be calibrated mounted
# upside-down on a platform but then mounted right-side-up in use.
import builtins
import json
import argparse
import numpy as np
from scipy.spatial.transform import Rotation as R
def nested_rotations(X1, Y1, Z1, X2, Y2, Z2):
# Create first set of rotations
rot_1 = R.from_euler('XYZ', [X1, Y1, Z1], degrees=True)
# Apply the second set of rotations in the new coordinate system
rot_2 = R.from_euler('XYZ', [X2, Y2, Z2], degrees=True)
final_rotation = rot_1 * rot_2
# Get the quaternion
quaternion = final_rotation.as_quat()
# Convert the quaternion to Euler angles (XYZ order)
euler_angles = final_rotation.as_euler('XYZ', degrees=True)
return euler_angles
def main():
print("Flip_Camera_Config_File.py version 1.0.0");
parser = argparse.ArgumentParser(description="Flip a camera configuration file 180 degrees around Y.")
parser.add_argument('input', type=str, help='Input JSON file name')
parser.add_argument('output', type=str, help='Output JSON file name')
args = parser.parse_args()
# Load the input JSON file
with open(args.input, 'r') as json_file:
data = json.load(json_file)
# Flip the positions and orientations of each camera
for camera in data['cameras']:
# Flip position
camera['positionMeters'][0] = -camera['positionMeters'][0] # Negate X coordinate
camera['positionMeters'][2] = -camera['positionMeters'][2] # Negate Z coordinate
# Flip orientation
original_euler = camera['orientationDegrees'] # Assuming orientation is in Euler angles [X, Y, Z]
flipped_euler = nested_rotations(0, 180, 0, original_euler[0], original_euler[1], original_euler[2])
camera['orientationDegrees'] = flipped_euler.tolist()
# Write the flipped camera configurations
with open(args.output, 'w') as json_file:
json.dump(data, json_file, indent=2)
print(f"Data has been written to {args.output} with {len(data['cameras'])} entries.")
if __name__ == "__main__":
main()