This project is a AI based fitness training. Recently lot of people facing many health issues due to the lack of physical activity. Not getting enough physical activity can lead to heart disease, even for people who have no other risk factors. It can also increase the likelihood of developing other heart disease risk factors, including obesity, high blood pressure, high blood cholesterol.
In the pandemic social distancing is the big factor, so many workout center are closed. So peoples doing training at home. But there is no a trainer. In the absence of trainer workouts may lead to serious problems.
This project is help you a as trainer at home.It gives the message have doing workout properly and gives how many times you have done your workout.
Software OverviewThe software is running on the computer and its written in python.
The main library is opencv and mediapipe.
Step1: Installing Libraries
First of all we are installing the latest version of python on your system.
1.Go to the python website
2.Select the latest version version of python
3.Download the executable installer
4.Run the executable installer
5.Verify python was installed in your system
6. Verify PIP installed in your system
you can check in terminal by
pip
pip --version
Install numpy
pip install numpy
Next we are going to install the opencv
pip install opencv-python
you can check by
python
import cv2
print(cv2.__version__)
Next is Mediapipe
Download the file from Mediapipe official site and install
Step 2: Importing
Import the downloaded library by
import cv2
import mediapipe
Step 3: Landmarks
mpDraw = mp.solutions.drawing_utils
mPose = mp.solutions.pose
pose = mPose.Pose()
while True:
success, img = cap.read()
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = pose.process(imgRGB)
if results.pose_landmarks:
mpDraw.draw_landmarks(img, results.pose_landmarks, mPose.POSE_CONNECTIONS)
Step 4: Landmark positions
lmList = []
if results.pose_landmarks:
mpDraw.draw_landmarks(img, results.pose_landmarks, mPose.POSE_CONNECTIONS)
for id, lm in enumerate(results.pose_landmarks.landmark):
h, w, c = img.shape
cx, cy = int(lm.x*w), int(lm.y*h)
lmList.append([id, cx, cy])
we can use the points position from the list
print(lmList)
[[0, 278, 335], [1, 287, 306], [2, 299, 306], [3, 310, 305],...........,[32, 287, 1485]]
you can use this image as a point reference
to get the points
x1, y1 = lmList[p1][1:]
>>> 278, 335
Step 5: Angle measurement
By this method we can find the angle by math library
angle = math.degrees(math.atan2(y3-y1,x3-x2)-
math.atan2(y1-y2,x1-x2))
print(f'angle:{angle}')
Conclusion:
This project will help to improve the training or workout without any problem.
Comments