def get_openmvg_camera_id(kapture_camera_id, kapture_to_openmvg_cam_ids):
    """ return a valid openmvg camera id for the given kapture on.
    It keeps kapture_to_openmvg_cam_ids uptodate, and ensure there is no collision.
    """

    if kapture_camera_id in kapture_to_openmvg_cam_ids:
        # already defined
        return kapture_to_openmvg_cam_ids[kapture_camera_id]

    # its not defined, then, make up one
    last_known_openmvg_camera_id = max(list(kapture_to_openmvg_cam_ids.values()) + [-1])
    assert type(last_known_openmvg_camera_id) == int
    openmvg_camera_id = last_known_openmvg_camera_id + 1
    assert openmvg_camera_id not in kapture_to_openmvg_cam_ids
    kapture_to_openmvg_cam_ids[kapture_camera_id] = openmvg_camera_id
    return openmvg_camera_id