RainerKuemmerle / g2o

g2o: A General Framework for Graph Optimization
3.1k stars 1.11k forks source link

Query optimizer for vertex ID? #687

Closed antithing closed 1 year ago

antithing commented 1 year ago

Hi, i am setting up a bundle adjustment problem using keyframes, 3d points and fiducial markers, and am fighting with the error:

g2o::OptimizableGraph::addVertex: FATAL, a vertex with ID has already been registered with this graph

Obviously i need to work on the logic behind assigning IDs, but i am wondering:

Is there a way to query if the vertex ID is used in the graph?

RainerKuemmerle commented 1 year ago

Calling vertices() on your optimizer gives you an unordered_map<int, Vertex*> where the key is the ID. Based on the unordered_map you can query if an ID is already contained in the graph, e.g., by the count() method, see https://en.cppreference.com/w/cpp/container/unordered_map/count

antithing commented 1 year ago

thank you! That's perfect.