OpenCV 5.0.0
Open Source Computer Vision
Loading...
Searching...
No Matches
Geometry_shape

Topics

 Geometry_subdiv2d

Detailed Description

Classes

struct  cv::Subdiv2D::QuadEdge
struct  cv::Subdiv2D::Vertex

Enumerations

enum  {
  cv::Subdiv2D::PTLOC_ERROR = -2 ,
  cv::Subdiv2D::PTLOC_OUTSIDE_RECT = -1 ,
  cv::Subdiv2D::PTLOC_INSIDE = 0 ,
  cv::Subdiv2D::PTLOC_VERTEX = 1 ,
  cv::Subdiv2D::PTLOC_ON_EDGE = 2
}
enum  {
  cv::Subdiv2D::NEXT_AROUND_ORG = 0x00 ,
  cv::Subdiv2D::NEXT_AROUND_DST = 0x22 ,
  cv::Subdiv2D::PREV_AROUND_ORG = 0x11 ,
  cv::Subdiv2D::PREV_AROUND_DST = 0x33 ,
  cv::Subdiv2D::NEXT_AROUND_LEFT = 0x13 ,
  cv::Subdiv2D::NEXT_AROUND_RIGHT = 0x31 ,
  cv::Subdiv2D::PREV_AROUND_LEFT = 0x20 ,
  cv::Subdiv2D::PREV_AROUND_RIGHT = 0x02
}
enum  cv::DistanceTypes {
  cv::DIST_USER = -1 ,
  cv::DIST_L1 = 1 ,
  cv::DIST_L2 = 2 ,
  cv::DIST_C = 3 ,
  cv::DIST_L12 = 4 ,
  cv::DIST_FAIR = 5 ,
  cv::DIST_WELSCH = 6 ,
  cv::DIST_HUBER = 7
}
enum  cv::RectanglesIntersectTypes {
  cv::INTERSECT_NONE = 0 ,
  cv::INTERSECT_PARTIAL = 1 ,
  cv::INTERSECT_FULL = 2
}
 types of intersection between rectangles More...

Functions

 cv::Subdiv2D::QuadEdge::QuadEdge ()
 cv::Subdiv2D::QuadEdge::QuadEdge (int edgeidx)
 cv::Subdiv2D::Subdiv2D ()
 cv::Subdiv2D::Subdiv2D (Rect rect)
 cv::Subdiv2D::Subdiv2D (Rect2f rect2f)
 cv::Subdiv2D::Vertex::Vertex ()
 cv::Subdiv2D::Vertex::Vertex (Point2f pt, bool isvirtual, int firstEdge=0)
void cv::approxPolyDP (InputArray curve, OutputArray approxCurve, double epsilon, bool closed)
 Approximates a polygonal curve(s) with the specified precision.
void cv::approxPolyN (InputArray curve, OutputArray approxCurve, int nsides, float epsilon_percentage=-1.0, bool ensure_convex=true)
 Approximates a polygon with a convex hull with a specified accuracy and number of sides.
double cv::arcLength (InputArray curve, bool closed)
 Calculates a contour perimeter or a curve length.
Rect cv::boundingRect (InputArray array)
 Calculates the up-right bounding rectangle of a point set or non-zero pixels of gray-scale image.
void cv::boxPoints (RotatedRect box, OutputArray points)
 Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle.
void cv::Subdiv2D::calcVoronoi ()
void cv::Subdiv2D::checkSubdiv () const
void cv::Subdiv2D::clearVoronoi ()
int cv::Subdiv2D::connectEdges (int edgeA, int edgeB)
double cv::contourArea (InputArray contour, bool oriented=false)
 Calculates a contour area.
void cv::convexHull (InputArray points, OutputArray hull, bool clockwise=false, bool returnPoints=true)
 Finds the convex hull of a point set.
void cv::convexityDefects (InputArray contour, InputArray convexhull, OutputArray convexityDefects)
 Finds the convexity defects of a contour.
void cv::Subdiv2D::deleteEdge (int edge)
void cv::Subdiv2D::deletePoint (int vtx)
int cv::Subdiv2D::edgeDst (int edge, Point2f *dstpt=0) const
 Returns the edge destination.
int cv::Subdiv2D::edgeOrg (int edge, Point2f *orgpt=0) const
 Returns the edge origin.
int cv::Subdiv2D::findNearest (Point2f pt, Point2f *nearestPt=0)
 Finds the subdivision vertex closest to the given point.
RotatedRect cv::fitEllipse (InputArray points)
 Fits an ellipse around a set of 2D points.
RotatedRect cv::fitEllipseAMS (InputArray points)
 Fits an ellipse around a set of 2D points.
RotatedRect cv::fitEllipseDirect (InputArray points)
 Fits an ellipse around a set of 2D points.
void cv::fitLine (InputArray points, OutputArray line, int distType, double param, double reps, double aeps)
 Fits a line to a 2D or 3D point set.
Mat cv::getAffineTransform (const Point2f src[], const Point2f dst[])
 Calculates an affine transform from three pairs of the corresponding points.
Mat cv::getAffineTransform (InputArray src, InputArray dst)
void cv::getClosestEllipsePoints (const RotatedRect &ellipse_params, InputArray points, OutputArray closest_pts)
 Compute for each 2d point the nearest 2d point located on a given ellipse.
int cv::Subdiv2D::getEdge (int edge, int nextEdgeType) const
 Returns one of the edges related to the given edge.
void cv::Subdiv2D::getEdgeList (std::vector< Vec4f > &edgeList) const
 Returns a list of all edges.
void cv::Subdiv2D::getLeadingEdgeList (std::vector< int > &leadingEdgeList) const
 Returns a list of the leading edge ID connected to each triangle.
Mat cv::getPerspectiveTransform (const Point2f src[], const Point2f dst[], int solveMethod=DECOMP_LU)
Mat cv::getPerspectiveTransform (InputArray src, InputArray dst, int solveMethod=DECOMP_LU)
 Calculates a perspective transform from four pairs of the corresponding points.
Mat cv::getRotationMatrix2D (Point2f center, double angle, double scale)
 Calculates an affine matrix of 2D rotation.
Matx23d cv::getRotationMatrix2D_ (Point2f center, double angle, double scale)
void cv::Subdiv2D::getTriangleList (std::vector< Vec6f > &triangleList) const
 Returns a list of all triangles.
Point2f cv::Subdiv2D::getVertex (int vertex, int *firstEdge=0) const
 Returns vertex location from vertex ID.
void cv::Subdiv2D::getVoronoiFacetList (const std::vector< int > &idx, std::vector< std::vector< Point2f > > &facetList, std::vector< Point2f > &facetCenters)
 Returns a list of all Voronoi facets.
void cv::HuMoments (const Moments &m, OutputArray hu)
void cv::HuMoments (const Moments &moments, double hu[7])
 Calculates seven Hu invariants.
void cv::Subdiv2D::initDelaunay (Rect rect)
 Creates a new empty Delaunay subdivision.
void cv::Subdiv2D::initDelaunay (Rect2f rect)
 Creates a new empty Delaunay subdivision.
