10000 Feat #25150: Pose Graph MST initialization by 03kiko · Pull Request #27423 · opencv/opencv · GitHub
[go: up one dir, main page]

Skip to content

Feat #25150: Pose Graph MST initialization #27423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 5.x
Choose a base branch
from

Conversation

03kiko
Copy link
Contributor
@03kiko 03kiko commented Jun 9, 2025

Implements an MST-based initialisation for pose graphs, as proposed in issue #25150. Both Prim’s and Kruskal’s algorithms were added to the 3D module. These receive a vector of node IDs and a vector of edges (each with source and target IDs and a weight), and return a vector with the resulting edges. These MST implementations treat edges as undirected internally, meaning users only need to provide one direction (A→B or B→A), and duplicates are handled automatically.

Additionally, a new pose graph initialisation method using MST (Prim) was implemented. It constructs the MST over the pose graph, then traverses it to reconstruct node poses. With this, users can call poseGraph->initializePosesWithMST() to create an initial solution for the pose graph problem.

A set of test cases validating the implementation was also included.

Notes

  • The edge weight used in the MST for pose graphs is calculated as:
    weight = || translation || + λ * rotation_angle,
    where λ = 0.485 was determined empirically based on optimiser performance;
  • Validated on Sphere-a pose graph, showing similar convergence behaviour with or without MST initialisation;
  • Alternative weight formulas, such as the Mahalanobis distance formula, were also tested, but the current formula yielded better results.

Future Work

  • Extend testing to more diverse pose graphs (currently limited to Sphere-a in opencv_extra)
  • Explore adaptive tuning of the λ parameter for broader applicability.

Co-authored-by: @miguel1099

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

03kiko and others added 2 commits June 9, 2025 22:15
Implements a MST-based initialization for pose graphs, as proposed in
issue opencv#25150. Both Prim’s and Kruskal’s algorithms were added to the 3D
module, receiving a vector of node IDs and a vector of edges (each with
source/target IDs and a weight) and returning a vector with the
resulting edges. These MST implementations treat edges as undirected
internally, meaning users only need to provide one direction (A→B or
B→A), and duplicates are handled automatically.

Additionally, a new pose graph initialization method using MST was
implemented. It constructs the MST over the pose graph, then traverses
it to reconstruct node poses.

A set of test cases validating the implementation was also included.

Co-authored-by: Miguel Agra <miguel.agra@tecnico.ulisboa.pt>
@03kiko
Copy link
Contributor Author
03kiko commented Jun 18, 2025

Hi @asmorkalov,

We noticed that no reviewers have been assigned to this PR yet. Is there a specific reason for this? Let us know if there's anything we can do to move this PR forward.

Thanks!

Comment on lines 23 to 32
CV_EXPORTS std::vector<MSTEdge> buildMSTPrim(
const size_t numNodes,
const std::vector<MSTEdge>& edges,
size_t root = 0
);

// builds a MST using Kruskal's algorithm
CV_EXPORTS std::vector<MSTEdge> buildMSTKruskal(
const size_t numNodes,
const std::vector<MSTEdge>& edges
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to use single function as public API with algorithm type parameter like it's done in many places in OpenCV. Also we have internal MST implementation at least in multi-camera calibration. It makes sense to move it to main header, not details.

// represents an edge in a graph for MST computation
struct CV_EXPORTS MSTEdge
{
size_t source, target;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size_t is not binding friendly. I propose to use just int here. Also you can use CV_EXPORTS_W_SIMPLE for the structure.

@asmorkalov asmorkalov self-assigned this Jun 20, 2025
Co-authored-by: Miguel Agra <miguel.agra@tecnico.ulisboa.pt>
@03kiko
Copy link
Contributor Author
03kiko commented Jun 22, 2025

Hi @asmorkalov, thanks for the feedback! Please let us know if everything looks good now or if there’s anything else you'd like us to adjust!

@03kiko
Copy link
Contributor Author
03kiko commented Jun 26, 2025

Hi @asmorkalov, could you trigger CI again? It seems to have failed to clone opencv_extra?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0