Skip to content
Open
Show file tree
Hide file tree
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
165 changes: 165 additions & 0 deletions PRANA/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
mediapipe_env
*.log

# Ignore node_modules folder
node_modules/

# Ignore all .env files (environment variables)
.env

# Ignore a specific file
secret_config.json
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST


# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
sample_venv/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
169 changes: 169 additions & 0 deletions PRANA/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
from flask import Flask, render_template, Response, request
import cv2
import mediapipe as mp
import numpy as np # For angle calculations


app = Flask(__name__)

mp_pose = mp.solutions.pose
pose = mp_pose.Pose(static_image_mode=False, min_detection_confidence=0.6, model_complexity=1)
mp_drawing = mp.solutions.drawing_utils


def detectPose(image, pose, display=False):
output_image = image.copy()
imageRGB = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = pose.process(imageRGB)
height, width, _ = image.shape
landmarks = []

if results.pose_landmarks:
mp_drawing.draw_landmarks(output_image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
for landmark in results.pose_landmarks.landmark:
landmarks.append((int(landmark.x * width), int(landmark.y * height), (landmark.z * width)))

return output_image, landmarks


def calculateAngle(a, b, c):
a = np.array(a)
b = np.array(b)
c = np.array(c)

ba = a - b
bc = c - b

cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
angle = np.arccos(np.clip(cosine_angle, -1.0, 1.0))
return np.degrees(angle)


def classifyPose(landmarks, output_image, selected_asana, display=False):
label = "Unknown Pose"
color = (0, 0, 255)

if not landmarks or len(landmarks) < 33:
cv2.putText(output_image, label, (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, color, 2)
return output_image, label

# Extract key joint angles
left_elbow_angle = calculateAngle(landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value],
landmarks[mp_pose.PoseLandmark.LEFT_ELBOW.value],
landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value])

right_elbow_angle = calculateAngle(landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value],
landmarks[mp_pose.PoseLandmark.RIGHT_ELBOW.value],
landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value])

left_shoulder_angle = calculateAngle(landmarks[mp_pose.PoseLandmark.LEFT_ELBOW.value],
landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value],
landmarks[mp_pose.PoseLandmark.LEFT_HIP.value])

right_shoulder_angle = calculateAngle(landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value],
landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value],
landmarks[mp_pose.PoseLandmark.RIGHT_ELBOW.value])

left_knee_angle = calculateAngle(landmarks[mp_pose.PoseLandmark.LEFT_HIP.value],
landmarks[mp_pose.PoseLandmark.LEFT_KNEE.value],
landmarks[mp_pose.PoseLandmark.LEFT_ANKLE.value])

right_knee_angle = calculateAngle(landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value],
landmarks[mp_pose.PoseLandmark.RIGHT_KNEE.value],
landmarks[mp_pose.PoseLandmark.RIGHT_ANKLE.value])

hip_distance = np.linalg.norm(np.array(landmarks[mp_pose.PoseLandmark.LEFT_HIP.value][:2]) -
np.array(landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value][:2]))

# Check only the selected asana
if selected_asana == "Trikonasana":
if (165 < left_knee_angle < 195 and 165 < right_knee_angle < 195 and
130 < left_elbow_angle < 180 and 175 < right_elbow_angle < 220):
label = "Trikonasana"

elif selected_asana == "Virabadrasana":
if (90 < left_knee_angle < 120 and 165 < right_knee_angle < 195):
label = "Virabadrasana"

elif selected_asana == "Vrikshasana":
if (315 < left_knee_angle < 335 or 25 < right_knee_angle < 45):
label = "Vrikshasana"

elif selected_asana == "Bhujangasana":
if (160 < left_elbow_angle < 190 and 160 < right_elbow_angle < 190 and
50 < left_shoulder_angle < 80 and 50 < right_shoulder_angle < 80):
label = "Bhujangasana"

elif selected_asana == "Sukhasana":
if (40 < left_knee_angle < 70 and 40 < right_knee_angle < 70 and
60 < left_shoulder_angle < 90 and 60 < right_shoulder_angle < 90 and hip_distance < 150):
label = "Sukhasana"

elif selected_asana == "Chakrasana":
if (240 < left_elbow_angle < 280 and 240 < right_elbow_angle < 280 and
250 < left_knee_angle < 290 and 250 < right_knee_angle < 290):
label = "Chakrasana"

# If the correct pose is detected, turn the label green
if label == selected_asana:
color = (0, 255, 0) # Green if pose matches
else:
label = "Unknown Pose"

cv2.putText(output_image, label, (10, 30), cv2.FONT_HERSHEY_PLAIN, 2, color, 2)
return output_image, label


def webcam_feed(selected_asana):
camera_video = cv2.VideoCapture(0)
camera_video.set(3, 1380)
camera_video.set(4, 960)

while camera_video.isOpened():
ok, frame = camera_video.read()
if not ok:
continue

frame = cv2.flip(frame, 1)
frame_height, frame_width, _ = frame.shape
frame = cv2.resize(frame, (int(frame_width * (640 / frame_height)), 640))

frame, landmarks = detectPose(frame, pose, display=False)

if landmarks:
frame, detected_asana = classifyPose(landmarks, frame, selected_asana, display=False)

# Display Accuracy
if detected_asana == selected_asana:
accuracy_text = f"{detected_asana}, 100%"
else:
accuracy_text = "Unknown Pose, 0%"

cv2.putText(frame, accuracy_text, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)

ret, jpeg = cv2.imencode('.jpg', frame)
frame = jpeg.tobytes()

yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

camera_video.release()
cv2.destroyAllWindows()


@app.route('/')
def index():
return render_template('index.html')

@app.route('/yoga_try')
def yoga_try():
asana = request.args.get('asana', 'Unknown')
return render_template('yoga_try.html', asana=asana)

@app.route('/video_feed1')
def video_feed1():
asana = request.args.get('asana', 'Unknown')
return Response(webcam_feed(asana), mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__ == '__main__':
app.run(debug=True)
11 changes: 11 additions & 0 deletions PRANA/models/Message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require('mongoose');
const messageSchema = new mongoose.Schema({
from: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, // Sender
to: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, // Receiver
text: { type: String, required: true }, // Message content
timestamp: { type: Date, default: Date.now }, // Time when the message was sent
});

const Message = mongoose.model('Message', messageSchema);

module.exports = Message;
15 changes: 15 additions & 0 deletions PRANA/models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
username: { type: String, unique: true, required: true },
email: { type: String, unique: true, required: true },
password: { type: String, required: true }, // Password will be hashed
friends: [{
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User'},
lastChatTime: { type: Date, default: Date.now }
}] // References to other users they are chatting with
});

const User = mongoose.model('User', userSchema);

module.exports = User;
Loading