Polygon

class Polygon(*args, **kwargs)

Bases: pybind11_object

Defines a generic 2D polygon.

A polygon is internally represented by N 2D points.

By default three coordinates in the \((i,j)\) frame (see vpImagePoint class documentation for more details about the frame) are used \((0,0)\) , \((1,0)\) and \((0,1)\) .

The code bellow shows how to manipulate a polygon.

#include <iostream>

#include <visp3/core/vpPolygon.h>

int main()
{
  std::vector<vpImagePoint> corners;

  // Initialize the corners vector with 4 points
  corners.push_back( vpImagePoint( 50, 100) );
  corners.push_back( vpImagePoint( 50, 300) );
  corners.push_back( vpImagePoint(200, 300) );
  corners.push_back( vpImagePoint(200, 100) );

  // Initialize a polygon with the corners
  vpPolygon polygon(corners);

  // Get the polygon bounding box
  vpRect bbox = polygon.getBoundingBox();
  std::cout << "Bounding box: " << bbox.getTopLeft() << " to "
            << bbox.getBottomRight() << std::endl;

  // Get the polygon surface and center
  std::cout << "Area: " << polygon.getArea() << std::endl;
  std::cout << "Center: " << polygon.getCenter() << std::endl;

  // Check if a point is inside the polygon
  vpImagePoint ip(550, 200);
  std::cout << "The point " << ip << " is "
            << (polygon.isInside(ip) ? "inside":"outside")
            << " the polygon" << std::endl;

  return 0;
}

Overloaded function.

  1. __init__(self: visp._visp.core.Polygon) -> None

Default constructor that creates an empty polygon.

  1. __init__(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint]) -> None

Constructor which initialises the polygon thanks to the given corners.

Warning

the corners must be ordered (either clockwise or counter clockwise).

Parameters:
corners

The Points defining the corners.

  1. __init__(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint]) -> None

Constructor which initialises the polygon thanks to the given corners.

Warning

the corners must be ordered (either clockwise or counter clockwise).

Parameters:
corners

The Points defining the corners.

  1. __init__(self: visp._visp.core.Polygon, poly: visp._visp.core.Polygon) -> None

Copy constructor

Parameters:
poly

The polygon used for the initialisation.

Methods

__init__

Overloaded function.

buildFrom

Overloaded function.

display

Display the polygon in the image (overlay, so the image is not modified).

getArea

Return the area of the polygon.

getBoundingBox

Return the bounding box.

getCenter

Return the center of the polygon.

getCorners

Get the corners of the polygon.

getSize

Return number of corners belonging to the polygon.

initClick

Overloaded function.

isInside

isInsideFromPoints

Inherited Methods

Operators

__doc__

__init__

Overloaded function.

__module__

Attributes

PnPolyRayCasting

PnPolySegmentIntersection

__annotations__

class PointInPolygonMethod(self, value: int)

Bases: pybind11_object

Values:

  • PnPolySegmentIntersection: Legacy Point In Polygon test.

  • PnPolyRayCasting: Point In Polygon test using ray casting method (faster).

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: visp._visp.core.Polygon) -> None

Default constructor that creates an empty polygon.

  1. __init__(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint]) -> None

Constructor which initialises the polygon thanks to the given corners.

Warning

the corners must be ordered (either clockwise or counter clockwise).

Parameters:
corners

The Points defining the corners.

  1. __init__(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint]) -> None

Constructor which initialises the polygon thanks to the given corners.

Warning

the corners must be ordered (either clockwise or counter clockwise).

Parameters:
corners

The Points defining the corners.

  1. __init__(self: visp._visp.core.Polygon, poly: visp._visp.core.Polygon) -> None

Copy constructor

Parameters:
poly

The polygon used for the initialisation.

buildFrom(*args, **kwargs)

Overloaded function.

  1. buildFrom(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint], create_convex_hull: bool = false) -> None

Initialises the triangle thanks to the collection of 2D points (in pixel).

Warning

the corners must be ordered (either clockwise or counter clockwise).

Parameters:
corners

The corners of the polygon.

create_convex_hull

Create a convex hull from the given corners.

  1. buildFrom(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint], create_convex_hull: bool = false) -> None

Initialises the polygon thanks to the collection of 2D points (in pixel).

Warning

the corners must be ordered (either clockwise or counter clockwise).

Parameters:
corners

The corners of the polygon.

create_convex_hull

Create a convex hull from the given corners.

  1. buildFrom(self: visp._visp.core.Polygon, corners: list[visp._visp.core.Point], cam: visp._visp.core.CameraParameters, create_convex_hull: bool = false) -> None

Initialises the triangle thanks to the collection of 2D points (in meter). The fields x and y are used to compute the corresponding coordinates in pixel thanks to the camera parameters cam .

Warning

the corners must be ordered (either clockwise or counter clockwise).

Parameters:
corners

The corners of the polygon.

cam

The camera parameters used to convert the coordinates from meter to pixel.

create_convex_hull

Create a convex hull from the given corners.

display(self, I: visp._visp.core.ImageGray, color: visp._visp.core.Color, thickness: int = 1) None

Display the polygon in the image (overlay, so the image is not modified). A call to the flush() method is necessary.

Parameters:
I: visp._visp.core.ImageGray

The image where the polygon is displayed.

color: visp._visp.core.Color

The color of the polygon’s lines.

thickness: int = 1

The thickness of the polygon’s lines.

getArea(self) float

Return the area of the polygon. The area is computed when the polygon is built from the corners.

Returns:

The area of the polygon.

getBoundingBox(self) visp._visp.core.Rect

Return the bounding box. The bounding box is the smallest rectangle containing all the polygon.

Returns:

The bounding box of the polygon.

getCenter(self) visp._visp.core.ImagePoint

Return the center of the polygon. The center is computed when the polygon is built from the corners.

Returns:

The area of the polygon.

getCorners(self) list[visp._visp.core.ImagePoint]

Get the corners of the polygon.

Returns:

A reference to the corners.

getSize(self) int

Return number of corners belonging to the polygon.

initClick(*args, **kwargs)

Overloaded function.

  1. initClick(self: visp._visp.core.Polygon, I: visp._visp.core.ImageGray, size: int = 5, color: visp._visp.core.Color = vpColor::red, thickness: int = 1) -> None

Initialises the polygon by (left-)clicking to add a corners to the polygon. A right click is used to stop the addition of new corners.

Parameters:
I

The image where to click to initialise the corners.

size

Cross size in terms of number of pixels that is displayed over a polygon corner.

color

Color used to display the cross over the polygon corner.

thickness

Thickness used to display the cross.

  1. initClick(self: visp._visp.core.Polygon, I: visp._visp.core.ImageRGBa, size: int = 5, color: visp._visp.core.Color = vpColor::red, thickness: int = 1) -> None

Initialises the polygon by (left-)clicking to add a corners to the polygon. A right click is used to stop the addition of new corners.

Parameters:
I

The image where to click to initialise the corners.

size

Size of the cross in terms of number of pixels that is displayed over a polygon corner.

color

Color used to display the cross over the polygon corner.

thickness

Thickness used to display the cross.

isInside(self, iP: visp._visp.core.ImagePoint, method: visp._visp.core.Polygon.PointInPolygonMethod = PnPolyRayCasting) bool
static isInsideFromPoints(roi: list[visp._visp.core.ImagePoint], i: float, j: float, method: visp._visp.core.Polygon.PointInPolygonMethod = PnPolyRayCasting) bool