void cv::Subdiv2D::insert (const std::vector< Point2f > &ptvec)
 Insert multiple points into a Delaunay triangulation.
int cv::Subdiv2D::insert (Point2f pt)
 Insert a single point into a Delaunay triangulation.
float cv::intersectConvexConvex (InputArray p1, InputArray p2, OutputArray p12, bool handleNested=true)
 Finds intersection of two convex polygons.
void cv::invertAffineTransform (InputArray M, OutputArray iM)
 Inverts an affine transformation.
bool cv::isContourConvex (InputArray contour)
 Tests a contour convexity.
bool cv::Subdiv2D::QuadEdge::isfree () const
bool cv::Subdiv2D::Vertex::isfree () const
int cv::Subdiv2D::isRightOf (Point2f pt, int edge) const
bool cv::Subdiv2D::Vertex::isvirtual () const
int cv::Subdiv2D::locate (Point2f pt, int &edge, int &vertex)
 Returns the location of a point within a Delaunay triangulation.
double cv::matchShapes (InputArray contour1, InputArray contour2, int method, double parameter)
 Compares two shapes.
RotatedRect cv::minAreaRect (InputArray points)
 Finds a rotated rectangle of the minimum area enclosing the input 2D point set.
void cv::minEnclosingCircle (InputArray points, Point2f &center, float &radius)
 Finds a circle of the minimum area enclosing a 2D point set.
double cv::minEnclosingConvexPolygon (InputArray points, OutputArray polygon, int k)
 Finds a convex polygon of minimum area enclosing a 2D point set and returns its area.
double cv::minEnclosingTriangle (InputArray points, OutputArray triangle)
 Finds a triangle of minimum area enclosing a 2D point set and returns its area.
Moments cv::moments (InputArray array, bool binaryImage=false)
 Calculates all of the moments up to the third order of a polygon or rasterized shape.
int cv::Subdiv2D::newEdge ()
int cv::Subdiv2D::newPoint (Point2f pt, bool isvirtual, int firstEdge=0)
int cv::Subdiv2D::nextEdge (int edge) const
 Returns next edge around the edge origin.
double cv::pointPolygonTest (InputArray contour, Point2f pt, bool measureDist)
 Performs a point-in-contour test.
int cv::rotatedRectangleIntersection (const RotatedRect &rect1, const RotatedRect &rect2, OutputArray intersectingRegion)
 Finds out if there is any intersection between two rotated rectangles.
int cv::Subdiv2D::rotateEdge (int edge, int rotate) const
 Returns another edge of the same quad-edge.
void cv::Subdiv2D::setEdgePoints (int edge, int orgPt, int dstPt)
void cv::Subdiv2D::splice (int edgeA, int edgeB)
void cv::Subdiv2D::swapEdges (int edge)
int cv::Subdiv2D::symEdge (int edge) const

Variables

Point2f cv::Subdiv2D::bottomRight
 Bottom right corner of the bounding rect.
int cv::Subdiv2D::Vertex::firstEdge
int cv::Subdiv2D::freePoint
int cv::Subdiv2D::freeQEdge
int cv::Subdiv2D::QuadEdge::next [4]
int cv::Subdiv2D::QuadEdge::pt [4]
Point2f cv::Subdiv2D::Vertex::pt
std::vector< QuadEdgecv::Subdiv2D::qedges
 All of the edges.
int cv::Subdiv2D::recentEdge
Point2f cv::Subdiv2D::topLeft
 Top left corner of the bounding rect.
int cv::Subdiv2D::Vertex::type
bool cv::Subdiv2D::validGeometry
std::vector< Vertexcv::Subdiv2D::vtx
 All of the vertices.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Subdiv2D point location cases

Enumerator
PTLOC_ERROR 

Point location error.

PTLOC_OUTSIDE_RECT 

Point outside the subdivision bounding rect.

PTLOC_INSIDE 

Point inside some facet.

PTLOC_VERTEX 

Point coincides with one of the subdivision vertices.

PTLOC_ON_EDGE 

Point on some edge.

◆ anonymous enum

anonymous enum

Subdiv2D edge type navigation (see: getEdge())

Enumerator
NEXT_AROUND_ORG 
NEXT_AROUND_DST 
PREV_AROUND_ORG 
PREV_AROUND_DST 
NEXT_AROUND_LEFT 
NEXT_AROUND_RIGHT 
PREV_AROUND_LEFT 
PREV_AROUND_RIGHT 

◆ DistanceTypes

#include <opencv2/geometry/2d.hpp>

Distance types for Distance Transform and M-estimators

See also
distanceTransform, fitLine
Enumerator
DIST_USER 
Python: cv.DIST_USER

User defined distance.

DIST_L1 
Python: cv.DIST_L1

distance = |x1-x2| + |y1-y2|

DIST_L2 
Python: cv.DIST_L2

the simple euclidean distance

DIST_C 
Python: cv.DIST_C

distance = max(|x1-x2|,|y1-y2|)

DIST_L12 
Python: cv.DIST_L12

L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)).

DIST_FAIR 
Python: cv.DIST_FAIR

distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998

DIST_WELSCH 
Python: cv.DIST_WELSCH

distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846

DIST_HUBER 
Python: cv.DIST_HUBER

distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345

◆ RectanglesIntersectTypes

#include <opencv2/geometry/2d.hpp>

types of intersection between rectangles

Enumerator
INTERSECT_NONE 
Python: cv.INTERSECT_NONE

No intersection.

INTERSECT_PARTIAL 
Python: cv.INTERSECT_PARTIAL

There is a partial intersection.

INTERSECT_FULL 
Python: cv.INTERSECT_FULL

One of the rectangle is fully enclosed in the other.

Function Documentation

◆ QuadEdge() [1/2]

cv::Subdiv2D::QuadEdge::QuadEdge ( )

◆ QuadEdge() [2/2]

cv::Subdiv2D::QuadEdge::QuadEdge ( int edgeidx)

◆ Subdiv2D() [1/3]

cv::Subdiv2D::Subdiv2D ( )
Python:
cv.Subdiv2D() -> <Subdiv2D object>
cv.Subdiv2D(rect) -> <Subdiv2D object>
cv.Subdiv2D(rect2f) -> <Subdiv2D object>

#include <opencv2/geometry/2d.hpp>

creates an empty Subdiv2D object. To create a new empty Delaunay subdivision you need to use the initDelaunay function.

◆ Subdiv2D() [2/3]

cv::Subdiv2D::Subdiv2D ( Rect rect)
Python:
cv.Subdiv2D() -> <Subdiv2D object>
cv.Subdiv2D(rect) -> <Subdiv2D object>
cv.Subdiv2D(rect2f) -> <Subdiv2D object>

#include <opencv2/geometry/2d.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
rectRectangle that includes all of the 2D points that are to be added to the subdivision.

The function creates an empty Delaunay subdivision where 2D points can be added using the function insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime error is raised.

◆ Subdiv2D() [3/3]

