bbox_utils package¶
Submodules¶
bbox_utils.bbox_2d module¶
-
class
bbox_utils.bbox_2d.
BoundingBox
(points, ordered=False)[source]¶ Bases:
object
-
property
center
¶ Returns the center point of the bounding box as (x, y)
- Returns
center of bounding box in (x, y) form. NOT (row, column) form.
- Return type
np.array
-
static
from_xywh
(top_left, width, height)[source]¶ Create a bounding box object from the top-left point, width, and height.
- Parameters
- Returns
a new bounding box instance
- Return type
-
static
from_xyxy
(top_left, bottom_right)[source]¶ Create a bounding box object from the top-left point and bottom-right point
- Parameters
top_left (np.array) – array of form [x, y]
bottom_right ((np.array) – array of form [x, y]
- Returns
a new bounding box instance
- Return type
-
static
from_yolo
(center, width, height, image_dimension)[source]¶ Create a bounding box object from YOLO formatted data
- Parameters
- Returns
a new bounding box instance
- Return type
-
property
height
¶
-
property
points
¶
-
to_xywh
()[source]¶ Returns the top-left point, width, and height
- Returns
tuple of form (np.array, float, float)
- Return type
-
to_xyxy
()[source]¶ Returns the top-left and bottom-right coordinate
- Returns
tuple of form (np.array, np.array)
- Return type
-
to_yolo
(image_dimension)[source]¶ Generates a YOLO formatted np.array with center_x, center_y, width, height
- Parameters
image_dimension (np.array) – array with image dimensions of form
(rows (rows, cols, depth) –
or (cols)) –
- Returns
array with YOLO formatted bounding box
- Return type
np.array
-
validate_points
(image_dimension)[source]¶ Make sure all the bounding box points are within an image’s dimensions
- Parameters
image_dimension (np.array) – array with the image’s dimensions
form (in) –
- Returns
whether the points are valid
- Return type
-
property
width
¶
-
property
bbox_utils.bbox_3d module¶
3D bounding box module. This file is modified from https://github.com/varunagrawal/bbox/blob/master/bbox/bbox3d.py.
-
class
bbox_utils.bbox_3d.
BoundingBox3D
(x, y, z, length=1, width=1, height=1, rw=1, rx=0, ry=0, rz=0, q=None, euler_angles=None, is_center=True)[source]¶ Bases:
object
Class for 3D Bounding Boxes (3-orthotope). It takes either the center of the 3D bounding box or the back-bottom-left corner, the width, height and length of the box, and quaternion values to indicate the rotation. :param x: X axis coordinate of 3D bounding box. Can be either center of bounding box or back-bottom-left corner. :type x:
float
:param y: Y axis coordinate of 3D bounding box. Can be either center of bounding box or back-bottom-left corner. :type y:float
:param z: Z axis coordinate of 3D bounding box. Can be either center of bounding box or back-bottom-left corner. :type z:float
:param length: The length of the box (default is 1).This corresponds to the dimension along the x-axis.
- Parameters
width (
float
, optional) – The width of the box (default is 1). This corresponds to the dimension along the y-axis.height (
float
, optional) – The height of the box (default is 1). This corresponds to the dimension along the z-axis.rw (
float
, optional) – The real part of the rotation quaternion (default is 1).rx (
int
, optional) – The first element of the quaternion vector (default is 0).ry (
int
, optional) – The second element of the quaternion vector (default is 0).rz (
int
, optional) – The third element of the quaternion vector (default is 0).euler_angles (
list
orndarray
of float, optional) – Sequence of euler angles in [x, y, z] rotation order (the default is None).is_center (bool, optional) – Flag to indicate if the provided coordinate is the center of the box (the default is True).
-
property
center
¶ Attribute to access center coordinates of box in (x, y, z) format. Can be set to
list
orndarray
of float. :returns: 3-dimensional vector representing (x, y, z) coordinates of the box. :rtype:ndarray
of float- Raises
ValueError – If c is not a vector/list of length 3.
-
property
edges
¶ Get the edge connections for the cube
- Returns
list of edges of the cube
- Return type
np.array
-
classmethod
from_center_dimension_euler
(center, dimension, euler_angles=None)[source]¶ Factory function to create BoundingBox3D from center, dimension, and euler arrays. Can pass in either np.arrays or Python lists.
- Parameters
- Returns
a new 3D bounding box object
- Return type
-
property
p
¶ Attribute to access ndarray of all corners of box in order. :returns: All corners of the bounding box in order.
The order goes bottom->top and clockwise starting from the bottom-left point.
- Return type
ndarray
of float
-
property
q
¶ Syntactic sugar for the rotation quaternion of the box. Returns
ndarray
of float: Quaternion values in (w, x, y, z) form.
-
property
quaternion
¶ The rotation quaternion. :returns: Quaternion values in (w, x, y, z) form. :rtype:
ndarray
of float
-
property
triangle_vertices
¶ Get triangle vertices to use when plotting a triangular mesh
- Returns
Triangular vertices of the cube
- Return type
np.array
bbox_utils.image module¶
-
class
bbox_utils.image.
Image
(image, *args, **kwargs)[source]¶ Bases:
object
-
display
(image=None, title=None, library='matplotlib')[source]¶ Display an image using a library of your choice.
- Parameters
- Raises
ValueError – an error if an invalid library argument is passed.
-
display_bbox
(bbox, color=(0, 0, 255), *args, **kwargs)[source]¶ Display a single bounding box
- Parameters
bbox (BoundingBox) – a single bounding box
color (tuple, optional) – color of the bounding box in BGR. Defaults to (0, 0, 255).
-
display_bboxes
(bboxes, colors, *args, **kwargs)[source]¶ Display a list of bounding boxes
- Parameters
bboxes (list(BoundingBox)) – a list of bounding boxes
color (str or list(str)) – a list of colors for each bounding box. Color should be specified in BGR.
-
classmethod
display_cv2
(image, title=None)[source]¶ Display an image using OpenCV.
- Parameters
image (np.ndarray) – a numpy ndarray in BGR format.
title (str, optional) – the title to give the plot. Defaults to None.
-
classmethod
display_matplotlib
(image, title=None)[source]¶ Display an image using matplotlib.
- Parameters
image (np.ndarray) – a numpy ndarray in BGR format.
title (str, optional) – the title to give the plot. Defaults to None.
-
bbox_utils.point_cloud module¶
-
class
bbox_utils.point_cloud.
PointCloud
(point_cloud, *args, **kwargs)[source]¶ Bases:
object
-
crop
(bbox)[source]¶ Extract a point cloud from a 3D bounding box.
Source: https://stackoverflow.com/a/65350251/6942666
- Parameters
bbox (BoundingBox3D) – a 3D bounding box
- Returns
- a new point cloud with just the points within
the bounding box.
- Return type
-
display_bbox
(bbox, color='#ff0000', size=2, *args, **kwargs)[source]¶ Display a single bounding box
- Parameters
bbox (BoundingBox) – a single bounding box
color (string, optional) – a valid Plotly color. Defaults to ‘#ff0000’
- Returns
a Plotly figure
- Return type
Figure
-
display_bboxes
(bboxes, colors='#ff0000', size=2, *args, **kwargs)[source]¶ Display a list of bounding boxes
- Parameters
bboxes (list(BoundingBox)) – a list of bounding boxes
a valid Plotly color: The ‘color’ property is a color and may be specified as:
A hex string (e.g. ‘#ff0000’)
An rgb/rgba string (e.g. ‘rgb(255,0,0)’)
An hsl/hsla string (e.g. ‘hsl(0,100%,50%)’)
An hsv/hsva string (e.g. ‘hsv(0,100%,100%)’)
- A named CSS color:
aliceblue, antiquewhite, aqua, aquamarine, azure, beige, bisque, black, blanchedalmond, blue, blueviolet, brown, burlywood, cadetblue, chartreuse, chocolate, coral, cornflowerblue, cornsilk, crimson, cyan, darkblue, darkcyan, darkgoldenrod, darkgray, darkgrey, darkgreen, darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, darksalmon, darkseagreen, darkslateblue, darkslategray, darkslategrey, darkturquoise, darkviolet, deeppink, deepskyblue, dimgray, dimgrey, dodgerblue, firebrick, floralwhite, forestgreen, fuchsia, gainsboro, ghostwhite, gold, goldenrod, gray, grey, green, greenyellow, honeydew, hotpink, indianred, indigo, ivory, khaki, lavender, lavenderblush, lawngreen, lemonchiffon, lightblue, lightcoral, lightcyan, lightgoldenrodyellow, lightgray, lightgrey, lightgreen, lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray, lightslategrey, lightsteelblue, lightyellow, lime, limegreen, linen, magenta, maroon, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, mediumvioletred, midnightblue, mintcream, mistyrose, moccasin, navajowhite, navy, oldlace, olive, olivedrab, orange, orangered, orchid, palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue, purple, red, rosybrown, royalblue, rebeccapurple, saddlebrown, salmon, sandybrown, seagreen, seashell, sienna, silver, skyblue, slateblue, slategray, slategrey, snow, springgreen, steelblue, tan, teal, thistle, tomato, turquoise, violet, wheat, white, whitesmoke, yellow, yellowgreen
A number that will be interpreted as a color
according to mesh3d.colorscale
-
classmethod
load_from_file
(file_path, *args, **kwargs)[source]¶ Loads a point cloud from a file
- Parameters
file_path (str) – the path to the file
-
property
number_of_points
¶ The number of points within a point cloud.
- Returns
the number of points within a point cloud.
- Return type
-
property
points
¶ Get a np.ndarray representation of the point cloud.
- Returns
the point cloud’s points
- Return type
np.ndarray
-
bbox_utils.utils module¶
-
bbox_utils.utils.
in_google_colab
()[source]¶ Checks to see whether currently running in Google Colab.
- Returns
True or False
- Return type
-
bbox_utils.utils.
order_points
(pts)[source]¶ Orders points in form [top left, top right, bottom right, bottom left]. Source: https://www.pyimagesearch.com/2016/03/21/ordering-coordinates-clockwise-with-python-and-opencv/
- Parameters
pts (np.ndarray) – list of points of form [[x1, y1], [x2, y2], [x3, y3], [x4, y4]]
- Returns
[description]
- Return type
[type]
-
bbox_utils.utils.
point_within_dimensions
(point, image_dimensions)[source]¶ Checks to see if a point falls inside an image’s dimension. Works for any number of dimensions. Acceptable range is [0, dim)
- Parameters
point (np.array) – array with the point’s coordinates
image_dimensions (np.array) – array with the image dimensions
- Returns
whether the point lies within the dimensions
- Return type
-
bbox_utils.utils.
pointwise_distance
(pts1, pts2)[source]¶ Calculates the distance between pairs of points
- Parameters
pts1 (np.ndarray) – array of form [[x1, y1], [x2, y2], …]
pts2 (np.ndarray) – array of form [[x1, y1], [x2, y2], …]
- Returns
distances between corresponding points
- Return type
np.array