BoundingBox

class BoundingBox(start_x, start_y, end_x, end_y)

A rectangular bounding box.

Checking if two BoundingBox instances are equal checks the equivalence of their coordinates.

Multiplying a BoundingBox by a scalar scales the bounding box and position. This can be helpful when scaling an image up or down.

Parameters:
  • start_x (int) – The starting x value.

  • start_y (int) – The starting y value.

  • end_x (int) – The ending x value.

  • end_y (int) – The ending y value.

classmethod from_width_height_center(width, height, center)
property start_x: int

The starting x value.

property start_y: int

The starting y value.

property end_x: int

The ending x value.

property end_y: int

The ending y value.

property width

The width of the bounding box.

property height

The height of the bounding box.

property area

The area of the bounding box.

property center

The center of the bounding box.

property opencv_bbox

Converts bounding box to OpenCV’s cv2.rectangle() format.

compute_distance(other_box)

Compute the distance between the center of this and another bounding box.

Parameters:

other_box (BoundingBox) – The second bounding box for the distance computation.

Returns:

The Euclidean distance between bounding box centers.

get_intersection(other_box)

Get the intersection of this box and other_box represented as another bounding box.

Parameters:

other_box (BoundingBox) – The overlapping box.

Returns:

The bounding box representing the intersection of this box and other_box.

compute_overlap(other_box)

Compute the fraction of this box which is overlapped by other_box.

Parameters:

other_box (BoundingBox) – The overlapping box.

Returns:

A value [0.0, 1.0] indicating the fraction of this box that is overlapped by other_box.

compute_iou(other_box)

Compute the IOU between this and the other_box.

Parameters:

other_box (BoundingBox) – The other box to use for IOU computation.

Returns:

A value [0.0, 1.0] indicating the IOU between this and the other_box.

scale_about_center(scale_x=1.0, scale_y=1.0)

Scale the bounding box along the x and y axes about the center of the bounding box.

Parameters:
  • scale_x (float) – scaling factor along the x axis

  • scale_y (float) – scaling factor along the y axis

scale_with_image(scale_x=1.0, scale_y=1.0)

Scale the bounding box/boxes along with the image. This is useful to draw scaled bounding boxes on scaled images. The scaling factors are computed as a ratio of resized image dimensions to the prior image dimensions.

For ex: scale_x = new image width / old image width

Parameters:
  • scale_x (float) – scaling factor along the x axis

  • scale_y (float) – scaling factor along the y axis

class BoundingBoxPrediction(box, confidence)

A single prediction result with a bounding box and confidence.

Parameters:
  • box (BoundingBox) – The bounding box around the detected object.

  • confidence (float) – The confidence of this prediction.

property box: BoundingBox

The bounding box around the object.

property confidence: float

The confidence of this prediction.