cv::Subdiv2D::Subdiv2D ( Rect2f rect2f)
Python:
cv.Subdiv2D() -> <Subdiv2D object>
cv.Subdiv2D(rect) -> <Subdiv2D object>
cv.Subdiv2D(rect2f) -> <Subdiv2D object>

#include <opencv2/geometry/2d.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ Vertex() [1/2]

cv::Subdiv2D::Vertex::Vertex ( )

◆ Vertex() [2/2]

cv::Subdiv2D::Vertex::Vertex ( Point2f pt,
bool isvirtual,
int firstEdge = 0 )

◆ approxPolyDP()

void cv::approxPolyDP ( InputArray curve,
OutputArray approxCurve,
double epsilon,
bool closed )
Python:
cv.approxPolyDP(curve, epsilon, closed[, approxCurve]) -> approxCurve

#include <opencv2/geometry/2d.hpp>

Approximates a polygonal curve(s) with the specified precision.

T he function cv::approxPolyDP approximates a curve or a p*olygon with another curve/polygon with less vertices so that the distance between them is less or equal to the specified precision. It uses the Douglas-Peucker algorithm https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm

Parameters
curveInput vector of a 2D point stored in std::vector or Mat
approxCurveResult of the approximation. The type should match the type of the input curve.
epsilonParameter specifying the approximation accuracy. This is the maximum distance between the original curve and its approximation.
closedIf true, the approximated curve is closed (its first and last vertices are connected). Otherwise, it is not closed.

◆ approxPolyN()

void cv::approxPolyN ( InputArray curve,
OutputArray approxCurve,
int nsides,
float epsilon_percentage = -1.0,
bool ensure_convex = true )
Python:
cv.approxPolyN(curve, nsides[, approxCurve[, epsilon_percentage[, ensure_convex]]]) -> approxCurve

#include <opencv2/geometry/2d.hpp>

Approximates a polygon with a convex hull with a specified accuracy and number of sides.

T he cv::approxPolyN function approximates a polygon with *a convex hull so that the difference between the contour area of the original contour and the new polygon is minimal. It uses a greedy algorithm for contracting two vertices into one in such a way that the additional area is minimal. Straight lines formed by each edge of the convex contour are drawn and the areas of the resulting triangles are considered. Each vertex will lie either on the original contour or outside it.

The algorithm based on the paper [LowIlie2003] .

Parameters
curveInput vector of a 2D points stored in std::vector or Mat, points must be float or integer.
approxCurveResult of the approximation. The type is vector of a 2D point (Point2f or Point) in std::vector or Mat.
nsidesThe parameter defines the number of sides of the result polygon.
epsilon_percentagedefines the percentage of the maximum of additional area. If it equals -1, it is not used. Otherwise algorithm stops if additional area is greater than contourArea(_curve) * percentage. If additional area exceeds the limit, algorithm returns as many vertices as there were at the moment the limit was exceeded.
ensure_convexIf it is true, algorithm creates a convex hull of input contour. Otherwise input vector should be convex.

◆ arcLength()

double cv::arcLength ( InputArray curve,
bool closed )
Python:
cv.arcLength(curve, closed) -> retval

#include <opencv2/geometry/2d.hpp>

Calculates a contour perimeter or a curve length.

The function computes a curve length or a closed contour perimeter.

Parameters
curveInput vector of 2D points, stored in std::vector or Mat.
closedFlag indicating whether the curve is closed or not.

◆ boundingRect()

Rect cv::boundingRect ( InputArray array)
Python:
cv.boundingRect(array) -> retval

#include <opencv2/geometry/2d.hpp>

Calculates the up-right bounding rectangle of a point set or non-zero pixels of gray-scale image.

The function calculates and returns the minimal up-right bounding rectangle for the specified point set or non-zero pixels of gray-scale image.

Parameters
arrayInput gray-scale image or 2D point set, stored in std::vector or Mat.

◆ boxPoints()

void cv::boxPoints ( RotatedRect box,
OutputArray points )
Python:
cv.boxPoints(box[, points]) -> points

#include <opencv2/geometry/2d.hpp>

Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle.

The function finds the four vertices of a rotated rectangle. The four vertices are returned in clockwise order starting from the point with greatest \(y\). If two points have the same \(y\) coordinate the rightmost is the starting point. This function is useful to draw the rectangle. In C++, instead of using this function, you can directly use RotatedRect::points method. Please visit the tutorial on Creating Bounding rotated boxes and ellipsesfor contours for more information.

Parameters
boxThe input rotated rectangle. It may be the output of minAreaRect.
pointsThe output array of four vertices of rectangles.

◆ calcVoronoi()

void cv::Subdiv2D::calcVoronoi ( )
protected

◆ checkSubdiv()

void cv::Subdiv2D::checkSubdiv ( ) const
protected

◆ clearVoronoi()

void cv::Subdiv2D::clearVoronoi ( )
protected

◆ connectEdges()

int cv::Subdiv2D::connectEdges ( int edgeA,
int edgeB )
protected

◆ contourArea()

double cv::contourArea ( InputArray contour,
bool oriented = false )
Python:
cv.contourArea(contour[, oriented]) -> retval

#include <opencv2/geometry/2d.hpp>

Calculates a contour area.

The function computes a contour area. Similarly to moments , the area is computed using the Green formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using drawContours or fillPoly , can be different. Also, the function will most certainly give a wrong results for contours with self-intersections.

Example:

vector<Point> contour;
contour.push_back(Point2f(0, 0));
contour.push_back(Point2f(10, 0));
contour.push_back(Point2f(10, 10));
contour.push_back(Point2f(5, 4));
double area0 = contourArea(contour);
vector<Point> approx;
approxPolyDP(contour, approx, 5, true);
double area1 = contourArea(approx);
cout << "area0 =" << area0 << endl <<
"area1 =" << area1 << endl <<
"approx poly vertices" << approx.size() << endl;
Point_< float > Point2f
Definition types.hpp:207
void approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool closed)
Approximates a polygonal curve(s) with the specified precision.
double contourArea(InputArray contour, bool oriented=false)
Calculates a contour area.
Parameters
contourInput vector of 2D points (contour vertices), stored in std::vector or Mat.
orientedOriented area flag. If it is true, the function returns a signed area value, depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can determine orientation of a contour by taking the sign of an area. By default, the parameter is false, which means that the absolute value is returned.
Examples
samples/cpp/snippets/segment_objects.cpp, and samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp.

◆ convexHull()

void cv::convexHull ( InputArray points,
OutputArray hull,
bool clockwise = false,
bool returnPoints = true )
Python:
cv.convexHull(points[, hull[, clockwise[, returnPoints]]]) -> hull

#include <opencv2/geometry/2d.hpp>

Finds the convex hull of a point set.

The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky's algorithm [Sklansky82] that has O(N logN) complexity in the current implementation.

