
gittech. site
for different kinds of informations and explorations.
Posture Detection System: computer vision to prevent neck strain
Posture Detection System
A real-time posture detection system using computer vision to help maintain good sitting posture and prevent neck strain.
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
Requirements
- Python 3.8 or higher
- Webcam
- Audio output capability
Installation
- Clone this repository:
git clone https://github.com/JordiNeil/bad_posture.git
- 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
- 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
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
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
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
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Running the Application
- Activate the virtual environment:
Windows:
venv\Scripts\activate
macOS/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.