Skip to content

anand-devx/posture-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Posture Guard - Real-time Posture Detection System

A modern web application that uses AI-powered pose detection to analyze and provide feedback on posture during squats and desk sitting. Built with React, Node.js, and MediaPipe.

πŸš€ Features

  • Real-time Posture Analysis: Upload videos or use webcam for live posture detection
  • Dual Mode Detection: Specialized analysis for squats and desk sitting postures
  • Rule-based Feedback: Intelligent posture assessment with specific warnings
  • Visual Overlays: Pose landmarks and angle measurements displayed on video and images
  • Modern UI: Clean, responsive interface with real-time feedback panels
  • File Management: Secure upload and processing of videos

πŸ› οΈ Tech Stack

Frontend

  • React 18 - Modern UI library with hooks
  • TypeScript - Type-safe JavaScript
  • Tailwind CSS - Utility-first CSS framework
  • Lucide React - Beautiful icons
  • Vite - Fast build tool

Backend

  • Node.js - JavaScript runtime
  • Express - Web framework
  • Multer - File upload handling
  • CORS - Cross-origin resource sharing

Python

  • MediaPipe - Pose detection and landmark extraction
  • OpenCV - Computer vision and image processing
  • Python - AI processing scripts

πŸ“‹ Prerequisites

  • Node.js (v16 or higher)
  • Python (v3.8 or higher)
  • npm or yarn

πŸ”§ Installation

1. Clone the Repository

git clone https://github.com/anand-devx/posture-guard.git
cd posture-guard

2. Install Frontend Dependencies

cd frontend
npm install

3. Install Backend Dependencies

cd.. # not needed if already using from root directory
cd backend
npm install

4. Install Python Dependencies

cd python # Or cd backend/python if using from root directory
pip install -r requirements.txt

πŸ“ Environment Variables

Rename the file named .env.sample to .env in the backend directory and add the following:

PORT=3001                               # βœ… Port your local server will run on
CLOUD_NAME=your_cloudinary_cloud_name   # βœ… Cloudinary cloud name
API_KEY=your_cloudinary_api_key         # βœ… Cloudinary API key
API_SECRET=your_cloudinary_api_secret   # βœ… Cloudinary API secret
CORS_ORIGIN=*                           # βœ… Allowed CORS origin(s); * means allow all (use carefully in production)

πŸ”’ Good practice

Always add .env to .gitignore to avoid committing secrets:

// .gitignore
.env

🚦 Running the Application

Change Server in Frontend

In fronend/src/App.tsx change the server_url at line 174 to localhost for testing using local backend, and to live_server for using live server. You can also adjust values of localhost and live_server

// frontend/src/App.tsx : line 172
const localhost = 'http://localhost:3001/api/analyze'; // You can change the port from 3001 to anything here

// frontend/src/App.tsx : line 173
const live_server = 'https://posture-guard.onrender.com/api/analyze'; // You can change the live server here

// frontend/src/App.tsx : line 174
const server_url = live_server; // for using live server
const server_url = localhost; // for using localhost

Development Mode (Recommended)

# From frontend and backend directory separately run
npm run dev

This will start both the frontend (port 5173) and backend (port 3001) servers.

🎯 Usage

1. Select Posture Type

  • Choose between "Squat Analysis" or "Sitting Analysis"

2. Upload Video/Image or Use Webcam

  • File Upload: Drag and drop video files (MP4, AVI, MOV, JPG, PNG formats supported)
  • Webcam: Click "Start Webcam" for real-time capture

3. Analyze Posture

  • Click "Analyze Posture" to process your video/image
  • View real-time feedback in the side panel

4. Review Results

  • Check posture quality indicators
  • View angle measurements
  • Get the proccessed image/video with detection results and angles

πŸ” Posture Analysis Rules

Squat Analysis

  • Knee Position: Flags if knee extends beyond toe
  • Back Angle: Warns if back angle < 30Β° or > 60Β° with respect to thigh
  • Depth Check: Ensures proper squat depth

Sitting Analysis

  • Neck Posture: Detects forward head posture (> 20Β°)
  • Back Alignment: Checks for neutral spine position wrt thigh
  • Overall Posture: Comprehensive sitting assessment