Parameters
pointsInput 2D point set, stored in std::vector or Mat.
hullOutput convex hull. It is either an integer vector of indices or vector of points. In the first case, the hull elements are 0-based indices of the convex hull points in the original array (since the set of convex hull points is a subset of the original point set). In the second case, hull elements are the convex hull points themselves.
clockwiseOrientation flag. If it is true, the output convex hull is oriented clockwise. Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing to the right, and its Y axis pointing upwards.
returnPointsOperation flag. In case of a matrix, when the flag is true, the function returns convex hull points. Otherwise, it returns indices of the convex hull points. When the output array is std::vector, the flag is ignored, and the output depends on the type of the vector: std::vector<int> implies returnPoints=false, std::vector<Point> implies returnPoints=true.
Note
points and hull should be different arrays, inplace processing isn't supported.

Check the corresponding tutorial for more details.

useful links:

https://www.learnopencv.com/convex-hull-using-opencv-in-python-and-c/

Examples
samples/cpp/geometry.cpp.

◆ convexityDefects()

void cv::convexityDefects ( InputArray contour,
InputArray convexhull,
OutputArray convexityDefects )
Python:
cv.convexityDefects(contour, convexhull[, convexityDefects]) -> convexityDefects

#include <opencv2/geometry/2d.hpp>

Finds the convexity defects of a contour.

The figure below displays convexity defects of a hand contour:

