Coretex
coretex.coretex.annotation.image.bbox.BBox Class Reference
Inheritance diagram for coretex.coretex.annotation.image.bbox.BBox:
coretex.codable.codable.Codable

Public Member Functions

float maxX (self)
 
float maxY (self)
 
List[float] polygon (self)
 
Self create (cls, float minX, float minY, float maxX, float maxY)
 
Self fromPoly (cls, List[float] polygon)
 
- Public Member Functions inherited from coretex.codable.codable.Codable
Dict[str, Any] encode (self)
 
None onDecode (self)
 
Self decode (cls, Dict[str, Any] encodedObject)
 

Detailed Description

    Bounding Box as a python class with utility methods

    Properties
    ----------
    minX : float
        top left x coordinate
    minY : float
        top left y coordinate
    width : float
        width of the bounding box
    height : float
        height of the bounding box

Definition at line 24 of file bbox.py.

Member Function Documentation

◆ create()

Self coretex.coretex.annotation.image.bbox.BBox.create (   cls,
float  minX,
float  minY,
float  maxX,
float  maxY 
)
    Utility constructor which has maxX and maxY as parameters instead
    of width and height

    Parameters
    ----------
    minX : float
top left x coordinate
    minY : float
top left y coordinate
    maxX : float
bottom right x coordinate
    maxY : float
bottom right y coordinate

    Returns
    -------
    Self -> bounding box

Definition at line 94 of file bbox.py.

94  def create(cls, minX: float, minY: float, maxX: float, maxY: float) -> Self:
95  """
96  Utility constructor which has maxX and maxY as parameters instead
97  of width and height
98 
99  Parameters
100  ----------
101  minX : float
102  top left x coordinate
103  minY : float
104  top left y coordinate
105  maxX : float
106  bottom right x coordinate
107  maxY : float
108  bottom right y coordinate
109 
110  Returns
111  -------
112  Self -> bounding box
113  """
114 
115  return cls(minX, minY, maxX - minX, maxY - minY)
116 

◆ fromPoly()

Self coretex.coretex.annotation.image.bbox.BBox.fromPoly (   cls,
List[float]  polygon 
)
    Creates bounding box from a polygon, by finding
    the minimum x and y coordinates and calculating
    width and height of the polygon

    Parameters
    ----------
    polygon : List[float]
list of x, y points - length must be even

    Returns
    -------
    Self -> bounding box

    Example
    -------
    >>> from coretex import Bbox
    \b
    >>> polygon = [0, 0, 0, 3, 4, 3, 4, 0]
    >>> bbox = Bbox.fromPoly(polygon)
    >>> print(f"minX: {bbox.minX}, minY: {bbox.minY}, width: {bbox.width}, height: {bbox.height}")
    "minX: 0, minY: 0, width: 4, height: 3"

Definition at line 118 of file bbox.py.

118  def fromPoly(cls, polygon: List[float]) -> Self:
119  """
120  Creates bounding box from a polygon, by finding
121  the minimum x and y coordinates and calculating
122  width and height of the polygon
123 
124  Parameters
125  ----------
126  polygon : List[float]
127  list of x, y points - length must be even
128 
129  Returns
130  -------
131  Self -> bounding box
132 
133  Example
134  -------
135  >>> from coretex import Bbox
136  \b
137  >>> polygon = [0, 0, 0, 3, 4, 3, 4, 0]
138  >>> bbox = Bbox.fromPoly(polygon)
139  >>> print(f"minX: {bbox.minX}, minY: {bbox.minY}, width: {bbox.width}, height: {bbox.height}")
140  "minX: 0, minY: 0, width: 4, height: 3"
141  """
142 
143  x: List[float] = []
144  y: List[float] = []
145 
146  for index, value in enumerate(polygon):
147  if index % 2 == 0:
148  x.append(value)
149  else:
150  y.append(value)
151 
152  return cls.create(min(x), min(y), max(x), max(y))

◆ maxX()

float coretex.coretex.annotation.image.bbox.BBox.maxX (   self)
    Returns
    -------
    float -> bottom right x coordinate

Definition at line 49 of file bbox.py.

49  def maxX(self) -> float:
50  """
51  Returns
52  -------
53  float -> bottom right x coordinate
54  """
55 
56  return self.minX + self.width
57 

◆ maxY()

float coretex.coretex.annotation.image.bbox.BBox.maxY (   self)
    Returns
    -------
    float -> bottom right y coordinate

Definition at line 59 of file bbox.py.

59  def maxY(self) -> float:
60  """
61  Returns
62  -------
63  float -> bottom right y coordinate
64  """
65 
66  return self.minY + self.height
67 

◆ polygon()

List[float] coretex.coretex.annotation.image.bbox.BBox.polygon (   self)
    Returns
    -------
    List[float] -> Bounding box represented as a polygon (x, y) values

Definition at line 69 of file bbox.py.

69  def polygon(self) -> List[float]:
70  """
71  Returns
72  -------
73  List[float] -> Bounding box represented as a polygon (x, y) values
74  """
75 
76  return [
77  self.minX, self.minY, # top left
78  self.maxX, self.minY, # top right
79  self.maxX, self.maxY, # bottom right
80  self.minX, self.maxY, # bottom left
81  self.minX, self.minY # top left
82  ]
83 

The documentation for this class was generated from the following file: