-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathdetection_in_world.py
66 lines (53 loc) · 1.65 KB
/
detection_in_world.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Object detection in world space.
"""
import numpy as np
class DetectionInWorld:
"""
Typically on the ground.
"""
__create_key = object()
@classmethod
def create(
cls, vertices: np.ndarray, centre: np.ndarray, label: int, confidence: float
) -> "tuple[bool, DetectionInWorld | None]":
"""
vertices is a quadrilateral of 4 points.
centre is a point.
A point is an xy coordinate (index 0 and 1 respectively).
"""
if vertices.shape != (4, 2):
return False, None
if centre.shape != (2,):
return False, None
if label < 0:
return False, None
if confidence < 0.0 or confidence > 1.0:
return False, None
return True, DetectionInWorld(cls.__create_key, vertices, centre, label, confidence)
def __init__(
self,
class_private_create_key: object,
vertices: np.ndarray,
centre: np.ndarray,
label: int,
confidence: float,
) -> None:
"""
Private constructor, use create() method.
"""
assert class_private_create_key is DetectionInWorld.__create_key, "Use create() method"
self.vertices = vertices
self.centre = centre
self.label = label
self.confidence = confidence
def __str__(self) -> str:
"""
To string.
"""
return f"{self.__class__}, vertices: {self.vertices.tolist()}, centre: {self.centre}, label: {self.label}, confidence: {self.confidence}"
def __repr__(self) -> str:
"""
For collections (e.g. list).
"""
return str(self)