image
Parameters
contourInput contour.
convexhullConvex hull obtained using convexHull that should contain indices of the contour points that make the hull.
convexityDefectsThe output vector of convexity defects. In C++ and the new Python/Java interface each convexity defect is represented as 4-element integer vector (a.k.a. Vec4i): (start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices in the original contour of the convexity defect beginning, end and the farthest point, and fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the farthest contour point and the hull. That is, to get the floating-point value of the depth will be fixpt_depth/256.0.

◆ deleteEdge()

void cv::Subdiv2D::deleteEdge ( int edge)
protected

◆ deletePoint()

void cv::Subdiv2D::deletePoint ( int vtx)
protected

◆ edgeDst()

int cv::Subdiv2D::edgeDst ( int edge,
Point2f * dstpt = 0 ) const
Python:
cv.Subdiv2D.edgeDst(edge) -> retval, dstpt

#include <opencv2/geometry/2d.hpp>

Returns the edge destination.

Parameters
edgeSubdivision edge ID.
dstptOutput vertex location.
Returns
vertex ID.

◆ edgeOrg()

int cv::Subdiv2D::edgeOrg ( int edge,
Point2f * orgpt = 0 ) const
Python:
cv.Subdiv2D.edgeOrg(edge) -> retval, orgpt

#include <opencv2/geometry/2d.hpp>

Returns the edge origin.

Parameters
edgeSubdivision edge ID.
orgptOutput vertex location.
Returns
vertex ID.

◆ findNearest()

int cv::Subdiv2D::findNearest ( Point2f pt,
Point2f * nearestPt = 0 )
Python:
cv.Subdiv2D.findNearest(pt) -> retval, nearestPt

#include <opencv2/geometry/2d.hpp>

Finds the subdivision vertex closest to the given point.

Parameters
ptInput point.
nearestPtOutput subdivision vertex point.

The function is another function that locates the input point within the subdivision. It finds the subdivision vertex that is the closest to the input point. It is not necessarily one of vertices of the facet containing the input point, though the facet (located using locate() ) is used as a starting point.

Returns
vertex ID.

◆ fitEllipse()

RotatedRect cv::fitEllipse ( InputArray points)
Python:
cv.fitEllipse(points) -> retval

#include <opencv2/geometry/2d.hpp>

Fits an ellipse around a set of 2D points.

The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of all. It returns the rotated rectangle in which the ellipse is inscribed. The first algorithm described by [Fitzgibbon95] is used. Developer should keep in mind that it is possible that the returned ellipse/rotatedRect data contains negative indices, due to the data points being close to the border of the containing Mat element.

Parameters
pointsInput 2D point set, stored in std::vector<> or Mat
Note
Input point types are Point2i or Point2f and at least 5 points are required.
getClosestEllipsePoints function can be used to compute the ellipse fitting error.
Examples
samples/cpp/geometry.cpp.

◆ fitEllipseAMS()

RotatedRect cv::fitEllipseAMS ( InputArray points)
Python:
cv.fitEllipseAMS(points) -> retval

#include <opencv2/geometry/2d.hpp>

Fits an ellipse around a set of 2D points.

The function calculates the ellipse that fits a set of 2D points. It returns the rotated rectangle in which the ellipse is inscribed. The Approximate Mean Square (AMS) proposed by [Taubin1991] is used.

For an ellipse, this basis set is \( \chi= \left(x^2, x y, y^2, x, y, 1\right) \), which is a set of six free coefficients \( A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \). However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \( (a,b) \), the position \( (x_0,y_0) \), and the orientation \( \theta \). This is because the basis set includes lines, quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. If the fit is found to be a parabolic or hyperbolic function then the standard fitEllipse method is used. The AMS method restricts the fit to parabolic, hyperbolic and elliptical curves by imposing the condition that \( A^T ( D_x^T D_x + D_y^T D_y) A = 1 \) where the matrices \( Dx \) and \( Dy \) are the partial derivatives of the design matrix \( D \) with respect to x and y. The matrices are formed row by row applying the following to each of the points in the set:

\begin{align*}D(i,:)&=\left\{x_i^2, x_i y_i, y_i^2, x_i, y_i, 1\right\} & D_x(i,:)&=\left\{2 x_i,y_i,0,1,0,0\right\} & D_y(i,:)&=\left\{0,x_i,2 y_i,0,1,0\right\} \end{align*}

The AMS method minimizes the cost function

\begin{equation*}\epsilon ^2=\frac{ A^T D^T D A }{ A^T (D_x^T D_x + D_y^T D_y) A^T } \end{equation*}

The minimum cost is found by solving the generalized eigenvalue problem.

\begin{equation*}D^T D A = \lambda \left( D_x^T D_x + D_y^T D_y\right) A \end{equation*}

Parameters
pointsInput 2D point set, stored in std::vector<> or Mat
Note
Input point types are Point2i or Point2f and at least 5 points are required.
getClosestEllipsePoints function can be used to compute the ellipse fitting error.
Examples
samples/cpp/geometry.cpp.

◆ fitEllipseDirect()

RotatedRect cv::fitEllipseDirect ( InputArray points)
Python:
cv.fitEllipseDirect(points) -> retval

#include <opencv2/geometry/2d.hpp>

Fits an ellipse around a set of 2D points.

The function calculates the ellipse that fits a set of 2D points. It returns the rotated rectangle in which the ellipse is inscribed. The Direct least square (Direct) method by [oy1998NumericallySD] is used.

For an ellipse, this basis set is \( \chi= \left(x^2, x y, y^2, x, y, 1\right) \), which is a set of six free coefficients \( A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \). However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \( (a,b) \), the position \( (x_0,y_0) \), and the orientation \( \theta \). This is because the basis set includes lines, quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. The Direct method confines the fit to ellipses by ensuring that \( 4 A_{xx} A_{yy}- A_{xy}^2 > 0 \). The condition imposed is that \( 4 A_{xx} A_{yy}- A_{xy}^2=1 \) which satisfies the inequality and as the coefficients can be arbitrarily scaled is not overly restrictive.

\begin{equation*}\epsilon ^2= A^T D^T D A \quad \text{with} \quad A^T C A =1 \quad \text{and} \quad C=\left(\begin{matrix} 0 & 0 & 2 & 0 & 0 & 0 \\ 0 & -1 & 0 & 0 & 0 & 0 \\ 2 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 \end{matrix} \right) \end{equation*}

The minimum cost is found by solving the generalized eigenvalue problem.

\begin{equation*}D^T D A = \lambda \left( C\right) A \end{equation*}

The system produces only one positive eigenvalue \( \lambda\) which is chosen as the solution with its eigenvector \(\mathbf{u}\). These are used to find the coefficients

\begin{equation*}A = \sqrt{\frac{1}{\mathbf{u}^T C \mathbf{u}}} \mathbf{u} \end{equation*}

The scaling factor guarantees that \(A^T C A =1\).

Parameters
pointsInput 2D point set, stored in std::vector<> or Mat
Note
Input point types are Point2i or Point2f and at least 5 points are required.
getClosestEllipsePoints function can be used to compute the ellipse fitting error.
Examples
samples/cpp/geometry.cpp.

◆ fitLine()

void cv::fitLine ( InputArray points,
OutputArray line,
int distType,
double param,
double reps,
double aeps )
Python:
cv.fitLine(points, distType, param, reps, aeps[, line]) -> line

#include <opencv2/geometry/2d.hpp>

Fits a line to a 2D or 3D point set.

The function fitLine fits a line to a 2D or 3D point set by minimizing \(\sum_i \rho(r_i)\) where \(r_i\) is a distance between the \(i^{th}\) point, the line and \(\rho(r)\) is a distance function, one of the following:

  • DIST_L2

    \[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\]

  • DIST_L1

    \[\rho (r) = r\]

  • DIST_L12

    \[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\]

  • DIST_FAIR

    \[\rho \left (r \right ) = C^2 \cdot \left ( \frac{r}{C} - \log{\left(1 + \frac{r}{C}\right)} \right ) \quad \text{where} \quad C=1.3998\]

  • DIST_WELSCH

    \[\rho \left (r \right ) = \frac{C^2}{2} \cdot \left ( 1 - \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right ) \quad \text{where} \quad C=2.9846\]

  • DIST_HUBER

    \[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\]

The algorithm is based on the M-estimator ( https://en.wikipedia.org/wiki/M-estimator ) technique that iteratively fits the line using the weighted least-squares algorithm. After each iteration the weights \(w_i\) are adjusted to be inversely proportional to \(\rho(r_i)\) .

Parameters
pointsInput vector of 2D or 3D points, stored in std::vector<> or Mat.
lineOutput line parameters. In case of 2D fitting, it should be a vector of 4 elements (like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and (x0, y0) is a point on the line. In case of 3D fitting, it should be a vector of 6 elements (like Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line and (x0, y0, z0) is a point on the line.
distTypeDistance used by the M-estimator, see DistanceTypes
paramNumerical parameter ( C ) for some types of distances. If it is 0, an optimal value is chosen.
repsSufficient accuracy for the radius (distance between the coordinate origin and the line).
aepsSufficient accuracy for the angle. 0.01 would be a good default value for reps and aeps.

◆ getAffineTransform() [1/2]

Mat cv::getAffineTransform ( const Point2f src[],
const Point2f dst[] )
Python:
cv.getAffineTransform(src, dst) -> retval

#include <opencv2/geometry/2d.hpp>

Calculates an affine transform from three pairs of the corresponding points.

The function calculates the \(2 \times 3\) matrix of an affine transform so that:

\[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\]

where

\[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\]

Parameters
srcCoordinates of triangle vertices in the source image.
dstCoordinates of the corresponding triangle vertices in the destination image.
See also
warpAffine, transform

◆ getAffineTransform() [2/2]

Mat cv::getAffineTransform ( InputArray src,
InputArray dst )
Python:
cv.getAffineTransform(src, dst) -> retval

◆ getClosestEllipsePoints()

void cv::getClosestEllipsePoints ( const RotatedRect & ellipse_params,
InputArray points,
OutputArray closest_pts )
Python:
cv.getClosestEllipsePoints(ellipse_params, points[, closest_pts]) -> closest_pts

#include <opencv2/geometry/2d.hpp>

Compute for each 2d point the nearest 2d point located on a given ellipse.

The function computes the nearest 2d location on a given ellipse for a vector of 2d points and is based on [Chatfield2017] code. This function can be used to compute for instance the ellipse fitting error.

Parameters
ellipse_paramsEllipse parameters
pointsInput 2d points
closest_ptsFor each 2d point, their corresponding closest 2d point located on a given ellipse
Note
Input point types are Point2i or Point2f
See also
fitEllipse, fitEllipseAMS, fitEllipseDirect

◆ getEdge()

int cv::Subdiv2D::getEdge ( int edge,
int nextEdgeType ) const
Python:
cv.Subdiv2D.getEdge(edge, nextEdgeType) -> retval

#include <opencv2/geometry/2d.hpp>

Returns one of the edges related to the given edge.

Parameters
edgeSubdivision edge ID.
nextEdgeTypeParameter specifying which of the related edges to return. The following values are possible:
  • NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge)
  • NEXT_AROUND_DST next around the edge vertex ( eDnext )
  • PREV_AROUND_ORG previous around the edge origin (reversed eRnext )
  • PREV_AROUND_DST previous around the edge destination (reversed eLnext )
  • NEXT_AROUND_LEFT next around the left facet ( eLnext )
  • NEXT_AROUND_RIGHT next around the right facet ( eRnext )
  • PREV_AROUND_LEFT previous around the left facet (reversed eOnext )
  • PREV_AROUND_RIGHT previous around the right facet (reversed eDnext )
sample output
Returns
edge ID related to the input edge.

◆ getEdgeList()

void cv::Subdiv2D::getEdgeList ( std::vector< Vec4f > & edgeList) const
Python:
cv.Subdiv2D.getEdgeList() -> edgeList

#include <opencv2/geometry/2d.hpp>

Returns a list of all edges.

Parameters
edgeListOutput vector.

The function gives each edge as a 4 numbers vector, where each two are one of the edge vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3].

◆ getLeadingEdgeList()

void cv::Subdiv2D::getLeadingEdgeList ( std::vector< int > & leadingEdgeList) const
Python:
cv.Subdiv2D.getLeadingEdgeList() -> leadingEdgeList

#include <opencv2/geometry/2d.hpp>

Returns a list of the leading edge ID connected to each triangle.

Parameters
leadingEdgeListOutput vector.

The function gives one edge ID for each triangle.

◆ getPerspectiveTransform() [1/2]

Mat cv::getPerspectiveTransform ( const Point2f src[],
const Point2f dst[],
int solveMethod = DECOMP_LU )
Python:
cv.getPerspectiveTransform(src, dst[, solveMethod]) -> retval

#include <opencv2/geometry/2d.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getPerspectiveTransform() [2/2]

Mat cv::getPerspectiveTransform ( InputArray src,
InputArray dst,
int solveMethod = DECOMP_LU )
Python:
cv.getPerspectiveTransform(src, dst[, solveMethod]) -> retval

#include <opencv2/geometry/2d.hpp>

Calculates a perspective transform from four pairs of the corresponding points.

The function calculates the \(3 \times 3\) matrix of a perspective transform so that:

\[\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\]

where

\[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\]

Parameters
srcCoordinates of quadrangle vertices in the source image.
dstCoordinates of the corresponding quadrangle vertices in the destination image.
solveMethodmethod passed to cv::solve (DecompTypes)
See also
findHomography, warpPerspective, perspectiveTransform
Examples
samples/cpp/snippets/warpPerspective_demo.cpp, and samples/dnn/text_detection.cpp.

◆ getRotationMatrix2D()

Mat cv::getRotationMatrix2D ( Point2f center,
double angle,
double scale )
inline
Python:
cv.getRotationMatrix2D(center, angle, scale) -> retval

#include <opencv2/geometry/2d.hpp>

Calculates an affine matrix of 2D rotation.

The function calculates the following matrix:

\[\begin{bmatrix} \alpha & \beta & (1- \alpha ) \cdot \texttt{center.x} - \beta \cdot \texttt{center.y} \\ - \beta & \alpha & \beta \cdot \texttt{center.x} + (1- \alpha ) \cdot \texttt{center.y} \end{bmatrix}\]

where

\[\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}\]

The transformation maps the rotation center to itself. If this is not the target, adjust the shift.

Parameters
centerCenter of the rotation in the source image.
angleRotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner).
scaleIsotropic scale factor.
See also
getAffineTransform, warpAffine, transform

