Skip to content

Commit 3c43978

Browse files
committed
using the extrinsic and intrinsic matrices from the global settings
1 parent 6b37e79 commit 3c43978

1 file changed

Lines changed: 71 additions & 27 deletions

File tree

GEMstack/offboard/lidar_colorization/colorization.py

Lines changed: 71 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import cv2
77
import open3d as o3d
88

9+
from ...utils import settings
10+
911
def parse_args():
1012
parser = argparse.ArgumentParser()
11-
parser.add_argument("--folder_path", type=str, required=True)
12-
parser.add_argument("--output_path", type=str, required=True)
13-
parser.add_argument("--camera_types", type=str, required=True)
13+
parser.add_argument("--folder_path", type=str, required=True, help="Path to the folder containing the point clouds and images")
14+
parser.add_argument("--output_path", type=str, required=True, help="Path to save the output point cloud")
15+
parser.add_argument("--camera_types", type=str, required=True, help="Comma-separated list of supported camera types (fr, rr, fl, rl) to colorize")
1416
return parser.parse_args()
1517

1618

@@ -24,46 +26,55 @@ def save_ply_with_open3d(points, filename):
2426

2527
def get_camera_extrinsic_matrix(camera_type):
2628
if camera_type == "front_right" or camera_type == "fr":
27-
# From your file
28-
rotation = np.array([
29-
[-0.7168464770690616, -0.10046018208578958, 0.6899557088168523],
30-
[-0.6970911725372957, 0.12308618950445319, -0.7063382243117325],
31-
[-0.01396515249660048, -0.9872981017750231, -0.15826380744561577]
32-
])
29+
# From the settings
30+
rotation = np.array(settings.get("calibration.front_right_camera.extrinsics.rotation"))
3331

34-
translation = np.array([1.8861563355156226, -0.7733611068168774, 1.6793040225335112])
32+
translation = np.array(settings.get("calibration.front_right_camera.extrinsics.position"))
3533

3634
# Build 4x4 homogeneous transformation matrix
3735
fr_to_vehicle = np.eye(4)
3836
fr_to_vehicle[:3, :3] = rotation
3937
fr_to_vehicle[:3, 3] = translation
4038
return fr_to_vehicle
4139
elif camera_type == "rear_right" or camera_type == "rr":
42-
# From your file
43-
rotation = np.array([
44-
[-0.7359657309159472, 0.15986191414426415, -0.6578743127098735],
45-
[0.6768157805459531, 0.14993386619459964, -0.7207220233709469],
46-
[-0.016578363047300385, -0.9756864271752846, -0.21854325362408236]
47-
])
40+
# From the settings
41+
rotation = np.array(settings.get("calibration.rear_right_camera.extrinsics.rotation"))
4842

49-
translation = np.array([0.11419591502518789, -0.6896311735924415, 1.711181163333824])
43+
translation = np.array(settings.get("calibration.rear_right_camera.extrinsics.position"))
5044

5145
# Build 4x4 homogeneous transformation matrix
5246
rr_to_vehicle = np.eye(4)
5347
rr_to_vehicle[:3, :3] = rotation
5448
rr_to_vehicle[:3, 3] = translation
5549
return rr_to_vehicle
50+
elif camera_type == "front_left" or camera_type == "fl":
51+
rotation = np.array(settings.get("calibration.front_left_camera.extrinsics.rotation"))
52+
translation = np.array(settings.get("calibration.front_left_camera.extrinsics.position"))
53+
54+
# Build 4x4 homogeneous transformation matrix
55+
fl_to_vehicle = np.eye(4)
56+
fl_to_vehicle[:3, :3] = rotation
57+
fl_to_vehicle[:3, 3] = translation
58+
return fl_to_vehicle
59+
elif camera_type == "rear_left" or camera_type == "rl":
60+
rotation = np.array(settings.get("calibration.rear_left_camera.extrinsics.rotation"))
61+
translation = np.array(settings.get("calibration.rear_left_camera.extrinsics.position"))
62+
63+
# Build 4x4 homogeneous transformation matrix
64+
rl_to_vehicle = np.eye(4)
65+
rl_to_vehicle[:3, :3] = rotation
66+
rl_to_vehicle[:3, 3] = translation
67+
return rl_to_vehicle
5668
else:
5769
raise ValueError(f"Camera type {camera_type} not supported")
5870

