Class Rectangle

java.lang.Object
ai.djl.modality.cv.output.Rectangle
All Implemented Interfaces:
BoundingBox, BytesSupplier, ai.djl.util.JsonSerializable, Serializable
Direct Known Subclasses:
Landmark, Mask

public class Rectangle extends Object implements BoundingBox, ai.djl.util.JsonSerializable
A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's upper-left point Point in the coordinate space, its width, and its height.

The rectangle coordinates are usually from 0-1 and are ratios of the image size. For example, if you have an image width of 400 pixels and the rectangle starts at 100 pixels, you would use .25.

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface ai.djl.util.JsonSerializable

    ai.djl.util.JsonSerializable.Serializer
  • Constructor Summary

    Constructors
    Constructor
    Description
    Rectangle(double x, double y, double width, double height)
    Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.
    Rectangle(Point point, double width, double height)
    Constructs a new Rectangle whose upper-left corner is specified as coordinate point and whose width and height are specified by the arguments of the same name.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the bounding Rectangle of this BoundingBox.
    double[]
    Returns the upper left and bottom right coordinates.
    double
    Returns the height of the Rectangle.
    double
    Returns the Intersection over Union (IoU) value between bounding boxes.
    Returns an iterator object that iterates along the BoundingBox boundary and provides access to the geometry of the BoundingBox outline.
    Returns the top left point of the bounding box.
    double
    Returns the width of the Rectangle.
    double
    Returns the left x-coordinate of the Rectangle.
    double
    Returns the top y-coordinate of the Rectangle.
    static List<Integer>
    nms(List<Rectangle> boxes, List<Double> scores, float nmsThreshold)
    Applies nms (non-maximum suppression) to the list of rectangles.
    com.google.gson.JsonObject

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface ai.djl.ndarray.BytesSupplier

    getAsBytes, getAsObject

    Methods inherited from interface ai.djl.util.JsonSerializable

    getAsString, toByteBuffer, toJson
  • Constructor Details

    • Rectangle

      public Rectangle(double x, double y, double width, double height)
      Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.
      Parameters:
      x - the specified X coordinate (0-1)
      y - the specified Y coordinate (0-1)
      width - the width of the Rectangle (0-1)
      height - the height of the Rectangle (0-1)
    • Rectangle

      public Rectangle(Point point, double width, double height)
      Constructs a new Rectangle whose upper-left corner is specified as coordinate point and whose width and height are specified by the arguments of the same name.
      Parameters:
      point - the upper-left corner of the coordinate (0-1)
      width - the width of the Rectangle (0-1)
      height - the height of the Rectangle (0-1)
  • Method Details

    • getBounds

      public Rectangle getBounds()
      Returns the bounding Rectangle of this BoundingBox.
      Specified by:
      getBounds in interface BoundingBox
      Returns:
      a new Rectangle for this BoundingBox
    • getPath

      public Iterable<Point> getPath()
      Returns an iterator object that iterates along the BoundingBox boundary and provides access to the geometry of the BoundingBox outline.
      Specified by:
      getPath in interface BoundingBox
      Returns:
      a Iterable object, which independently traverses the geometry of the BoundingBox
    • getPoint

      public Point getPoint()
      Returns the top left point of the bounding box.
      Specified by:
      getPoint in interface BoundingBox
      Returns:
      the Point of the top left corner
    • getIoU

      public double getIoU(BoundingBox box)
      Returns the Intersection over Union (IoU) value between bounding boxes.

      Also known as Jaccard index

      Specified by:
      getIoU in interface BoundingBox
      Parameters:
      box - the bounding box to calculate
      Returns:
      the IoU value
    • getX

      public double getX()
      Returns the left x-coordinate of the Rectangle.
      Returns:
      the left x-coordinate of the Rectangle (0-1)
    • getY

      public double getY()
      Returns the top y-coordinate of the Rectangle.
      Returns:
      the top y-coordinate of the Rectangle (0-1)
    • getWidth

      public double getWidth()
      Returns the width of the Rectangle.
      Returns:
      the width of the Rectangle (0-1)
    • getHeight

      public double getHeight()
      Returns the height of the Rectangle.
      Returns:
      the height of the Rectangle (0-1)
    • getCoordinates

      public double[] getCoordinates()
      Returns the upper left and bottom right coordinates.
      Returns:
      the upper left and bottom right coordinates
    • serialize

      public com.google.gson.JsonObject serialize()
      Specified by:
      serialize in interface ai.djl.util.JsonSerializable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • nms

      public static List<Integer> nms(List<Rectangle> boxes, List<Double> scores, float nmsThreshold)
      Applies nms (non-maximum suppression) to the list of rectangles.
      Parameters:
      boxes - an list of Rectangle
      scores - a list of scores
      nmsThreshold - the nms threshold
      Returns:
      the filtered list with the index of the original list