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

Method get_data

eval_code/recons/datasets/dtu.py:144–240  ·  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

142 return self.get_data(index=index, ids=ids)
143
144 def get_data(
145 self,
146 index: Optional[int] = None,
147 sequence_name: Optional[str] = None,
148 ids: Union[List[int], np.ndarray, None] = None,
149 ):
150 if sequence_name is None:
151 if index is None:
152 raise ValueError("Please specify either index or sequence_name")
153 sequence_name: str = self.sequence_list[index]
154 seq_len: int = self.metadata[sequence_name]
155
156 if ids is None:
157 ids = np.arange(seq_len).tolist()
158 elif isinstance(ids, np.ndarray):
159 assert ids.ndim == 1, f"ids should be a 1D array, but got {ids.ndim}D"
160 ids = ids.tolist()
161
162 image_path = osp.join(self.DTU_DIR, sequence_name, "images")
163 depth_path = osp.join(self.DTU_DIR, sequence_name, "depths")
164 mask_path = osp.join(self.DTU_DIR, sequence_name, "binary_masks")
165 cam_path = osp.join(self.DTU_DIR, sequence_name, "cams")
166
167 image_paths: list = [""] * len(ids)
168 images: list = [0] * len(ids)
169 depths: list = [0] * len(ids)
170 extrinsics: np.ndarray = np.zeros((len(ids), 3, 4))
171 intrinsics: np.ndarray = np.zeros((len(ids), 3, 3))
172
173 for id_index, id in enumerate(ids):
174 impath = osp.join(image_path, f"{id:08d}.jpg")
175 depthpath = osp.join(depth_path, f"{id:08d}.npy")
176 campath = osp.join(cam_path, f"{id:08d}_cam.txt")
177 maskpath = osp.join(mask_path, f"{id:08d}.png")
178
179 rgb_image: Image.Image = Image.open(impath)
180 depthmap: np.ndarray = np.load(depthpath)
181 rgb_image: Image.Image = resize_image(rgb_image, (depthmap.shape[1], depthmap.shape[0]))
182
183 depthmap = np.nan_to_num(depthmap.astype(np.float32), 0.0)
184
185 mask_pil = Image.open(maskpath)
186
187 # 如果图像本身是单通道,保持原样
188 if mask_pil.mode in ['L', '1']: # L:灰度, 1:二值
189 mask = np.array(mask_pil) / 255.0
190 else:
191 # 如果是多通道,转换为灰度
192 mask = np.array(mask_pil.convert('L')) / 255.0
193 mask = mask.astype(np.float32)
194
195 mask[mask > 0.5] = 1.0
196 mask[mask < 0.5] = 0.0
197
198 mask = cv2.resize(
199 mask,
200 (depthmap.shape[1], depthmap.shape[0]),
201 interpolation=cv2.INTER_NEAREST,

Callers 5

__getitem__Method · 0.95
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 8

resize_imageFunction · 0.90
load_cam_mvsnetFunction · 0.85
openMethod · 0.80
resizeMethod · 0.80
readMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected