| 1 |
import os |
| 2 |
|
| 3 |
import pycolmap |
| 4 |
|
| 5 |
|
| 6 |
def test_reconstruction_default_init(): |
| 7 |
reconstruction = pycolmap.Reconstruction() |
| 8 |
assert reconstruction is not None |
| 9 |
|
| 10 |
|
| 11 |
def test_reconstruction_copy_init(synthetic_reconstruction): |
| 12 |
reconstruction_copy = pycolmap.Reconstruction(synthetic_reconstruction) |
| 13 |
assert ( |
| 14 |
reconstruction_copy.num_cameras() |
| 15 |
== synthetic_reconstruction.num_cameras() |
| 16 |
) |
| 17 |
|
| 18 |
|
| 19 |
def test_reconstruction_num_rigs(synthetic_reconstruction): |
| 20 |
assert isinstance(synthetic_reconstruction.num_rigs(), int) |
| 21 |
assert synthetic_reconstruction.num_rigs() > 0 |
| 22 |
|
| 23 |
|
| 24 |
def test_reconstruction_num_cameras(synthetic_reconstruction): |
| 25 |
assert isinstance(synthetic_reconstruction.num_cameras(), int) |
| 26 |
assert synthetic_reconstruction.num_cameras() > 0 |
| 27 |
|
| 28 |
|
| 29 |
def test_reconstruction_num_frames(synthetic_reconstruction): |
| 30 |
assert isinstance(synthetic_reconstruction.num_frames(), int) |
| 31 |
assert synthetic_reconstruction.num_frames() > 0 |
| 32 |
|
| 33 |
|
| 34 |
def test_reconstruction_num_images(synthetic_reconstruction): |
| 35 |
assert isinstance(synthetic_reconstruction.num_images(), int) |
| 36 |
assert synthetic_reconstruction.num_images() > 0 |
| 37 |
|
| 38 |
|
| 39 |
def test_reconstruction_num_points3d(synthetic_reconstruction): |
| 40 |
assert isinstance(synthetic_reconstruction.num_points3D(), int) |
| 41 |
assert synthetic_reconstruction.num_points3D() > 0 |
| 42 |
|
| 43 |
|
| 44 |
def test_reconstruction_num_reg_frames(synthetic_reconstruction): |
| 45 |
assert isinstance(synthetic_reconstruction.num_reg_frames(), int) |
| 46 |
|
| 47 |
|
| 48 |
def test_reconstruction_num_reg_images(synthetic_reconstruction): |
| 49 |
assert isinstance(synthetic_reconstruction.num_reg_images(), int) |
| 50 |
|
| 51 |
|
| 52 |
def test_reconstruction_cameras_property(synthetic_reconstruction): |
| 53 |
cameras = synthetic_reconstruction.cameras |
| 54 |
assert len(cameras) > 0 |
| 55 |
|
| 56 |
|
| 57 |
def test_reconstruction_frames_property(synthetic_reconstruction): |
| 58 |
frames = synthetic_reconstruction.frames |
| 59 |
assert frames is not None |
| 60 |
|
| 61 |
|
| 62 |
def test_reconstruction_images_property(synthetic_reconstruction): |
| 63 |
images = synthetic_reconstruction.images |
| 64 |
assert len(images) > 0 |
| 65 |
|
| 66 |
|
| 67 |
def test_reconstruction_points3d_property(synthetic_reconstruction): |
| 68 |
points = synthetic_reconstruction.points3D |
| 69 |
assert len(points) > 0 |
| 70 |
|
| 71 |
|
| 72 |
def test_reconstruction_camera_access(synthetic_reconstruction): |
| 73 |
camera_ids = list(synthetic_reconstruction.cameras.keys()) |
| 74 |
camera = synthetic_reconstruction.camera(camera_ids[0]) |
| 75 |
assert camera is not None |
| 76 |
|
| 77 |
|
| 78 |
def test_reconstruction_frame_access(synthetic_reconstruction): |
| 79 |
frame_ids = list(synthetic_reconstruction.frames.keys()) |
| 80 |
frame = synthetic_reconstruction.frame(frame_ids[0]) |
| 81 |
assert frame is not None |
| 82 |
|
| 83 |
|
| 84 |
def test_reconstruction_image_access(synthetic_reconstruction): |
| 85 |
image_ids = list(synthetic_reconstruction.images.keys()) |
| 86 |
image = synthetic_reconstruction.image(image_ids[0]) |
| 87 |
assert image is not None |
| 88 |
|
| 89 |
|
| 90 |
def test_reconstruction_point3d_access(synthetic_reconstruction): |
| 91 |
point_ids = list(synthetic_reconstruction.points3D.keys()) |
| 92 |
point = synthetic_reconstruction.point3D(point_ids[0]) |
| 93 |
assert point is not None |
| 94 |
|
| 95 |
|
| 96 |
def test_reconstruction_exists_camera(synthetic_reconstruction): |
| 97 |
camera_ids = list(synthetic_reconstruction.cameras.keys()) |
| 98 |
assert synthetic_reconstruction.exists_camera(camera_ids[0]) |
| 99 |
assert not synthetic_reconstruction.exists_camera(99999) |
| 100 |
|
| 101 |
|
| 102 |
def test_reconstruction_exists_frame(synthetic_reconstruction): |
| 103 |
frame_ids = list(synthetic_reconstruction.frames.keys()) |
| 104 |
assert synthetic_reconstruction.exists_frame(frame_ids[0]) |
| 105 |
|
| 106 |
|
| 107 |
def test_reconstruction_exists_image(synthetic_reconstruction): |
| 108 |
image_ids = list(synthetic_reconstruction.images.keys()) |
| 109 |
assert synthetic_reconstruction.exists_image(image_ids[0]) |
| 110 |
assert not synthetic_reconstruction.exists_image(99999) |
| 111 |
|
| 112 |
|
| 113 |
def test_reconstruction_exists_point3d(synthetic_reconstruction): |
| 114 |
point_ids = list(synthetic_reconstruction.points3D.keys()) |
| 115 |
assert synthetic_reconstruction.exists_point3D(point_ids[0]) |
| 116 |
assert not synthetic_reconstruction.exists_point3D(99999) |
| 117 |
|
| 118 |
|
| 119 |
def test_reconstruction_reg_image_ids(synthetic_reconstruction): |
| 120 |
reg_ids = synthetic_reconstruction.reg_image_ids() |
| 121 |
assert isinstance(reg_ids, list) |
| 122 |
|
| 123 |
|
| 124 |
def test_reconstruction_reg_frame_ids(synthetic_reconstruction): |
| 125 |
reg_ids = synthetic_reconstruction.reg_frame_ids() |
| 126 |
assert isinstance(reg_ids, list) |
| 127 |
|
| 128 |
|
| 129 |
def test_reconstruction_point3d_ids(synthetic_reconstruction): |
| 130 |
point_ids = synthetic_reconstruction.point3D_ids() |
| 131 |
assert len(point_ids) > 0 |
| 132 |
|
| 133 |
|
| 134 |
def test_reconstruction_is_valid(synthetic_reconstruction): |
| 135 |
result = synthetic_reconstruction.is_valid() |
| 136 |
assert isinstance(result, bool) |
| 137 |
|
| 138 |
|
| 139 |
def test_reconstruction_compute_num_observations(synthetic_reconstruction): |
| 140 |
count = synthetic_reconstruction.compute_num_observations() |
| 141 |
assert isinstance(count, int) |
| 142 |
|
| 143 |
|
| 144 |
def test_reconstruction_compute_mean_track_length(synthetic_reconstruction): |
| 145 |
length = synthetic_reconstruction.compute_mean_track_length() |
| 146 |
assert isinstance(length, float) |
| 147 |
|
| 148 |
|
| 149 |
def test_reconstruction_compute_mean_reprojection_error( |
| 150 |
synthetic_reconstruction, |
| 151 |
): |
| 152 |
reconstruction_copy = pycolmap.Reconstruction(synthetic_reconstruction) |
| 153 |
error = reconstruction_copy.compute_mean_reprojection_error() |
| 154 |
assert isinstance(error, float) |
| 155 |
|
| 156 |
|
| 157 |
def test_reconstruction_compute_mean_observations_per_reg_image( |
| 158 |
synthetic_reconstruction, |
| 159 |
): |
| 160 |
mean_obs = ( |
| 161 |
synthetic_reconstruction.compute_mean_observations_per_reg_image() |
| 162 |
) |
| 163 |
assert isinstance(mean_obs, float) |
| 164 |
|
| 165 |
|
| 166 |
def test_reconstruction_summary(synthetic_reconstruction): |
| 167 |
summary = synthetic_reconstruction.summary() |
| 168 |
assert isinstance(summary, str) |
| 169 |
assert "Reconstruction" in summary |
| 170 |
|
| 171 |
|
| 172 |
def test_reconstruction_compute_bounding_box(synthetic_reconstruction): |
| 173 |
bbox = synthetic_reconstruction.compute_bounding_box() |
| 174 |
assert bbox is not None |
| 175 |
|
| 176 |
|
| 177 |
def test_reconstruction_compute_centroid(synthetic_reconstruction): |
| 178 |
centroid = synthetic_reconstruction.compute_centroid() |
| 179 |
assert centroid.shape == (3,) |
| 180 |
|
| 181 |
|
| 182 |
def test_reconstruction_normalize(synthetic_reconstruction): |
| 183 |
reconstruction_copy = pycolmap.Reconstruction(synthetic_reconstruction) |
| 184 |
reconstruction_copy.normalize() |
| 185 |
assert reconstruction_copy.num_points3D() > 0 |
| 186 |
|
| 187 |
|
| 188 |
def test_reconstruction_transform(synthetic_reconstruction): |
| 189 |
reconstruction_copy = pycolmap.Reconstruction(synthetic_reconstruction) |
| 190 |
transform = pycolmap.Sim3d() |
| 191 |
reconstruction_copy.transform(transform) |
| 192 |
assert reconstruction_copy.num_points3D() > 0 |
| 193 |
|
| 194 |
|
| 195 |
def test_reconstruction_write_read_binary_roundtrip( |
| 196 |
synthetic_reconstruction, tmp_path |
| 197 |
): |
| 198 |
output_dir = str(tmp_path / "binary") |
| 199 |
|
| 200 |
os.makedirs(output_dir) |
| 201 |
synthetic_reconstruction.write_binary(output_dir) |
| 202 |
loaded = pycolmap.Reconstruction() |
| 203 |
loaded.read_binary(output_dir) |
| 204 |
assert loaded.num_cameras() == synthetic_reconstruction.num_cameras() |
| 205 |
assert loaded.num_images() == synthetic_reconstruction.num_images() |
| 206 |
|
| 207 |
|
| 208 |
def test_reconstruction_write_read_text_roundtrip( |
| 209 |
synthetic_reconstruction, tmp_path |
| 210 |
): |
| 211 |
output_dir = str(tmp_path / "text") |
| 212 |
|
| 213 |
os.makedirs(output_dir) |
| 214 |
synthetic_reconstruction.write_text(output_dir) |
| 215 |
loaded = pycolmap.Reconstruction() |
| 216 |
loaded.read_text(output_dir) |
| 217 |
assert loaded.num_cameras() == synthetic_reconstruction.num_cameras() |
| 218 |
assert loaded.num_images() == synthetic_reconstruction.num_images() |
| 219 |
|
| 220 |
|
| 221 |
def test_reconstruction_add_camera(): |
| 222 |
reconstruction = pycolmap.Reconstruction() |
| 223 |
camera = pycolmap.Camera.create_from_model_id( |
| 224 |
1, pycolmap.CameraModelId.PINHOLE, 500.0, 1024, 768 |
| 225 |
) |
| 226 |
reconstruction.add_camera(camera) |
| 227 |
assert reconstruction.exists_camera(1) |
| 228 |
|
| 229 |
|
| 230 |
def test_reconstruction_find_image_with_name(synthetic_reconstruction): |
| 231 |
image_ids = list(synthetic_reconstruction.images.keys()) |
| 232 |
first_image = synthetic_reconstruction.image(image_ids[0]) |
| 233 |
found = synthetic_reconstruction.find_image_with_name(first_image.name) |
| 234 |
assert found is not None |
| 235 |
|
| 236 |
|
| 237 |
def test_reconstruction_find_common_reg_image_ids(synthetic_reconstruction): |
| 238 |
reconstruction_copy = pycolmap.Reconstruction(synthetic_reconstruction) |
| 239 |
common_ids = synthetic_reconstruction.find_common_reg_image_ids( |
| 240 |
reconstruction_copy |
| 241 |
) |
| 242 |
assert isinstance(common_ids, list) |
| 243 |
|
| 244 |
|
| 245 |
def test_reconstruction_export_import_ply_roundtrip( |
| 246 |
synthetic_reconstruction, tmp_path |
| 247 |
): |
| 248 |
ply_path = str(tmp_path / "points.ply") |
| 249 |
synthetic_reconstruction.export_PLY(ply_path) |
| 250 |
new_reconstruction = pycolmap.Reconstruction() |
| 251 |
new_reconstruction.import_PLY(ply_path) |
| 252 |
assert new_reconstruction.num_points3D() > 0 |
| 253 |
|
| 254 |
|
| 255 |
def test_reconstruction_crop(synthetic_reconstruction): |
| 256 |
reconstruction_copy = pycolmap.Reconstruction(synthetic_reconstruction) |
| 257 |
bbox = reconstruction_copy.compute_bounding_box() |
| 258 |
reconstruction_copy.crop(bbox) |
| 259 |
assert reconstruction_copy is not None |
| 260 |
|
| 261 |
|
| 262 |
def test_reconstruction_delete_all_points2d_and_points3d( |
| 263 |
synthetic_reconstruction, |
| 264 |
): |
| 265 |
reconstruction_copy = pycolmap.Reconstruction(synthetic_reconstruction) |
| 266 |
reconstruction_copy.delete_all_points2D_and_points3D() |
| 267 |
assert reconstruction_copy.num_points3D() == 0 |