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
- 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
You can just use it. It's live in https://bad-posture.onrender.com I promise it's not spying or recording anything :)
- Python 3.8 or higher
- Webcam
- Audio output capability
- Clone this repository:
git clone https://github.com/JordiNeil/bad_posture.git- Create and activate a virtual environment:
Move to the backend directory
cd backendThen create and activate a virtual environment:
python -m venv venv
venv\Scripts\activatepython3 -m venv venv
source venv/bin/activate- Install the required packages:
pip install -r requirements.txtcd backend
uvicorn main:app --reload-
Open your web browser and navigate to: http://localhost:8000/docs
-
Click the "Start Detection" button and allow webcam access when prompted.
-
Position yourself in front of the webcam
-
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
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
- Good posture: Neck angle between 65° and 100°
- Bad posture: Neck angle outside this range
- Try to maintain your head aligned with your shoulders
-
No webcam found:
- Check webcam connection
- Try changing camera index (0 or 1) in the code
-
Sound not playing:
- Verify sound file exists in correct location
- Check system audio settings
- Try using winsound alternative (Windows only)
-
MediaPipe errors:
- Ensure good lighting conditions
- Check if camera is properly positioned
Contributions are welcome! Please feel free to submit a Pull Request.
- Activate the virtual environment:
Windows:
venv\Scripts\activatemacOS/Linux:
source venv/bin/activate- Start the application:
cd backend
uvicorn main:app --reload-
Open your web browser and navigate to: http://localhost:8000
-
Click the "Start Detection" button and allow webcam access when prompted.
-
The application will periodically send images to the backend for processing and update the UI with the posture status.