◆ getRotationMatrix2D_()

Matx23d cv::getRotationMatrix2D_ ( Point2f center,
double angle,
double scale )

◆ getTriangleList()

void cv::Subdiv2D::getTriangleList ( std::vector< Vec6f > & triangleList) const
Python:
cv.Subdiv2D.getTriangleList() -> triangleList

#include <opencv2/geometry/2d.hpp>

Returns a list of all triangles.

Parameters
triangleListOutput vector.

The function gives each triangle as a 6 numbers vector, where each two are one of the triangle vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5].

◆ getVertex()

Point2f cv::Subdiv2D::getVertex ( int vertex,
int * firstEdge = 0 ) const
Python:
cv.Subdiv2D.getVertex(vertex) -> retval, firstEdge

#include <opencv2/geometry/2d.hpp>

Returns vertex location from vertex ID.

Parameters
vertexvertex ID.
firstEdgeOptional. The first edge ID which is connected to the vertex.
Returns
vertex (x,y)

◆ getVoronoiFacetList()

void cv::Subdiv2D::getVoronoiFacetList ( const std::vector< int > & idx,
std::vector< std::vector< Point2f > > & facetList,
std::vector< Point2f > & facetCenters )
Python:
cv.Subdiv2D.getVoronoiFacetList(idx) -> facetList, facetCenters

#include <opencv2/geometry/2d.hpp>

Returns a list of all Voronoi facets.

Parameters
idxVector of vertices IDs to consider. For all vertices you can pass empty vector.
facetListOutput vector of the Voronoi facets.
facetCentersOutput vector of the Voronoi facets center points.

◆ HuMoments() [1/2]

void cv::HuMoments ( const Moments & m,
OutputArray hu )
Python:
cv.HuMoments(m[, hu]) -> hu

#include <opencv2/geometry/2d.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ HuMoments() [2/2]

void cv::HuMoments ( const Moments & moments,
double hu[7] )
Python:
cv.HuMoments(m[, hu]) -> hu

#include <opencv2/geometry/2d.hpp>

Calculates seven Hu invariants.

The function calculates seven Hu invariants (introduced in [Hu62]; see also https://en.wikipedia.org/wiki/Image_moment) defined as:

\[\begin{array}{l} hu[0]= \eta _{20}+ \eta _{02} \\ hu[1]=( \eta _{20}- \eta _{02})^{2}+4 \eta _{11}^{2} \\ hu[2]=( \eta _{30}-3 \eta _{12})^{2}+ (3 \eta _{21}- \eta _{03})^{2} \\ hu[3]=( \eta _{30}+ \eta _{12})^{2}+ ( \eta _{21}+ \eta _{03})^{2} \\ hu[4]=( \eta _{30}-3 \eta _{12})( \eta _{30}+ \eta _{12})[( \eta _{30}+ \eta _{12})^{2}-3( \eta _{21}+ \eta _{03})^{2}]+(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ hu[5]=( \eta _{20}- \eta _{02})[( \eta _{30}+ \eta _{12})^{2}- ( \eta _{21}+ \eta _{03})^{2}]+4 \eta _{11}( \eta _{30}+ \eta _{12})( \eta _{21}+ \eta _{03}) \\ hu[6]=(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}]-( \eta _{30}-3 \eta _{12})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ \end{array}\]

where \(\eta_{ji}\) stands for \(\texttt{Moments::nu}_{ji}\) .

These values are proved to be invariants to the image scale, rotation, and reflection except the seventh one, whose sign is changed by reflection. This invariance is proved with the assumption of infinite image resolution. In case of raster images, the computed Hu invariants for the original and transformed images are a bit different.

Parameters
momentsInput moments computed with moments .
huOutput Hu invariants.
See also
matchShapes

◆ initDelaunay() [1/2]

void cv::Subdiv2D::initDelaunay ( Rect rect)
Python:
cv.Subdiv2D.initDelaunay(rect) -> None
cv.Subdiv2D.initDelaunay2f(rect) -> None

#include <opencv2/geometry/2d.hpp>

Creates a new empty Delaunay subdivision.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
rectRectangle that includes all of the 2D points that are to be added to the subdivision.

◆ initDelaunay() [2/2]

void cv::Subdiv2D::initDelaunay ( Rect2f rect)
Python:
cv.Subdiv2D.initDelaunay(rect) -> None
cv.Subdiv2D.initDelaunay2f(rect) -> None

#include <opencv2/geometry/2d.hpp>

Creates a new empty Delaunay subdivision.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
rectRectangle that includes all of the 2d points that are to be added to the subdivision.

◆ insert() [1/2]

void cv::Subdiv2D::insert ( const std::vector< Point2f > & ptvec)
Python:
cv.Subdiv2D.insert(pt) -> retval
cv.Subdiv2D.insert(ptvec) -> None

#include <opencv2/geometry/2d.hpp>

Insert multiple points into a Delaunay triangulation.

Parameters
ptvecPoints to insert.

The function inserts a vector of points into a subdivision and modifies the subdivision topology appropriately.

◆ insert() [2/2]

int cv::Subdiv2D::insert ( Point2f pt)
Python:
cv.Subdiv2D.insert(pt) -> retval
cv.Subdiv2D.insert(ptvec) -> None

#include <opencv2/geometry/2d.hpp>

Insert a single point into a Delaunay triangulation.

Parameters
ptPoint to insert.

The function inserts a single point into a subdivision and modifies the subdivision topology appropriately. If a point with the same coordinates exists already, no new point is added.

Returns
the ID of the point.
Note
If the point is outside of the triangulation specified rect a runtime error is raised.

◆ intersectConvexConvex()

float cv::intersectConvexConvex ( InputArray p1,
InputArray p2,
OutputArray p12,
bool handleNested = true )
Python:
cv.intersectConvexConvex(p1, p2[, p12[, handleNested]]) -> retval, p12

#include <opencv2/geometry/2d.hpp>

Finds intersection of two convex polygons.

Parameters
p1First polygon
p2Second polygon
p12Output polygon describing the intersecting area
handleNestedWhen true, an intersection is found if one of the polygons is fully enclosed in the other. When false, no intersection is found. If the polygons share a side or the vertex of one polygon lies on an edge of the other, they are not considered nested and an intersection will be found regardless of the value of handleNested.
Returns
Area of intersecting polygon. May be negative, if algorithm has not converged, e.g. non-convex input.
Note
intersectConvexConvex doesn't confirm that both polygons are convex and will return invalid results if they aren't.
Examples
samples/cpp/snippets/intersectExample.cpp.

◆ invertAffineTransform()

void cv::invertAffineTransform ( InputArray M,
OutputArray iM )
Python:
cv.invertAffineTransform(M[, iM]) -> iM

#include <opencv2/geometry/2d.hpp>

Inverts an affine transformation.

The function computes an inverse affine transformation represented by \(2 \times 3\) matrix M:

\[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}\]