πŸ“Š API Endpoints

POST /api/analyze

Analyze posture in uploaded video

  • Body: FormData with file and postureType
  • Response: Analysis results with feedback

GET /api/

Health check endpoint

  • Response: Server Name

🎨 UI Components

Main Interface

  • Upload Zone: Drag-and-drop file upload
  • Webcam Panel: Live video capture
  • Control Buttons: Analysis and upload controls

Feedback Panel

  • Real-time Status: Good/poor posture indicators
  • Angle Measurements: Precise angle calculations
  • Warnings: Specific posture improvement suggestions

πŸ”§ Configuration

Customization

  • Modify posture rules in backend/python/posture_analyzer.py
  • Adjust UI colors in tailwind.config.js
  • Update analysis parameters in server configuration

πŸ“ Project Structure

posture-guard-ai/
β”œβ”€β”€ backend/                         # Backend server and API
β”‚   β”œβ”€β”€ package.json                 # Node.js backend dependencies
β”‚   β”œβ”€β”€ requirements.txt             # Python dependencies for posture analysis
β”‚   β”œβ”€β”€ server.js                    # Express server entry point
β”‚   β”œβ”€β”€ .env.sample
β”‚   β”œβ”€β”€ src/                         # Backend source code
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   └── cloudinary.js        # Cloudinary config
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚   └── analysisController.js
β”‚   β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”‚   β”œβ”€β”€ errorHandler.js
β”‚   β”‚   β”‚   └── upload.js
β”‚   β”‚   β”œβ”€β”€ python/
β”‚   β”‚   β”‚   └── posture_analyzer.py  # Python script for posture analysis
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   └── analysisRoutes.js
β”‚   β”‚   β”œβ”€β”€ temp/                    # Temporary and processed files
β”‚   β”‚   β”‚   β”œβ”€β”€ *.jpg
β”‚   β”‚   β”‚   β”œβ”€β”€ *.jpeg
β”‚   β”‚   β”‚   └── processed-*.jpg
β”‚   β”‚   └── utils/
β”‚   β”‚       β”œβ”€β”€ cloudinaryUpload.js
β”‚   β”‚       └── runPythonScript.js
β”œβ”€β”€ frontend/                        # Frontend React app
β”‚   β”œβ”€β”€ package.json                 # Frontend dependencies
β”‚   β”œβ”€β”€ index.html                   # Main HTML file
β”‚   β”œβ”€β”€ eslint.config.js
β”‚   β”œβ”€β”€ postcss.config.js
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   β”œβ”€β”€ tsconfig.app.json
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”œβ”€β”€ tsconfig.node.json
β”‚   β”œβ”€β”€ vite.config.ts
β”‚   └── src/
β”‚       β”œβ”€β”€ App.tsx                  # Main React component
β”‚       β”œβ”€β”€ index.css                # Global styles
β”‚       β”œβ”€β”€ main.tsx                 # React entry point
β”‚       β”œβ”€β”€ vite-env.d.ts
β”‚       └── assets/
β”‚           β”œβ”€β”€ logo.svg
β”‚           β”œβ”€β”€ logo2.svg
β”‚           β”œβ”€β”€ logo3.svg
β”‚           β”œβ”€β”€ logo4.svg
β”‚           β”œβ”€β”€ logo5.svg
β”‚           └── meditation-yoga-posture-svgrepo-com.svg
β”œβ”€β”€ .gitignore                       # Git ignore file
β”œβ”€β”€ README.md                        # Project documentation

πŸš€ Deployment

Frontend Deployment (Netlify/Vercel)

npm run build
# Deploy dist/ folder

Backend Deployment (Heroku/Railway/Render)

# Ensure Python and Node.js dependencies are installed
npm install && pip install -r requirements.txt

Full Stack Deployment

  • Frontend: Netlify, Vercel, or GitHub Pages
  • Backend: Render, Railway, or Heroku
  • Database: MongoDB Atlas or PostgreSQL

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ž Support

For support, email anandyadav11206@gmail.com


Made with ❀️ by the Anand