Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import cv2
import mediapipe as mp
import numpy as np
import time



# Initialize MediaPipe Pose
mp_pose = mp.solutions.pose
Expand Down Expand Up @@ -52,6 +55,11 @@ def analyze_side_posture(landmarks):
back_angle = calculate_angle(shoulder, hip, knee)

return neck_angle, back_angle


#calutating start time
starttime = time.time()


while cap.isOpened():
ret, frame = cap.read()
Expand All @@ -68,6 +76,10 @@ def analyze_side_posture(landmarks):
# Convert back to BGR for OpenCV
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

#finding current time
currenttime = time.time()
durationtime = currenttime - starttime

if results.pose_landmarks:
# Draw pose landmarks
mp_drawing.draw_landmarks(
Expand All @@ -78,12 +90,14 @@ def analyze_side_posture(landmarks):
# Analyze posture
landmarks = results.pose_landmarks.landmark
neck_angle, back_angle = analyze_side_posture(landmarks)

# Display angles
cv2.putText(image, f'Neck angle: {neck_angle:.1f}', (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
cv2.putText(image, f'Back angle: {back_angle:.1f}', (10, 60),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
cv2.putText(image, f"Duration: {durationtime:.2f} secs", (10, 90),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)

# Basic posture feedback
if 80 <= neck_angle <= 100:
Expand All @@ -96,9 +110,9 @@ def analyze_side_posture(landmarks):
else:
back_status = "Adjust back position"

cv2.putText(image, neck_status, (10, 90),
cv2.putText(image, neck_status, (10, 120),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.putText(image, back_status, (10, 120),
cv2.putText(image, back_status, (10, 150),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)

# Display the image
Expand Down