Reference for ultralytics/solutions/ai_gym.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/ai_gym.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.ai_gym.AIGym
Bases: BaseSolution
A class to manage gym steps of people in a real-time video stream based on their poses.
This class extends BaseSolution to monitor workouts using YOLO pose estimation models. It tracks and counts repetitions of exercises based on predefined angle thresholds for up and down positions.
Attributes:
Name | Type | Description |
---|---|---|
count | List[int] | Repetition counts for each detected person. |
angle | List[float] | Current angle of the tracked body part for each person. |
stage | List[str] | Current exercise stage ('up', 'down', or '-') for each person. |
initial_stage | str | None | Initial stage of the exercise. |
up_angle | float | Angle threshold for considering the 'up' position of an exercise. |
down_angle | float | Angle threshold for considering the 'down' position of an exercise. |
kpts | List[int] | Indices of keypoints used for angle calculation. |
annotator | Annotator | Object for drawing annotations on the image. |
Methods:
Name | Description |
---|---|
monitor | Processes a frame to detect poses, calculate angles, and count repetitions. |
Examples:
>>> gym = AIGym(model="yolov8n-pose.pt")
>>> image = cv2.imread("gym_scene.jpg")
>>> processed_image = gym.monitor(image)
>>> cv2.imshow("Processed Image", processed_image)
>>> cv2.waitKey(0)
Source code in ultralytics/solutions/ai_gym.py
monitor
Monitors workouts using Ultralytics YOLO Pose Model.
This function processes an input image to track and analyze human poses for workout monitoring. It uses the YOLO Pose model to detect keypoints, estimate angles, and count repetitions based on predefined angle thresholds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im0 | ndarray | Input image for processing. | required |
Returns:
Type | Description |
---|---|
ndarray | Processed image with annotations for workout monitoring. |
Examples: