Joint Angles¶
A joint angle is measured at the joint point, between the rays that run to the start and end points.
supervision.key_points.angles.JointAngle
dataclass
¶
A named joint, given as three key point positions, whose angle is measured.
The angle is the interior angle at joint between the rays joint -> start
and joint -> end, between 0 and 180 degrees. For example, a left knee in the
COCO 17-keypoint layout is
JointAngle("left_knee", start=11, joint=13, end=15): hip, knee, ankle.
Note
start, joint and end are zero-based positions along the second
axis of :attr:~supervision.key_points.core.KeyPoints.xy. Skeleton edges in
:class:~supervision.key_points.skeletons.Skeleton use one-based indices
instead.
Note
The measured angle is the same whichever end point is start and which is
end. Only the side of the arc drawn by
:class:~supervision.key_points.annotators.JointAngleAnnotator for a joint
of exactly 180 degrees depends on that order.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
A label for the joint. It appears in error messages and lets callers
name the columns of the array returned by
:func: |
start |
int
|
Position of the first end point. |
joint |
int
|
Position of the joint, where the angle is measured. |
end |
int
|
Position of the second end point. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a position is not an integer. |
ValueError
|
If a position is negative or the three positions are not distinct. |
Example
>>> from supervision.key_points.angles import JointAngle
>>> JointAngle(name="left_knee", start=11, joint=13, end=15)
JointAngle(name='left_knee', start=11, joint=13, end=15)
Source code in src/supervision/key_points/angles.py
Methods:¶
__post_init__() -> None
¶
Reject positions that cannot define an angle.
Source code in src/supervision/key_points/angles.py
supervision.key_points.angles.joint_angles(key_points: KeyPoints, angles: Sequence[JointAngle]) -> npt.NDArray[np.float64]
¶
Compute joint angles in degrees for every skeleton.
Each angle is the interior angle at the joint of a
:class:~supervision.key_points.angles.JointAngle, measured in the image plane
from the x/y coordinates; an extra coordinate such as depth is ignored. These
are 2D image-plane angles, not anatomical 3D joint angles: when a limb is
foreshortened, for example a forearm pointing towards the camera, the two can
differ widely. The interior angle never exceeds 180 degrees, so a joint that
bends through straight reads the same angle on either side.
An angle is NaN when one of its three points cannot be used, so no value is
invented: a point is unusable when it is hidden by
:attr:~supervision.key_points.core.KeyPoints.visible, has a non-finite x/y
coordinate, or sits at [0, 0], the marker some models use for a missing
point. These are the rules
:meth:~supervision.key_points.core.KeyPoints.as_detections applies. The angle
is also NaN when an end point coincides with the joint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
KeyPoints
|
Key points of |
required |
|
Sequence[JointAngle]
|
The joints to measure. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
An array of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a joint refers to a position outside the |
Example
>>> import numpy as np
>>> import supervision as sv
>>> from supervision.key_points.angles import JointAngle
>>> key_points = sv.KeyPoints(
... xy=np.array(
... [
... [[100, 50], [100, 100], [150, 100]],
... [[0, 0], [100, 100], [150, 100]],
... ],
... dtype=np.float32,
... )
... )
>>> knee = JointAngle(name="knee", start=0, joint=1, end=2)
>>> sv.joint_angles(key_points, [knee])
array([[90.],
[nan]])
Source code in src/supervision/key_points/angles.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |