Computational Geometry Primitives Module#

Topics#

Detailed Description#

Coordinate geometry: 2D shape analysis and fitting, planar subdivision, multi-view 3D vision, and point-cloud sampling and segmentation.

Classes#

Name

Description

struct cv::MSTEdge

Represents an edge in a graph for Minimum Spanning Tree (MST) computation. View details

Enumerations#

Represents the algorithms available for building a Minimum Spanning Tree (MST). View details

Enumeration Type Documentation#

MSTAlgorithm#

enum cv::MSTAlgorithm

#include <opencv2/geometry/mst.hpp>

Represents the algorithms available for building a Minimum Spanning Tree (MST).

More algorithms may be added in the future.

Enumerator:

MST_PRIM
Python: cv.MST_PRIM

MST_KRUSKAL
Python: cv.MST_KRUSKAL

Function Documentation#

buildMST()#

bool cv::buildMST(
int numNodes,
const std::vector< MSTEdge > & inputEdges,
std::vector< MSTEdge > & resultingEdges,
MSTAlgorithm algorithm,
int root = 0 )

#include <opencv2/geometry/mst.hpp>

Python:

cv.buildMST(numNodes, inputEdges, algorithm[, root]) -> retval, resultingEdges

Builds a Minimum Spanning Tree (MST) using the specified algorithm (see MSTAlgorithm).

Supports graphs with negative edge weights. Self-loop edges (edges where source and target are the same) are ignored. If multiple edges exist between the same pair of nodes, only the one with the lowest weight is considered. If the graph is disconnected or input is invalid, the function returns false.

Note

The root parameter is ignored for algorithms that do not require a starting node.

Additional MST algorithms may be supported in the future via the algorithm parameter (see MSTAlgorithm).

Parameters

  • numNodes — Number of nodes in the graph (must be greater than 0).

  • inputEdges — Input vector of edges representing the graph.

  • resultingEdges — Output vector to store the edges of the resulting MST.

  • algorithm — Specifies which algorithm to use to compute the MST (see MSTAlgorithm).

  • root — Starting node for the MST algorithm (only used for certain algorithms).

Returns

true if a valid MST was successfully built; false otherwise.