(reconstruction, image_dir, color_by='visibility',
selected=[], n=1, seed=0, dpi=75)
| 10 | |
| 11 | |
| 12 | def visualize_sfm_2d(reconstruction, image_dir, color_by='visibility', |
| 13 | selected=[], n=1, seed=0, dpi=75): |
| 14 | assert image_dir.exists() |
| 15 | if not isinstance(reconstruction, pycolmap.Reconstruction): |
| 16 | reconstruction = pycolmap.Reconstruction(reconstruction) |
| 17 | |
| 18 | if not selected: |
| 19 | image_ids = reconstruction.reg_image_ids() |
| 20 | selected = random.Random(seed).sample( |
| 21 | image_ids, min(n, len(image_ids))) |
| 22 | |
| 23 | for i in selected: |
| 24 | image = reconstruction.images[i] |
| 25 | keypoints = np.array([p.xy for p in image.points2D]) |
| 26 | visible = np.array([p.has_point3D() for p in image.points2D]) |
| 27 | |
| 28 | if color_by == 'visibility': |
| 29 | color = [(0, 0, 1) if v else (1, 0, 0) for v in visible] |
| 30 | text = f'visible: {np.count_nonzero(visible)}/{len(visible)}' |
| 31 | elif color_by == 'track_length': |
| 32 | tl = np.array([reconstruction.points3D[p.point3D_id].track.length() |
| 33 | if p.has_point3D() else 1 for p in image.points2D]) |
| 34 | max_, med_ = np.max(tl), np.median(tl[tl > 1]) |
| 35 | tl = np.log(tl) |
| 36 | color = cm.jet(tl / tl.max()).tolist() |
| 37 | text = f'max/median track length: {max_}/{med_}' |
| 38 | elif color_by == 'depth': |
| 39 | p3ids = [p.point3D_id for p in image.points2D if p.has_point3D()] |
| 40 | z = np.array([image.transform_to_image( |
| 41 | reconstruction.points3D[j].xyz)[-1] for j in p3ids]) |
| 42 | z -= z.min() |
| 43 | color = cm.jet(z / np.percentile(z, 99.9)) |
| 44 | text = f'visible: {np.count_nonzero(visible)}/{len(visible)}' |
| 45 | keypoints = keypoints[visible] |
| 46 | else: |
| 47 | raise NotImplementedError(f'Coloring not implemented: {color_by}.') |
| 48 | |
| 49 | name = image.name |
| 50 | plot_images([read_image(image_dir / name)], dpi=dpi) |
| 51 | plot_keypoints([keypoints], colors=[color], ps=4) |
| 52 | add_text(0, text) |
| 53 | add_text(0, name, pos=(0.01, 0.01), fs=5, lcolor=None, va='bottom') |
| 54 | |
| 55 | |
| 56 | def visualize_loc(results, image_dir, reconstruction=None, db_image_dir=None, |
nothing calls this directly
no test coverage detected