Geometric utils¶
Module contains geometric structures (Rect, Point, Size)
-
lunavl.sdk.image_utils.geometry.
COORDINATE_TYPE
= ~COORDINATE_TYPE¶ generic type for allowed values type of coordinates
-
lunavl.sdk.image_utils.geometry.
LANDMARKS
= ~LANDMARKS¶ generic type for allowed values type of landmarks
-
class
lunavl.sdk.image_utils.geometry.
Landmarks
(coreLandmarks)[source]¶ Base class for landmarks
-
class
lunavl.sdk.image_utils.geometry.
Point
(x, y)[source]¶ Point.
-
x
¶ x-coordinate
- Type
CoordinateType
-
y
¶ y-coordinate
- Type
CoordinateType
-
asDict
()[source]¶ Convert point to list
- Returns
[self.x, self.y]
>>> Point(1, 2).asDict() [1, 2] >>> Point(1.0, 2.0).asDict() [1.0, 2.0]
- Return type
List
[~COORDINATE_TYPE]
-
classmethod
fromVector2
(vec2)[source]¶ Create Point from Core Vector2i and Vector2f
- Parameters
vec2 – vector2i or vector2f
- Returns
point
- Return type
Point
[~COORDINATE_TYPE]
-
toVector2
()[source]¶ Create Vector2i or Vector2f from point
- Returns
Vector2i if x and y are integer otherwise Vector2f
>>> vec2 = Point(1, 2).toVector2() >>> isinstance(vec2, Vector2i) True >>> vec2 = Point(1.0, 2.0).toVector2() >>> isinstance(vec2, Vector2f) True
- Return type
Union
[Vector2i
,Vector2f
]
-
-
class
lunavl.sdk.image_utils.geometry.
Rect
(x=0, y=0, width=0, height=0)[source]¶ -
coreRect
¶ core rect object
- Type
CoreRect
-
adjust
(dx, dy, dw, dh)[source]¶ Adjusts the rect by given amounts.
- Parameters
dx – adjustment for upper left corner x coordinate
dy – adjustment for upper left corner y coordinate
dw – adjustment for width
dh – adjustment for height
- Return type
None
-
adjusted
(dx, dy, dw, dh)[source]¶ Copies and adjusts the rect by given amounts.
- Parameters
dx – adjustment for upper left corner x coordinate
dy – adjustment for upper left corner y coordinate
dw – adjustment for width
dh – adjustment for height
- Returns
return copy.
- Return type
Rect
[~COORDINATE_TYPE]
-
asDict
()[source]¶ Convert rect to dict
- Returns
self.x, “y”: self.y, “width”: self.width, “height”: self.height}
- Return type
{“x”
>>> Rect(1, 2, 3, 4).asDict() {'x': 1, 'y': 2, 'width': 3, 'height': 4} >>> Rect(1.0, 2, 3.0, 4.0).asDict() {'x': 1.0, 'y': 2.0, 'width': 3.0, 'height': 4.0}
- Return type
dict
-
bottom
¶ Get lower y-coordinate of the rect
- Returns
self.y + self.width
>>> Rect(1, 2, 3, 4).bottom 6
- Return type
~COORDINATE_TYPE
-
bottomRight
¶ Get coordinates of the right bottom angle
- Returns
point
>>> Rect(1, 2, 3, 4).bottomRight x = 4, y = 6
- Return type
Point
[~COORDINATE_TYPE]
-
center
¶ Get coordinates of the center
- Returns
point
>>> Rect(1, 2, 3, 4).center x = 2, y = 4 >>> Rect(1, 2, 3, 5).center x = 2, y = 4 >>> Rect(1, 2, 4, 4).center x = 3, y = 4 >>> Rect(1.0, 2.0, 4.0, 5.0).center x = 3.0, y = 4.5
- Return type
Point
[~COORDINATE_TYPE]
-
classmethod
fromCoreRect
(rect)[source]¶ Load rect from core rect
- Parameters
rect – core rect
- Returns
new rect
- Return type
Rect
[~COORDINATE_TYPE]
-
getArea
()[source]¶ Get rect area
- Returns
self.width * self.height
>>> Rect(1, 2, 3, 4).getArea() 12 >>> Rect(1.0, 2.0, 3.5, 4.5).getArea() 15.75
- Return type
~COORDINATE_TYPE
-
height
¶ Getter of height
- Returns
self._rect.height
- Return type
~COORDINATE_TYPE
-
classmethod
initByCorners
(topLeftCorner, bottomRightBottom)[source]¶ Init rect by top left corner, bottom right bottom
- Parameters
topLeftCorner – top left corner
bottomRightBottom – bottom right bottom
- Returns
new rect
- Return type
Rect
[~COORDINATE_TYPE]
-
isInside
(other)[source]¶ Check other rect is inside in this or not
- Parameters
other – other rect
- Returns
true if this inside of the ‘other’
>>> first = Rect(1, 2, 3, 4) >>> second = Rect(1, 2, 3, 3) >>> first.isInside(second) False >>> second.isInside(first) True
- Return type
bool
-
isValid
()[source]¶ Validate width and height of the rect
- Returns
True if width and height > 0 otherwise False
>>> Rect(1, 2, 3, 4).isValid() True >>> Rect(1, 2, -3, 3).isValid() False
- Return type
bool
-
left
¶ Get lower x-coordinate of the rect
- Returns
self.x
>>> Rect(1, 2, 3, 4).left 1
>>> Rect(1, 2, -3, 4).left 1
- Return type
~COORDINATE_TYPE
-
right
¶ Get upper x-coordinate of the rect
- Returns
self.x
>>> Rect(1, 2, 3, 4).right 4
>>> Rect(1, 2, -3, 4).right -2
- Return type
~COORDINATE_TYPE
-
size
¶ Get rect size
- Returns
size
>>> Rect(1, 2, 3, 4).size width = 3, height = 4
- Return type
Size
[~COORDINATE_TYPE]
-
top
¶ Get upper y-coordinate of the rect
- Returns
self.y
>>> Rect(1, 2, 3, 4).top 2
>>> Rect(1, 2, 3, -4).top 2
- Return type
~COORDINATE_TYPE
-
topLeft
¶ Get coordinates of the top left angle
- Returns
point
>>> Rect(1, 2, 3, 4).topLeft x = 1, y = 2
- Return type
Point
[~COORDINATE_TYPE]
-
width
¶ Getter of width
- Returns
self._rect.width
- Return type
~COORDINATE_TYPE
-
x
¶ Getter of x coordinate
- Returns
self._rect.x
- Return type
~COORDINATE_TYPE
-
y
¶ Getter of y coordinate
- Returns
self._rect.y
- Return type
~COORDINATE_TYPE
-