API Reference¶
Everything you can import from detectors_world.
create_detector
¶
create_detector(kind: str, **options: Any) -> Detector
Create a detector by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
|
required |
**options
|
Any
|
Passed to the detector class, for example |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Hand
¶
Hand(*, max_hands: int = 2, detection_confidence: float = 0.5, tracking_confidence: float = 0.5, static_image: bool = False, model_path: PathLike | None = None)
Bases: _LandmarkDetector
Finds hands and their 21 landmarks (wrist, knuckles and fingertips).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_hands
|
int
|
Largest number of hands to look for. |
2
|
detection_confidence
|
float
|
Minimum confidence (0.0 to 1.0) to report a new hand. |
0.5
|
tracking_confidence
|
float
|
Minimum confidence (0.0 to 1.0) to keep tracking a hand between frames. |
0.5
|
static_image
|
bool
|
|
False
|
model_path
|
PathLike | None
|
Use a local |
None
|
detect
¶
detect(frame: ndarray, *, draw: bool = True, color: Color = (224, 224, 224), point_color: Color = (0, 0, 255)) -> list[Landmarks]
Find hands in frame and optionally draw them on it.
Returns:
| Type | Description |
|---|---|
list[Landmarks]
|
One |
list[Landmarks]
|
An empty list when no hand is visible. Labels name the person's own hands, |
list[Landmarks]
|
and MediaPipe swaps them on a mirrored frame such as |
locate
¶
locate(frame: ndarray, *, hand: int = 0, draw: bool = True, color: Color = (0, 255, 0), radius: int = 6) -> list[list[int]]
Pixel positions of one hand's landmarks from the latest detect() call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
ndarray
|
The image to draw on. |
required |
hand
|
int
|
Which hand to return, starting at 0. |
0
|
draw
|
bool
|
Draw a dot on each landmark. |
True
|
color
|
Color
|
Dot color in BGR. |
(0, 255, 0)
|
radius
|
int
|
Dot radius in pixels. |
6
|
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
|
Pose
¶
Pose(*, model: str = 'full', max_poses: int = 1, detection_confidence: float = 0.5, tracking_confidence: float = 0.5, static_image: bool = False, model_path: PathLike | None = None)
Bases: _LandmarkDetector
Finds a body and its 33 landmarks (face, shoulders, arms, hips, legs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
|
'full'
|
max_poses
|
int
|
Largest number of people to look for. |
1
|
detection_confidence
|
float
|
Minimum confidence (0.0 to 1.0) to report a new body. |
0.5
|
tracking_confidence
|
float
|
Minimum confidence (0.0 to 1.0) to keep tracking a body between frames. |
0.5
|
static_image
|
bool
|
|
False
|
model_path
|
PathLike | None
|
Use a local |
None
|
detect
¶
detect(frame: ndarray, *, draw: bool = True, color: Color = (224, 224, 224), point_color: Color = (0, 0, 255)) -> list[Landmarks]
Find bodies in frame and optionally draw them on it.
Returns:
| Type | Description |
|---|---|
list[Landmarks]
|
One |
locate
¶
locate(frame: ndarray, *, pose: int = 0, draw: bool = True, color: Color = (0, 255, 0), radius: int = 6) -> list[list[int]]
Pixel positions of one body's landmarks from the latest detect() call.
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
|
Face
¶
Face(*, detection_confidence: float = 0.6, static_image: bool = False, model_path: PathLike | None = None)
Bases: Detector
Finds faces and returns a box around each one (faces within about 2 m of the camera).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detection_confidence
|
float
|
Minimum confidence (0.0 to 1.0) to report a face. |
0.6
|
static_image
|
bool
|
|
False
|
model_path
|
PathLike | None
|
Use a local |
None
|
detect
¶
detect(frame: ndarray, *, draw: bool = True, color: Color = (0, 255, 0)) -> list[FaceBox]
Find faces in frame and optionally draw a box and key points on each.
Returns:
| Type | Description |
|---|---|
list[FaceBox]
|
One |
locate
¶
locate(frame: ndarray, *, draw: bool = True, color: Color = (0, 255, 0)) -> list[list[Any]]
Face boxes from the latest detect() call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
ndarray
|
The image to draw on. |
required |
draw
|
bool
|
Draw a framed box and the confidence percentage on each face. |
True
|
color
|
Color
|
Drawing color in BGR. |
(0, 255, 0)
|
Returns:
| Type | Description |
|---|---|
list[list[Any]]
|
|
FaceMesh
¶
FaceMesh(*, max_faces: int = 2, detection_confidence: float = 0.5, tracking_confidence: float = 0.5, static_image: bool = False, model_path: PathLike | None = None)
Bases: _LandmarkDetector
Finds faces and their 478 mesh landmarks (including the irises).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_faces
|
int
|
Largest number of faces to look for. |
2
|
detection_confidence
|
float
|
Minimum confidence (0.0 to 1.0) to report a new face. |
0.5
|
tracking_confidence
|
float
|
Minimum confidence (0.0 to 1.0) to keep tracking a face between frames. |
0.5
|
static_image
|
bool
|
|
False
|
model_path
|
PathLike | None
|
Use a local |
None
|
detect
¶
detect(frame: ndarray, *, draw: bool = True, color: Color = (224, 224, 224), thickness: int = 1, radius: int = 2) -> list[Landmarks]
Find faces in frame and optionally draw the mesh on them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
ndarray
|
A BGR image from OpenCV. |
required |
draw
|
bool
|
Draw a ring on each landmark and the face outlines (eyes, brows, lips, face oval). |
True
|
color
|
Color
|
Drawing color in BGR. |
(224, 224, 224)
|
thickness
|
int
|
Line thickness in pixels. |
1
|
radius
|
int
|
Landmark ring radius in pixels. |
2
|
Returns:
| Type | Description |
|---|---|
list[Landmarks]
|
One |
locate
¶
locate(frame: ndarray, *, face: int = 0, draw: bool = False, show_ids: bool = False, color: Color = (0, 255, 0), radius: int = 1) -> list[list[int]]
Pixel positions of one face's landmarks from the latest detect() call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
ndarray
|
The image to draw on. |
required |
face
|
int
|
Which face to return, starting at 0. |
0
|
draw
|
bool
|
Draw a dot on each landmark. |
False
|
show_ids
|
bool
|
Write each landmark's number next to it, to find the ids you need. |
False
|
color
|
Color
|
Dot and text color in BGR. |
(0, 255, 0)
|
radius
|
int
|
Dot radius in pixels. |
1
|
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
|
Detector
¶
Detector(model: bytes, static_image: bool)
Bases: ABC
Base class for all detectors.
Detectors hold a loaded model. Use them as a context manager, or call
close() when you are done, to release it.
Landmarks
dataclass
¶
Landmarks(points: tuple[tuple[int, int], ...], normalized: tuple[tuple[float, float, float], ...], label: str | None = None, score: float | None = None)
Landmarks of one detected hand, body, or face mesh.
Attributes:
| Name | Type | Description |
|---|---|---|
points |
tuple[tuple[int, int], ...]
|
|
normalized |
tuple[tuple[float, float, float], ...]
|
|
label |
str | None
|
|
score |
float | None
|
Confidence of |
FaceBox
dataclass
¶
FaceBox(x: int, y: int, width: int, height: int, score: float, keypoints: tuple[tuple[int, int], ...] = ())
One detected face.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
int
|
Left edge in pixels. |
y |
int
|
Top edge in pixels. |
width |
int
|
Box width in pixels. |
height |
int
|
Box height in pixels. |
score |
float
|
Detection confidence, from 0.0 to 1.0. |
keypoints |
tuple[tuple[int, int], ...]
|
|
cache_dir
¶
cache_dir() -> Path
Folder where downloaded model files are kept.
Set the DETECTORS_WORLD_CACHE environment variable to use another folder.
DetectorCreator
¶
DetectorCreator()
Deprecated: use create_detector instead. Kept so 0.x code keeps running.