MCPcopy
hub / github.com/naver/dust3r / crop_one_seq

Function crop_one_seq

datasets_preprocess/preprocess_waymo.py:177–251  ·  view source on GitHub ↗
(input_dir, output_dir, seq, resolution=512)

Source from the content-addressed store, hash-verified

175
176
177def crop_one_seq(input_dir, output_dir, seq, resolution=512):
178 seq_dir = osp.join(input_dir, seq)
179 out_dir = osp.join(output_dir, seq)
180 if osp.isfile(osp.join(out_dir, '00100_1.jpg')):
181 return
182 os.makedirs(out_dir, exist_ok=True)
183
184 # load calibration file
185 try:
186 with open(osp.join(seq_dir, 'calib.json')) as f:
187 calib = json.load(f)
188 except IOError:
189 print(f'/!\\ Error: Missing calib.json in sequence {seq} /!\\', file=sys.stderr)
190 return
191
192 axes_transformation = np.array([
193 [0, -1, 0, 0],
194 [0, 0, -1, 0],
195 [1, 0, 0, 0],
196 [0, 0, 0, 1]])
197
198 cam_K = {}
199 cam_distortion = {}
200 cam_res = {}
201 cam_to_car = {}
202 for cam_idx, cam_info in calib:
203 cam_idx = str(cam_idx)
204 cam_res[cam_idx] = (W, H) = (cam_info['width'], cam_info['height'])
205 f1, f2, cx, cy, k1, k2, p1, p2, k3 = cam_info['intrinsics']
206 cam_K[cam_idx] = np.asarray([(f1, 0, cx), (0, f2, cy), (0, 0, 1)])
207 cam_distortion[cam_idx] = np.asarray([k1, k2, p1, p2, k3])
208 cam_to_car[cam_idx] = np.asarray(cam_info['extrinsics']).reshape(4, 4) # cam-to-vehicle
209
210 frames = sorted(f[:-3] for f in os.listdir(seq_dir) if f.endswith('.jpg'))
211
212 # from dust3r.viz import SceneViz
213 # viz = SceneViz()
214
215 for frame in tqdm(frames, leave=False):
216 cam_idx = frame[-2] # cam index
217 assert cam_idx in '12345', f'bad {cam_idx=} in {frame=}'
218 data = np.load(osp.join(seq_dir, frame + 'npz'))
219 car_to_world = data['pose']
220 W, H = cam_res[cam_idx]
221
222 # load depthmap
223 pos2d = data['pixels'].round().astype(np.uint16)
224 x, y = pos2d.T
225 pts3d = data['pts3d'] # already in the car frame
226 pts3d = geotrf(axes_transformation @ inv(cam_to_car[cam_idx]), pts3d)
227 # X=LEFT_RIGHT y=ALTITUDE z=DEPTH
228
229 # load image
230 image = imread_cv2(osp.join(seq_dir, frame + 'jpg'))
231
232 # downscale image
233 output_resolution = (resolution, 1) if W > H else (1, resolution)
234 image, _, intrinsics2 = cropping.rescale_image_depthmap(image, None, cam_K[cam_idx], output_resolution)

Callers

nothing calls this directly

Calls 3

geotrfFunction · 0.90
invFunction · 0.90
imread_cv2Function · 0.90

Tested by

no test coverage detected