MCPcopy Create free account
hub / github.com/SceneFun3D/scenefun3d / DataParser

Class DataParser

utils/data_parser.py:124–742  ·  view source on GitHub ↗

A class for parsing data files in the SceneFun3D dataset.

Source from the content-addressed store, hash-verified

122 return angle_axis.flatten() # Return as a 1D array (rotation vector)
123
124class DataParser:
125 """
126 A class for parsing data files in the SceneFun3D dataset.
127 """
128
129 def __init__(self, data_root_path):
130 """
131 Initialize the DataParser instance with the root path.
132
133 Args:
134 data_root_path (str): The root path where data is located.
135 """
136 self.data_root_path = os.path.join(data_root_path)
137
138 def TrajStringToMatrix(self, traj_str):
139 """
140 Converts a line from the camera trajectory file into translation and rotation matrices.
141
142 Args:
143 traj_str (str): A space-delimited string where each line represents a camera pose at a particular timestamp.
144 The line consists of seven columns:
145 - Column 1: timestamp
146 - Columns 2-4: rotation (axis-angle representation in radians)
147 - Columns 5-7: translation (in meters)
148
149 Returns:
150 (tuple): A tuple containing:
151 - ts (str): Timestamp.
152 - Rt (numpy.ndarray): 4x4 transformation matrix representing rotation and translation.
153
154 Raises:
155 AssertionError: If the input string does not have exactly seven columns.
156 """
157 tokens = traj_str.split()
158 assert len(tokens) == 7
159 ts = tokens[0]
160
161 # Rotation in angle axis
162 angle_axis = [float(tokens[1]), float(tokens[2]), float(tokens[3])]
163 r_w_to_p = convert_angle_axis_to_matrix3(np.asarray(angle_axis))
164
165 # Translation
166 t_w_to_p = np.asarray([float(tokens[4]), float(tokens[5]), float(tokens[6])])
167 extrinsics = np.eye(4, 4)
168 extrinsics[:3, :3] = r_w_to_p
169 extrinsics[:3, -1] = t_w_to_p
170 Rt = np.linalg.inv(extrinsics)
171
172 return (ts, Rt)
173
174 def get_camera_trajectory(self, visit_id, video_id, pose_source="colmap"):
175 """
176 Retrieve the camera trajectory from a file and convert it into a dictionary whose keys are timestamps and
177 values are the corresponding camera poses.
178
179 Args:
180 visit_id (str): The identifier of the scene.
181 video_id (str): The identifier of the video sequence.

Callers 5

mainFunction · 0.90
mainFunction · 0.90
export_sceneFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected