MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / get_data

Method get_data

eval_code/recons/datasets/sevenscenes.py:112–195  ·  view source on GitHub ↗
(
            self,
            index: Optional[int] = None,
            sequence_name: Optional[str] = None,
            ids: Union[List[int], np.ndarray, None] = None,
        )

Source from the content-addressed store, hash-verified

110 return self.get_data(index=index, ids=ids)
111
112 def get_data(
113 self,
114 index: Optional[int] = None,
115 sequence_name: Optional[str] = None,
116 ids: Union[List[int], np.ndarray, None] = None,
117 ):
118 if sequence_name is None:
119 if index is None:
120 raise ValueError("Please specify either index or sequence_name")
121 sequence_name: str = self.sequence_list[index]
122 seq_len: int = self.metadata[sequence_name]
123
124 if ids is None:
125 ids = np.arange(seq_len).tolist()
126 elif isinstance(ids, np.ndarray):
127 assert ids.ndim == 1, f"ids should be a 1D array, but got {ids.ndim}D"
128 ids = ids.tolist()
129
130 fx, fy, cx, cy = 525, 525, 320, 240 # hard code
131
132 image_paths: list = [""] * len(ids)
133 images: list = [0] * len(ids)
134 depths: list = [0] * len(ids)
135 extrinsics: np.ndarray = np.zeros((len(ids), 3, 4)) # (S, 3, 4)
136 intrinsics: np.ndarray = np.tile(
137 np.array(
138 [
139 [fx, 0, cx],
140 [0, fy, cy],
141 [0, 0, 1 ]
142 ],
143 dtype=np.float32
144 ),
145 reps=(len(ids), 1, 1)
146 ) # (S, 3, 3)
147
148 for id_index, id in enumerate(ids):
149
150 impath: str = osp.join(self.SEVENSCENES_DIR, sequence_name, f"frame-{id:06d}.color.png")
151 depthpath: str = osp.join(self.SEVENSCENES_DIR, sequence_name, f"frame-{id:06d}.depth.proj.png")
152 posepath: str = osp.join(self.SEVENSCENES_DIR, sequence_name, f"frame-{id:06d}.pose.txt")
153
154 rgb_image: Image.Image = Image.open(impath)
155 depthmap: np.ndarray = imageio.v2.imread(depthpath)
156 assert depthmap.shape == (480, 640), f"Depth map shape {depthmap.shape} does not match expected (480, 640)"
157 rgb_image: Image.Image = resize_image(rgb_image, (depthmap.shape[1], depthmap.shape[0]))
158
159 depthmap[depthmap == 65535] = 0
160 depthmap = np.nan_to_num(depthmap.astype(np.float32), 0.0) / 1000.0
161 depthmap[depthmap > 10] = 0 # to far, invalid
162 depthmap[depthmap < 1e-3] = 0 # to near, invalid
163
164 rgb_image, depthmap, intrinsics[id_index] = resize_image_depth_and_intrinsic(
165 image=rgb_image,
166 depth_map=depthmap,
167 intrinsic=intrinsics[id_index],
168 output_width=self.load_img_size, # finally width = 518, height = 388
169 )

Callers 1

__getitem__Method · 0.95

Calls 6

resize_imageFunction · 0.90
closed_form_inverse_se3Function · 0.90
openMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected