colmap / pycolmap

Python bindings for COLMAP
BSD 3-Clause "New" or "Revised" License
899 stars 129 forks source link

Use reference_internal for reconstruction data #213

Closed sarlinpe closed 9 months ago

sarlinpe commented 9 months ago

Fixes https://github.com/colmap/pycolmap/issues/212

Drawback: keeps the entire reconstruction object in memory until any Python reference to any child object image/camera/point3D is deleted.

Minimal example:

import pycolmap
import numpy as np
import gc

reconstruction = pycolmap.Reconstruction()
i = reconstruction.add_point3D(
    xyz=np.array([0, 0, 0]),
    color=np.array([0, 0, 0], dtype=np.uint8),
    track=pycolmap.Track(),
)
p = reconstruction.points3D[i]
print(p.summary())

del reconstruction
gc.collect()

# allocate most of the memory to a new object
x = np.random.rand(3000,10000,100)

assert np.all(p.color == np.zeros(3))