colmap / pycolmap

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

Are Point3D and Image 0 indexed? #264

Closed Coelhomatias closed 1 month ago

Coelhomatias commented 4 months ago

This is not an issue and only a question. I see that the id's for most classes are initialized with a big number. Is this because it is possible to have the id be 0? I am asking this because in the current project I am working on there is no id=0 on any of the classes and was wondering if the id will never be 0 or am I just lucky?

sarlinpe commented 4 months ago

IDs are not indices, they are not ordered and are not guaranteed to be continuous. I think that image and point IDs usually start at 1 but most parts of COLMAP won't complain if they are given a value 0.

jytime commented 3 months ago

For me it works well if you count image and camera from 0, e.g.,:

fidx=0
camera = pycolmap.Camera(model="SIMPLE_PINHOLE", width=image_size[0], height=image_size[1], params=pycolmap_intri_pinhole, camera_id=fidx, )
image = pycolmap.Image(id=fidx, name=f"image_{fidx}", camera_id=camera.camera_id, cam_from_world=cam_from_world)

reconstruction.add_camera(camera)
reconstruction.add_image(image)

However, if you want to add 3D points manually, they start from 1.

for vidx in valid_idx:         
    reconstruction.add_point3D(points3d[vidx], pycolmap.Track(), np.zeros(3))
(Pdb) reconstruction.points3D[0]
*** KeyError: ''
(Pdb) reconstruction.points3D[1]
Point3D(xyz=[-2.73191, 8.97091, 32.4668], color=[0, 0, 0], error=-1, track=Track(length=2))