The result is also a \(2 \times 3\) matrix of the same type as M.

Parameters
MOriginal affine transformation.
iMOutput reverse affine transformation.

◆ isContourConvex()

bool cv::isContourConvex ( InputArray contour)
Python:
cv.isContourConvex(contour) -> retval

#include <opencv2/geometry/2d.hpp>

Tests a contour convexity.

The function tests whether the input contour is convex or not. The contour must be simple, that is, without self-intersections. Otherwise, the function output is undefined.

Parameters
contourInput vector of 2D points, stored in std::vector<> or Mat
Examples
samples/cpp/snippets/intersectExample.cpp.

◆ isfree() [1/2]

bool cv::Subdiv2D::QuadEdge::isfree ( ) const

◆ isfree() [2/2]

bool cv::Subdiv2D::Vertex::isfree ( ) const

◆ isRightOf()

int cv::Subdiv2D::isRightOf ( Point2f pt,
int edge ) const
protected

◆ isvirtual()

bool cv::Subdiv2D::Vertex::isvirtual ( ) const

◆ locate()

int cv::Subdiv2D::locate ( Point2f pt,
int & edge,
int & vertex )
Python:
cv.Subdiv2D.locate(pt) -> retval, edge, vertex

#include <opencv2/geometry/2d.hpp>

Returns the location of a point within a Delaunay triangulation.

Parameters
ptPoint to locate.
edgeOutput edge that the point belongs to or is located to the right of it.
vertexOptional output vertex the input point coincides with.

The function locates the input point within the subdivision and gives one of the triangle edges or vertices.

Returns
an integer which specify one of the following five cases for point location:
  • The point falls into some facet. The function returns PTLOC_INSIDE and edge will contain one of edges of the facet.
  • The point falls onto the edge. The function returns PTLOC_ON_EDGE and edge will contain this edge.
  • The point coincides with one of the subdivision vertices. The function returns PTLOC_VERTEX and vertex will contain a pointer to the vertex.
  • The point is outside the subdivision reference rectangle. The function returns PTLOC_OUTSIDE_RECT and no pointers are filled.
  • One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error processing mode is selected, PTLOC_ERROR is returned.

◆ matchShapes()

double cv::matchShapes ( InputArray contour1,
InputArray contour2,
int method,
double parameter )
Python:
cv.matchShapes(contour1, contour2, method, parameter) -> retval

#include <opencv2/geometry/2d.hpp>

Compares two shapes.

The function compares two shapes. All three implemented methods use the Hu invariants (see HuMoments)

Parameters
contour1First contour or grayscale image.
contour2Second contour or grayscale image.
methodComparison method, see ShapeMatchModes
parameterMethod-specific parameter (not supported now).

◆ minAreaRect()

RotatedRect cv::minAreaRect ( InputArray points)
Python:
cv.minAreaRect(points) -> retval

#include <opencv2/geometry/2d.hpp>

Finds a rotated rectangle of the minimum area enclosing the input 2D point set.

The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a specified point set. The angle of rotation represents the angle between the line connecting the starting and ending points (based on the clockwise order with greatest index for the corner with greatest \(y\)) and the horizontal axis. This angle always falls between \([-90, 0)\) because, if the object rotates more than a rect angle, the next edge is used to measure the angle. The starting and ending points change as the object rotates.Developer should keep in mind that the returned RotatedRect can contain negative indices when data is close to the containing Mat element boundary.

Parameters
pointsInput vector of 2D points, stored in std::vector<> or Mat
Examples
samples/cpp/geometry.cpp.

◆ minEnclosingCircle()

void cv::minEnclosingCircle ( InputArray points,
Point2f & center,
float & radius )
Python:
cv.minEnclosingCircle(points) -> center, radius

#include <opencv2/geometry/2d.hpp>

Finds a circle of the minimum area enclosing a 2D point set.

The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm.

Parameters
pointsInput vector of 2D points, stored in std::vector<> or Mat
centerOutput center of the circle.
radiusOutput radius of the circle.
Examples
samples/cpp/geometry.cpp.

◆ minEnclosingConvexPolygon()

double cv::minEnclosingConvexPolygon ( InputArray points,
OutputArray polygon,
int k )
Python:
cv.minEnclosingConvexPolygon(points, k[, polygon]) -> retval, polygon

#include <opencv2/geometry/2d.hpp>

Finds a convex polygon of minimum area enclosing a 2D point set and returns its area.

This function takes a given set of 2D points and finds the enclosing polygon with k vertices and minimal area. It takes the set of points and the parameter k as input and returns the area of the minimal enclosing polygon.

The Implementation is based on a paper by Aggarwal, Chang and Yap [Aggarwal1985]. They provide a \(\theta(n²log(n)log(k))\) algorithm for finding the minimal convex polygon with k vertices enclosing a 2D convex polygon with n vertices (k < n). Since the minEnclosingConvexPolygon function takes a 2D point set as input, an additional preprocessing step of computing the convex hull of the 2D point set is required. The complexity of the convexHull function is \(O(n log(n))\) which is lower than \(\theta(n²log(n)log(k))\). Thus the overall complexity of the function is \(O(n²log(n)log(k))\).

Parameters
pointsInput vector of 2D points, stored in std::vector<> or Mat
polygonOutput vector of 2D points defining the vertices of the enclosing polygon
kNumber of vertices of the output polygon

◆ minEnclosingTriangle()

