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> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif 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.
__init__(self: visp._visp.core.Polygon) -> None
Default constructor that creates an empty polygon.
__init__(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint]) -> None
__init__(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint]) -> None
__init__(self: visp._visp.core.Polygon, poly: visp._visp.core.Polygon) -> None
Copy constructor
- Parameters:
- poly
The polygon used for the initialisation.
Methods
Overloaded function.
Overloaded function.
Display the polygon in the image (overlay, so the image is not modified).
Return the area of the polygon.
Return the bounding box.
Return the center of the polygon.
Get the corners of the polygon.
Return number of corners belonging to the polygon.
Overloaded function.
Inherited Methods
Operators
__doc__
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).
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.Polygon) -> None
Default constructor that creates an empty polygon.
__init__(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint]) -> None
__init__(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint]) -> None
__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.
buildFrom(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint], create_convex_hull: bool = false) -> visp._visp.core.Polygon
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.
buildFrom(self: visp._visp.core.Polygon, corners: list[visp._visp.core.ImagePoint], create_convex_hull: bool = false) -> visp._visp.core.Polygon
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.
buildFrom(self: visp._visp.core.Polygon, corners: list[visp._visp.core.Point], cam: visp._visp.core.CameraParameters, create_convex_hull: bool = false) -> visp._visp.core.Polygon
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.
- initClick(*args, **kwargs)¶
Overloaded function.
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.
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 ¶