Skip to content

JordiNeil/bad_posture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Posture Detection System

A real-time posture detection system using computer vision to help maintain good sitting posture and prevent neck strain.

Use the new version here: bad-posture

bad_posture

Features

  • Real-time posture detection using webcam
  • Neck angle calculation and monitoring
  • Visual feedback with status and angles
  • Audio alerts for prolonged bad posture
  • Timer display for bad posture duration

Live testing

You can just use it. It's live in https://bad-posture.onrender.com I promise it's not spying or recording anything :)

Requirements

  • Python 3.8 or higher
  • Webcam
  • Audio output capability

Installation

  1. Clone this repository:
git clone https://github.com/JordiNeil/bad_posture.git
  1. Create and activate a virtual environment:

Move to the backend directory

cd backend

Then create and activate a virtual environment:

Windows:

python -m venv venv
venv\Scripts\activate

macOS/Linux:

python3 -m venv venv
source venv/bin/activate
  1. Install the required packages:
pip install -r requirements.txt

Make sure you're in the backend directory and virtual environment is activated

cd backend
uvicorn main:app --reload
  1. Open your web browser and navigate to: http://localhost:8000/docs

  2. Click the "Start Detection" button and allow webcam access when prompted.

  3. Position yourself in front of the webcam

  4. The program will:

    • Show your posture status (Good/Bad)
    • Display your current neck angle
    • Show a timer when in bad posture
    • Play an alert sound after 2 minutes of bad posture

Project Structure

The project has the following structure:

bad_posture/
├── backend/
│   ├── main.py            # FastAPI backend server
│   └── requirements.txt   # Python dependencies
├── frontend/
│   ├── index.html        # Main HTML file
│   ├── styles.css        # Styles
│   ├── app.js            # Frontend JavaScript
│   └── sounds/
│       └── soft-alert.mp3 # Alert sound
└── README.md

Posture Guidelines

  • Good posture: Neck angle between 65° and 100°
  • Bad posture: Neck angle outside this range
  • Try to maintain your head aligned with your shoulders

Troubleshooting

  1. No webcam found:

    • Check webcam connection
    • Try changing camera index (0 or 1) in the code
  2. Sound not playing:

    • Verify sound file exists in correct location
    • Check system audio settings
    • Try using winsound alternative (Windows only)
  3. MediaPipe errors:

    • Ensure good lighting conditions
    • Check if camera is properly positioned

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Running the Application

  1. Activate the virtual environment:

Windows:

venv\Scripts\activate

macOS/Linux:

source venv/bin/activate
  1. Start the application:
cd backend
uvicorn main:app --reload
  1. Open your web browser and navigate to: http://localhost:8000

  2. Click the "Start Detection" button and allow webcam access when prompted.

  3. The application will periodically send images to the backend for processing and update the UI with the posture status.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published