double cv::minEnclosingTriangle ( InputArray points,
OutputArray triangle )
Python:
cv.minEnclosingTriangle(points[, triangle]) -> retval, triangle

#include <opencv2/geometry/2d.hpp>

Finds a triangle of minimum area enclosing a 2D point set and returns its area.

The function finds a triangle of minimum area enclosing the given set of 2D points and returns its area. The output for a given 2D point set is shown in the image below. 2D points are depicted in red* and the enclosing triangle in yellow.

Sample output of the minimum enclosing triangle function

The implementation of the algorithm is based on O'Rourke's [ORourke86] and Klee and Laskowski's [KleeLaskowski85] papers. O'Rourke provides a \(\theta(n)\) algorithm for finding the minimal enclosing triangle of a 2D convex polygon with n vertices. Since the minEnclosingTriangle function takes a 2D point set as input an additional preprocessing step of computing the convex hull of the 2D point set is required. The complexity of the convexHull function is \(O(n log(n))\) which is higher than \(\theta(n)\). Thus the overall complexity of the function is \(O(n log(n))\).

Parameters
pointsInput vector of 2D points with depth CV_32S or CV_32F, stored in std::vector<> or Mat
triangleOutput vector of three 2D points defining the vertices of the triangle. The depth of the OutputArray must be CV_32F.
Examples
samples/cpp/geometry.cpp.

◆ moments()

Moments cv::moments ( InputArray array,
bool binaryImage = false )
Python:
cv.moments(array[, binaryImage]) -> retval

#include <opencv2/geometry/2d.hpp>

Calculates all of the moments up to the third order of a polygon or rasterized shape.

The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. The results are returned in the structure cv::Moments.

Parameters
arraySingle channel raster image (CV_8U, CV_16U, CV_16S, CV_32F, CV_64F) or an array ( \(1 \times N\) or \(N \times 1\) ) of 2D points (Point or Point2f).
binaryImageIf it is true, all non-zero image pixels are treated as 1's. The parameter is used for images only.
Returns
moments.
Note
Only applicable to contour moments calculations from Python bindings: Note that the numpy type for the input array should be either np.int32 or np.float32.
For contour-based moments, the zeroth-order moment m00 represents the contour area.

If the input contour is degenerate (for example, a single point or all points are collinear), the area is zero and therefore m00 == 0.

In this case, the centroid coordinates (m10/m00, m01/m00) are undefined and must be handled explicitly by the caller.

A common workaround is to compute the center using cv::boundingRect() or by averaging the input points.

See also
contourArea, arcLength

◆ newEdge()

int cv::Subdiv2D::newEdge ( )
protected

◆ newPoint()

int cv::Subdiv2D::newPoint ( Point2f pt,
bool isvirtual,
int firstEdge = 0 )
protected

◆ nextEdge()

int cv::Subdiv2D::nextEdge ( int edge) const
Python:
cv.Subdiv2D.nextEdge(edge) -> retval

#include <opencv2/geometry/2d.hpp>

Returns next edge around the edge origin.

Parameters
edgeSubdivision edge ID.
Returns
an integer which is next edge ID around the edge origin: eOnext on the picture above if e is the input edge).

◆ pointPolygonTest()

double cv::pointPolygonTest ( InputArray contour,
Point2f pt,
bool measureDist )
Python:
cv.pointPolygonTest(contour, pt, measureDist) -> retval

#include <opencv2/geometry/2d.hpp>

Performs a point-in-contour test.

The function determines whether the point is inside a contour, outside, or lies on an edge (or coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge) value, correspondingly. When measureDist=false , the return value is +1, -1, and 0, respectively. Otherwise, the return value is a signed distance between the point and the nearest contour edge.

See below a sample output of the function where each image pixel is tested against the contour:

sample output
Parameters
contourInput contour.
ptPoint tested against the contour.
measureDistIf true, the function estimates the signed distance from the point to the nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not.

◆ rotatedRectangleIntersection()

int cv::rotatedRectangleIntersection ( const RotatedRect & rect1,
const RotatedRect & rect2,
OutputArray intersectingRegion )
Python:
cv.rotatedRectangleIntersection(rect1, rect2[, intersectingRegion]) -> retval, intersectingRegion

#include <opencv2/geometry/2d.hpp>

Finds out if there is any intersection between two rotated rectangles.

If there is then the vertices of the intersecting region are returned as well.

Below are some examples of intersection configurations. The hatched pattern indicates the intersecting region and the red vertices are returned by the function.

intersection examples
Parameters
rect1First rectangle
rect2Second rectangle
intersectingRegionThe output array of the vertices of the intersecting region. It returns at most 8 vertices. Stored as std::vector<cv::Point2f> or cv::Mat as Mx1 of type CV_32FC2.
Returns
One of RectanglesIntersectTypes

◆ rotateEdge()

int cv::Subdiv2D::rotateEdge ( int edge,
int rotate ) const
Python:
cv.Subdiv2D.rotateEdge(edge, rotate) -> retval

#include <opencv2/geometry/2d.hpp>

Returns another edge of the same quad-edge.

Parameters
edgeSubdivision edge ID.
rotateParameter specifying which of the edges of the same quad-edge as the input one to return. The following values are possible:
  • 0 - the input edge ( e on the picture below if e is the input edge)
  • 1 - the rotated edge ( eRot )
  • 2 - the reversed edge (reversed e (in green))
  • 3 - the reversed rotated edge (reversed eRot (in green))
Returns
one of the edges ID of the same quad-edge as the input edge.

◆ setEdgePoints()

void cv::Subdiv2D::setEdgePoints ( int edge,
int orgPt,
int dstPt )
protected

◆ splice()

void cv::Subdiv2D::splice ( int edgeA,
int edgeB )
protected

◆ swapEdges()

void cv::Subdiv2D::swapEdges ( int edge)
protected

◆ symEdge()

int cv::Subdiv2D::symEdge ( int edge) const
Python:
cv.Subdiv2D.symEdge(edge) -> retval

Variable Documentation

◆ bottomRight

Point2f cv::Subdiv2D::bottomRight
protected

Bottom right corner of the bounding rect.

◆ firstEdge

int cv::Subdiv2D::Vertex::firstEdge

◆ freePoint

int cv::Subdiv2D::freePoint
protected

◆ freeQEdge

int cv::Subdiv2D::freeQEdge
protected

◆ next

int cv::Subdiv2D::QuadEdge::next[4]

◆ pt [1/2]

int cv::Subdiv2D::QuadEdge::pt[4]

◆ pt [2/2]

Point2f cv::Subdiv2D::Vertex::pt

◆ qedges

std::vector<QuadEdge> cv::Subdiv2D::qedges
protected

All of the edges.

◆ recentEdge

int cv::Subdiv2D::recentEdge
protected

◆ topLeft

Point2f cv::Subdiv2D::topLeft
protected

Top left corner of the bounding rect.

◆ type

int cv::Subdiv2D::Vertex::type

◆ validGeometry

bool cv::Subdiv2D::validGeometry
protected

◆ vtx

std::vector<Vertex> cv::Subdiv2D::vtx
protected

All of the vertices.