5971
def get_camera_intrinsic_matrix(camera_type):
6072
if camera_type == "front_right" or camera_type == "fr":
6173
# Provided intrinsics
62-
focal = [1176.2554468073797, 1175.1456876174707] # fx, fy
63-
center = [966.4326452411585, 608.5803255934914] # cx, cy
64-
fr_cam_distort = [-0.2701363254469883, 0.16439325523243875, -0.001607207824773341, -7.412467081891699e-05,
65-
-0.06199397580030171]
66-
skew = 0 # assume no skew
74+
focal = settings.get("calibration.front_right_camera.intrinsics.focal") # fx, fy
75+
center = settings.get("calibration.front_right_camera.intrinsics.center") # cx, cy
76+
fr_cam_distort = settings.get("calibration.front_right_camera.intrinsics.distort")
77+
skew = settings.get("calibration.front_right_camera.intrinsics.skew")
6778

6879
fx, fy = focal
6980
cx, cy = center
@@ -77,11 +88,10 @@ def get_camera_intrinsic_matrix(camera_type):
7788
return fr_cam_K, np.array(fr_cam_distort)
7889
elif camera_type == "rear_right" or camera_type == "rr":
7990
# Provided intrinsics
80-
focal = [1162.3787554048329, 1162.855381183851] # fx, fy
81-
center = [956.2663906909728, 569.2039945552984] # cx, cy
82-
rr_cam_distort = [-0.25040910859151444, 0.1109210921906881, -0.00041247665414900384, 0.0008205455176671751,
83-
-0.026395952816984845]
84-
skew = 0 # assume no skew
91+
focal = settings.get("calibration.rear_right_camera.intrinsics.focal") # fx, fy
92+
center = settings.get("calibration.rear_right_camera.intrinsics.center") # cx, cy
93+
rr_cam_distort = settings.get("calibration.rear_right_camera.intrinsics.distort")
94+
skew = settings.get("calibration.rear_right_camera.intrinsics.skew")
8595

8696
fx, fy = focal
8797
cx, cy = center
@@ -93,6 +103,40 @@ def get_camera_intrinsic_matrix(camera_type):
93103
[0, 0, 1]
94104
])
95105
return rr_cam_K, np.array(rr_cam_distort)
106+
elif camera_type == "front_left" or camera_type == "fl":
107+
# Provided intrinsics
108+
focal = settings.get("calibration.front_left_camera.intrinsics.focal") # fx, fy
109+
center = settings.get("calibration.front_left_camera.intrinsics.center") # cx, cy
110+
fl_cam_distort = settings.get("calibration.front_left_camera.intrinsics.distort")
111+
skew = settings.get("calibration.front_left_camera.intrinsics.skew")
112+
113+
fx, fy = focal
114+
cx, cy = center
115+
116+
# Build K matrix
117+
fl_cam_K = np.array([
118+
[fx, skew, cx],
119+
[0, fy, cy],
120+
[0, 0, 1]
121+
])
122+
return fl_cam_K, np.array(fl_cam_distort)
123+
elif camera_type == "rear_left" or camera_type == "rl":
124+
# Provided intrinsics
125+
focal = settings.get("calibration.rear_left_camera.intrinsics.focal") # fx, fy
126+
center = settings.get("calibration.rear_left_camera.intrinsics.center") # cx, cy
127+
rl_cam_distort = settings.get("calibration.rear_left_camera.intrinsics.distort")
128+
skew = settings.get("calibration.rear_left_camera.intrinsics.skew")
129+
130+
fx, fy = focal
131+
cx, cy = center
132+
133+
# Build K matrix
134+
rl_cam_K = np.array([
135+
[fx, skew, cx],
136+
[0, fy, cy],
137+
[0, 0, 1]
138+
])
139+
return rl_cam_K, np.array(rl_cam_distort)
96140
else:
97141
raise ValueError(f"Camera type {camera_type} not supported")
98142

0 commit comments

Comments
 (0)