ImageEn, unit IEVision

TIEVisionMath.convexHull

TIEVisionMath.convexHull

Declaration

function convexHull(points: TIEVisionVectorPoint; clockwise: bool32 = False): TIEVisionVectorPoint; overload; safecall;
function convexHull(points: TIEVisionVectorPoint2f; clockwise: bool32 = False): TIEVisionVectorPoint2f; overload; safecall;

Description

Returns the convex hull of a point set, i.e. the smallest convex polygon that contains all the points (like a rubber band stretched around them).
The hull points are returned in order around the polygon.
Parameter Description
points Point set, e.g. a contour from findContours or a list of landmarks
clockwise Orientation of the result. As in OpenCV, this assumes the Y axis points up, so on an image (where Y points down) the default of False runs clockwise on screen

Note:
◼Use convexHullIndices to get the positions of the hull points in the source list
◼The ratio of contourArea of a contour to the area of its hull ("solidity") is a common shape measure
◼Returns an empty list for an empty point set. Raises an exception for NaN or infinite coordinates

Demo

Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr

Examples

Also see: Automated Samples
// Draw the convex hull of some points on the image
points := IEVisionLib().createVectorPoint();
points.push_back( IEVisionPoint( 100, 100 ));
points.push_back( IEVisionPoint( 300, 120 ));
points.push_back( IEVisionPoint( 200, 180 ));  // Inside the hull
points.push_back( IEVisionPoint( 250, 350 ));
points.push_back( IEVisionPoint( 80, 280 ));

hull := IEVisionLib().createMath().convexHull( points );
contours := IEVisionLib().createVectorObjRef();
contours.push_back( hull );
IEVisionLib().createDrawing().drawContours( ImageEnView1.IEBitmap.GetIEVisionImage(), contours, IEVisionScalar( 0, 0, 255 ), -1, 2 );
ImageEnView1.Update();


// Draw the convex hull of 20 random points in the middle of the image
w := ImageEnView1.IEBitmap.Width;
h := ImageEnView1.IEBitmap.Height;
pts := IEVisionLib().createVectorPoint();
for i := 1 to 20 do
  pts.push_back( IEVisionPoint( w div 5 + Random( w * 3 div 5 ), h div 5 + Random( h * 3 div 5 )));
hull := IEVisionLib().createMath().convexHull( pts );
contours := IEVisionLib().createVectorObjRef();
contours.push_back( hull );
IEVisionLib().createDrawing().drawContours( ImageEnView1.IEBitmap.GetIEVisionImage(), contours, IEVisionScalar( 0, 0, 255 ), -1, 2, 16 );
ImageEnView1.Update();

  

See Also

◼convexHullIndices
◼contourArea
◼fillConvexPoly