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
AIGym(**kwargs)
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 |
---|---|---|
states |
Dict[float, int, str]
|
Stores per-track angle, count, and stage for workout monitoring. |
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. |
Methods:
Name | Description |
---|---|
process |
Processes a frame to detect poses, calculate angles, and count repetitions. |
Examples:
>>> gym = AIGym(model="yolo11n-pose.pt")
>>> image = cv2.imread("gym_scene.jpg")
>>> results = gym.process(image)
>>> processed_image = results.plot_im
>>> cv2.imshow("Processed Image", processed_image)
>>> cv2.waitKey(0)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Keyword arguments passed to the parent class constructor. model (str): Model name or path, defaults to "yolo11n-pose.pt". |
{}
|
Source code in ultralytics/solutions/ai_gym.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
process
process(im0)
Monitor 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 |
---|---|
SolutionResults
|
Contains processed image |
Examples:
>>> gym = AIGym()
>>> image = cv2.imread("workout.jpg")
>>> results = gym.process(image)
>>> processed_image = results.plot_im
Source code in ultralytics/solutions/ai_gym.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 |
|