Module compoelem.types

Expand source code
from dataclasses import dataclass
from typing import Sequence, Tuple
import numpy as np

from shapely.geometry import LineString, Point, Polygon

from .detect.openpose_common_utils import CocoPart

Img = Sequence[Sequence[int]]

class Keypoint:
    x: int
    y: int
    score: float
    isNone: bool
    def __init__(self, x: int, y: int, score: float = 0):
        self.x = int(x)
        self.y = int(y)
        self.score = score
        self.isNone = False
    def __str__(self) -> str:
        return "Kp ({},{})".format(self.x, self.y)
    def __repr__(self) -> str:
        return "Kp ({},{})".format(self.x, self.y)

class NoneKeypoint(Keypoint):
    x: int
    y: int
    isNone: bool
    score: int
    def __init__(self):
        self.x = -1
        self.y = -1
        self.score = 0
        self.isNone = True
    def __str__(self) -> str:
        return "N Kp"
    def __repr__(self) -> str:
        return "N Kp"

@dataclass
class Pose:
    keypoints: Sequence[Keypoint]

Poses = Sequence[Pose]

class PoseTriangle:
    shape: Polygon
    top: Keypoint
    left: Keypoint
    right: Keypoint
    def __init__(self, top: Keypoint, left: Keypoint, right: Keypoint): 
        self.top = top
        self.left = left
        self.right = right
        self.shape = Polygon([[top.x, top.y], [left.x, left.y], [right.x, right.y]])

class PoseLine:
    line: LineString
    top: Point
    bottom: Point
    def __init__(self, top:Point, bottom: Point): 
        self.top = top
        self.bottom = bottom
        self.line = LineString([[top.x, top.y], [bottom.x, bottom.y]])

ConeCombination = Tuple[int, ...]

class ConeIntersection:
    shape: Polygon
    cone_combination: ConeCombination
    cone_combination_length: int
    def __init__(self, shape: Polygon, cone_combination: ConeCombination): 
        self.shape = shape
        self.cone_combination = cone_combination
        self.cone_combination_length = len(cone_combination)

class GlobalActionLine:
    line: LineString
    start: Point
    end: Point
    center: Point
    area: float
    angle: float
    intersection_shape: Polygon
    def __init__(self, center: Point, angle: float, area: float, intersection_shape: Polygon = None):
        self.angle = angle
        self.area = area
        self.center = center
        if intersection_shape:
            self.intersection_shape = intersection_shape
        else:
            self.intersection_shape = Polygon()

        dist = 2000 # FIXME: move hardcoded value to config, or maybe calculate dist based on area
        if np.isnan(angle):
            x_offset = 0
            y_offset = 0
            #print("Warning: GlobalActionLine angle is NaN")
        else:
            x_offset = int(dist * np.cos(angle))
            y_offset = int(dist * np.sin(angle))
        self.start = Point(center.x - x_offset, center.y - y_offset)
        self.end = Point(center.x + x_offset, center.y + y_offset)


class PoseDirection:
    line: LineString
    start: Point
    end: Point
    cone: Polygon
    def __init__(self, start:Point, end: Point, cone: Polygon): 
        self.start = start
        self.end = end
        self.line = LineString([[start.x, start.y], [end.x, end.y]])
        self.cone = cone

Classes

class ConeIntersection (shape: shapely.geometry.polygon.Polygon, cone_combination: Tuple[int, ...])
Expand source code
class ConeIntersection:
    shape: Polygon
    cone_combination: ConeCombination
    cone_combination_length: int
    def __init__(self, shape: Polygon, cone_combination: ConeCombination): 
        self.shape = shape
        self.cone_combination = cone_combination
        self.cone_combination_length = len(cone_combination)

Class variables

var cone_combination : Tuple[int, ...]
var cone_combination_length : int
var shape : shapely.geometry.polygon.Polygon
class GlobalActionLine (center: shapely.geometry.point.Point, angle: float, area: float, intersection_shape: shapely.geometry.polygon.Polygon = None)
Expand source code
class GlobalActionLine:
    line: LineString
    start: Point
    end: Point
    center: Point
    area: float
    angle: float
    intersection_shape: Polygon
    def __init__(self, center: Point, angle: float, area: float, intersection_shape: Polygon = None):
        self.angle = angle
        self.area = area
        self.center = center
        if intersection_shape:
            self.intersection_shape = intersection_shape
        else:
            self.intersection_shape = Polygon()

        dist = 2000 # FIXME: move hardcoded value to config, or maybe calculate dist based on area
        if np.isnan(angle):
            x_offset = 0
            y_offset = 0
            #print("Warning: GlobalActionLine angle is NaN")
        else:
            x_offset = int(dist * np.cos(angle))
            y_offset = int(dist * np.sin(angle))
        self.start = Point(center.x - x_offset, center.y - y_offset)
        self.end = Point(center.x + x_offset, center.y + y_offset)

Class variables

var angle : float
var area : float
var center : shapely.geometry.point.Point
var end : shapely.geometry.point.Point
var intersection_shape : shapely.geometry.polygon.Polygon
var line : shapely.geometry.linestring.LineString
var start : shapely.geometry.point.Point
class Keypoint (x: int, y: int, score: float = 0)
Expand source code
class Keypoint:
    x: int
    y: int
    score: float
    isNone: bool
    def __init__(self, x: int, y: int, score: float = 0):
        self.x = int(x)
        self.y = int(y)
        self.score = score
        self.isNone = False
    def __str__(self) -> str:
        return "Kp ({},{})".format(self.x, self.y)
    def __repr__(self) -> str:
        return "Kp ({},{})".format(self.x, self.y)

Subclasses

Class variables

var isNone : bool
var score : float
var x : int
var y : int
class NoneKeypoint
Expand source code
class NoneKeypoint(Keypoint):
    x: int
    y: int
    isNone: bool
    score: int
    def __init__(self):
        self.x = -1
        self.y = -1
        self.score = 0
        self.isNone = True
    def __str__(self) -> str:
        return "N Kp"
    def __repr__(self) -> str:
        return "N Kp"

Ancestors

Class variables

var isNone : bool
var score : int
var x : int
var y : int
class Pose (keypoints: Sequence[Keypoint])

Pose(keypoints: Sequence[compoelem.types.Keypoint])

Expand source code
class Pose:
    keypoints: Sequence[Keypoint]

Class variables

var keypoints : Sequence[Keypoint]
class PoseDirection (start: shapely.geometry.point.Point, end: shapely.geometry.point.Point, cone: shapely.geometry.polygon.Polygon)
Expand source code
class PoseDirection:
    line: LineString
    start: Point
    end: Point
    cone: Polygon
    def __init__(self, start:Point, end: Point, cone: Polygon): 
        self.start = start
        self.end = end
        self.line = LineString([[start.x, start.y], [end.x, end.y]])
        self.cone = cone

Class variables

var cone : shapely.geometry.polygon.Polygon
var end : shapely.geometry.point.Point
var line : shapely.geometry.linestring.LineString
var start : shapely.geometry.point.Point
class PoseLine (top: shapely.geometry.point.Point, bottom: shapely.geometry.point.Point)
Expand source code
class PoseLine:
    line: LineString
    top: Point
    bottom: Point
    def __init__(self, top:Point, bottom: Point): 
        self.top = top
        self.bottom = bottom
        self.line = LineString([[top.x, top.y], [bottom.x, bottom.y]])

Class variables

var bottom : shapely.geometry.point.Point
var line : shapely.geometry.linestring.LineString
var top : shapely.geometry.point.Point
class PoseTriangle (top: Keypoint, left: Keypoint, right: Keypoint)
Expand source code
class PoseTriangle:
    shape: Polygon
    top: Keypoint
    left: Keypoint
    right: Keypoint
    def __init__(self, top: Keypoint, left: Keypoint, right: Keypoint): 
        self.top = top
        self.left = left
        self.right = right
        self.shape = Polygon([[top.x, top.y], [left.x, left.y], [right.x, right.y]])

Class variables

var leftKeypoint
var rightKeypoint
var shape : shapely.geometry.polygon.Polygon
var topKeypoint