OrientedBBox¶
-
class OrientedBBox(top, left, bottom, right, angle=
0, sly_id=None, class_id=None, labeler_login=None, updated_at=None, created_at=None)[source]¶ Bases:
Rectangle2D bounding box with rotation angle; axis-aligned coordinates plus angle. Immutable.
OrientedBBox geometry for a single
Label.OrientedBBoxclass object is immutable.- Parameters:
- top : int or float¶
Minimal vertical value of the oriented bounding box.
- left : int or float¶
Minimal horizontal value of the oriented bounding box.
- bottom : int or float¶
Maximal vertical value of the oriented bounding box.
- right : int or float¶
Maximal vertical value of the oriented bounding box.
- angle : int or float, optional¶
Angle of rotation in radians. Positive values mean clockwise rotation.
- sly_id : int, optional¶
OrientedBBox ID in Supervisely server.
- class_id : int, optional¶
ID of ObjClass to which OrientedBBox belongs.
- labeler_login : str, optional¶
Login of the user who created the oriented bounding box.
- updated_at : str, optional¶
Date and Time when OrientedBBox was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: ‘2021-01-22T19:37:50.158Z’.
- created_at : str, optional¶
Date and Time when OrientedBBox was created. Date Format is the same as in “updated_at” parameter.
- Raises:
ValueError – if top argument has greater value than bottom, or left argument has greater value than right
- Usage Example:
import supervisely as sly import math top = 100 left = 100 bottom = 700 right = 900 angle = math.pi / 12 # 15 degrees in radians figure = sly.OrientedBBox(top, left, bottom, right, angle=angle)
Methods
Returns the allowed transforms for the OrientedBBox.
Get the corners of the OrientedBBox.
Clone from GEOMETRYYY
Convert geometry config from json format
Convert geometry config to json format
Checks if Rectangle contains a given Rectangle object.
Check if the OrientedBBox contains the given OrientedBBox.
Check if the OrientedBBox contains the given point.
Check if the OrientedBBox contains the given point.
Check if the OrientedBBox contains the given Rectangle.
Convert geometry to another geometry shape.
Crop the OrientedBBox by another OrientedBBox using the Sutherland-Hodgman algorithm.
Draws the figure contour on a given bitmap canvas :param bitmap: np.ndarray :param color: [R, G, B] :param thickness: (int) :param config: drawing config specific to a concrete subclass, e.g. per edge colors.
Flips current Rectangle in horizontal.
Flips current Rectangle in vertical.
Create OrientedBBox with given array shape.
Create OrientedBBox from given Rectangle.
Create Rectangle from given geometry objects.
Convert a json dict to OrientedBBox.
Create Rectangle with given size shape.
Returns the name of the geometry.
Slice of given numpy array with OrientedBBox align bbox.
Returns 2D boolean mask of the geometry.
Checks intersects Rectangle with given Rectangle object or not.
Get the name of the geometry.
Crops object like "crop" method, but return results with coordinates relative to rect :param rect: Rectangle for crop.
Resizes current Rectangle.
Rotates current Rectangle.
Scales current Rectangle.
Convert the OrientedBBox to the axis-aligned
Rectanglethat fully contains the OrientedBBox.Convert the OrientedBBox to a json dict.
Height and width of Rectangle.
Translates current Rectangle.
Validate geometry.
Attributes
Angle of rotation in radians.
Rectangle area.
Maximal vertical value of Rectangle.
Center of Rectangle.
Get list of Rectangle corners.
Height of Rectangle
Minimal horizontal value of Rectangle.
Maximal horizontal value of Rectangle.
Minimal vertical value of Rectangle.
Width of Rectangle.
-
classmethod from_array(arr, angle=
0)[source]¶ Create OrientedBBox with given array shape.
- Parameters:
- arr : np.ndarray¶
Numpy array to create OrientedBBox from.
- Returns:
OrientedBBox from Numpy array.
- Return type:
- Usage Example:
import supervisely as sly np_array = np.zeros((300, 400)) figure_from_np = sly.OrientedBBox.from_array(np_array, angle=15)
- classmethod from_bbox(bbox)[source]¶
Create OrientedBBox from given Rectangle.
- Parameters:
- bbox¶
Rectangle to create OrientedBBox from.
- Returns:
OrientedBBox from Rectangle.
- Return type:
- Usage Example:
import supervisely as sly axis_aligned_bbox = sly.Rectangle(100, 100, 700, 900) figure_from_bbox = sly.OrientedBBox.from_bbox(axis_aligned_bbox)
- classmethod from_geometries_list(geometries)¶
Create Rectangle from given geometry objects.
- Parameters:
- geometries¶
List of geometry type objects:
Bitmap>,Cuboid>,Point>,Polygon>,Polyline>,Rectangle>,GraphNodes>.
- Returns:
Rectangle from given geometry objects.
- Return type:
- Usage Example:
import supervisely as sly geom_objs = [sly.Point(100, 200), sly.Polyline([sly.PointLocation(730, 2104), sly.PointLocation(2479, 402)])] figure_from_geom_objs = sly.Rectangle.from_geometries_list(geom_objs)
- classmethod from_json(data)[source]¶
Convert a json dict to OrientedBBox. Read more about Supervisely format.
- Parameters:
- data : Dict¶
OrientedBBox in json format as a dict.
- Returns:
OrientedBBox from json.
- Return type:
- Usage Example:
import supervisely as sly import math figure_json = { "points": [ [100, 100], [900, 700] ], "angle": math.pi / 12 # 15 degrees in radians } figure = sly.OrientedBBox.from_json(figure_json)
- classmethod name()¶
Get the name of the geometry.
Same as
geometry_name(), but shorter. In order to make the code more concise.- Returns:
string with name of geometry
- static geometry_name()[source]¶
Returns the name of the geometry.
- Returns:
name of the geometry
- Return type:
- calculate_rotated_corners()[source]¶
Get the corners of the OrientedBBox.
- Returns:
List of corners as PointLocation objects.
- Return type:
List[
PointLocation]- Usage Example:
corners = oriented_bbox.calculate_rotated_corners()
- clone()¶
Clone from GEOMETRYYY
- contains_obb(obb)[source]¶
Check if the OrientedBBox contains the given OrientedBBox.
- Parameters:
- obb¶
OrientedBBox to check.
- Returns:
True if the OrientedBBox is inside the
OrientedBBox, False otherwise- Return type:
- Usage Example:
obb2 = sly.OrientedBBox(150, 200, 400, 500, angle=10) is_inside = obb1.contains_obb(obb2)
- contains_point(geometry)[source]¶
Check if the OrientedBBox contains the given point.
- Parameters:
- geometry¶
Geometry to check.
- Returns:
True if the point is inside the
OrientedBBox, False otherwise- Return type:
- Usage Example:
point = sly.PointLocation(150, 200) is_inside = oriented_bbox.contains_point(point)
- contains_point_location(point)[source]¶
Check if the OrientedBBox contains the given point.
- Parameters:
- point¶
PointLocation to check.
- Returns:
True if the point is inside the
OrientedBBox, False otherwise- Return type:
- Usage Example:
point = sly.PointLocation(150, 200) is_inside = oriented_bbox.contains_point_location(point)
- contains_rectangle(rectangle)[source]¶
Check if the OrientedBBox contains the given Rectangle.
- Parameters:
- rectangle¶
Rectangle to check.
- Returns:
True if the Rectangle is inside the
OrientedBBox, False otherwise- Return type:
- Usage Example:
rectangle = sly.Rectangle(150, 200, 400, 500) is_inside = obb.contains_rectangle(rectangle)
-
convert(new_geometry, contour_radius=
0, approx_epsilon=None)¶ Convert geometry to another geometry shape.
- crop(clip)[source]¶
Crop the OrientedBBox by another OrientedBBox using the Sutherland-Hodgman algorithm.
-
draw_contour(bitmap, color, thickness=
1, config=None)¶ Draws the figure contour on a given bitmap canvas :param bitmap: np.ndarray :param color: [R, G, B] :param thickness: (int) :param config: drawing config specific to a concrete subclass, e.g. per edge colors
- fliplr(img_size)¶
Flips current Rectangle in horizontal.
- Parameters:
- Returns:
Flipped Rectangle in horizontal.
- Return type:
- Usage Example:
# Remember that Rectangle class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 fliplr_figure = figure.fliplr((height, width))
- flipud(img_size)¶
Flips current Rectangle in vertical.
- Parameters:
- Returns:
Flipped Rectangle in vertical.
- Return type:
- Usage Example:
# Remember that Rectangle class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 flipud_figure = figure.flipud((height, width))
- get_cropped_numpy_slice(data)[source]¶
Slice of given numpy array with OrientedBBox align bbox.
- Parameters:
- data : np.ndarray¶
Numpy array to slice.
- Returns:
Sliced numpy array
- Return type:
np.ndarray
- Usage Example:
np_slice = np.zeros((200, 500)) mask_slice = figure.get_cropped_numpy_slice(np_slice) print(mask_slice.shape)
- get_mask(img_size)¶
Returns 2D boolean mask of the geometry. With shape as img_size (height, width) and filled with True values inside the geometry and False values outside. dtype = np.bool shape = img_size
- relative_crop(rect)¶
Crops object like “crop” method, but return results with coordinates relative to rect :param rect: Rectangle for crop. :type rect:
Rectangle:returns: List of Geometry after relative crop. :rtype: List[Geometry]` :raises NotImplementedError: if method is not implemented in subclass
- resize(in_size, out_size)¶
Resizes current Rectangle.
- Parameters:
- Returns:
Resized Rectangle.
- Return type:
- Usage Example:
# Remember that Rectangle class object is immutable, and we need to assign new instance of Rectangle to a new variable in_height, in_width = 300, 400 out_height, out_width = 600, 800 resize_figure = figure.resize((in_height, in_width), (out_height, out_width))
- rotate(rotator)¶
Rotates current Rectangle.
- Parameters:
- rotator¶
Class for object rotation.
- Returns:
Rotated Rectangle.
- Return type:
- Usage Example:
from supervisely.geometry.image_rotator import ImageRotator # Remember that Rectangle class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 rotator = ImageRotator((height, width), 25) rotate_figure = figure.rotate(rotator)
- to_bbox()[source]¶
Convert the OrientedBBox to the axis-aligned
Rectanglethat fully contains the OrientedBBox.- Returns:
Axis-aligned Rectangle that fully contains the OrientedBBox.
- Return type:
- Usage Example:
axis_aligned_bbox = oriented_bbox.to_bbox()
- to_json()[source]¶
Convert the OrientedBBox to a json dict. Read more about Supervisely format.
- Returns:
Json format as a dict
- Return type:
- Usage Example:
figure_json = figure.to_json() print(figure_json) # Output: { # "points": [ # [100, 100], # [900, 700] # ], # "angle": 0.2618 # radians (15 degrees) # }
- to_size()¶
Height and width of Rectangle.
- Returns:
Height and width of Rectangle.
- Return type:
Tuple[int, int]- Usage Example:
height, width = figure.to_size() print(height, width) # Output: 700 900
- translate(drow, dcol)¶
Translates current Rectangle.
- Parameters:
- Returns:
Translated Rectangle.
- Return type:
- Usage Example:
# Remember that Rectangle class object is immutable, and we need to assign new instance of Rectangle to a new variable translate_figure = figure.translate(150, 250)
- validate(obj_class_shape, settings)¶
Validate geometry.
- Parameters:
- Raises:
ValueError – if geometry validation error
- property angle : int | float¶
Angle of rotation in radians. Positive values mean clockwise rotation.
- property area : float¶
Rectangle area.
- Returns:
Area of current Rectangle.
- Return type:
- Usage Example:
print(figure.area) # Output: 7288.0
- property bottom : int¶
Maximal vertical value of Rectangle.
- Returns:
Maximal vertical value
- Return type:
- Usage Example:
print(figure.bottom) # Output: 700
- property center : supervisely.geometry.point_location.PointLocation¶
Center of Rectangle.
- Returns:
Center of Rectangle.
- Return type:
- Usage Example:
center = figure.center()
- property corners : list[PointLocation, PointLocation, PointLocation, PointLocation]¶
Get list of Rectangle corners.
- Returns:
List of Rectangle corners.
- Return type:
List[
PointLocation]- Usage Example:
corners = figure.corners for corner in corners: print(corner.row, corner.col) # Output: # 100 100 # 100 900 # 700 900 # 700 100
- property height : int¶
Height of Rectangle
- Returns:
Height
- Return type:
- Usage Example:
print(figure.height) # Output: 601
- property left : int¶
Minimal horizontal value of Rectangle.
- Returns:
Minimal horizontal value
- Return type:
- Usage Example:
print(figure.left) # Output: 100
- property right : int¶
Maximal horizontal value of Rectangle.
- Returns:
Maximal horizontal value
- Return type:
- Usage Example:
print(figure.right) # Output: 900