{"id":22514454,"url":"https://github.com/shamiul5201/sitting-posture-analysis","last_synced_at":"2026-04-08T21:32:00.134Z","repository":{"id":264338578,"uuid":"893068035","full_name":"shamiul5201/Sitting-Posture-Analysis","owner":"shamiul5201","description":"A side-view posture analysis application that detects a person's posture, measures neck and torso inclination angles, monitors bending below a threshold, tracks posture duration, and ensures proper camera alignment for accurate side-view detection.","archived":false,"fork":false,"pushed_at":"2024-11-28T01:06:45.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-13T20:54:05.978Z","etag":null,"topics":["computer-vision","machine-learning","mediapipe","opencv","pygame","streamlit"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shamiul5201.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-23T12:59:05.000Z","updated_at":"2024-11-28T01:06:49.000Z","dependencies_parsed_at":"2025-02-02T03:26:01.557Z","dependency_job_id":"257e5dfb-14ea-40fe-ba2a-6c62e8fe0ca4","html_url":"https://github.com/shamiul5201/Sitting-Posture-Analysis","commit_stats":null,"previous_names":["shamiul5201/sitting-posture-analysis"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shamiul5201/Sitting-Posture-Analysis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shamiul5201%2FSitting-Posture-Analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shamiul5201%2FSitting-Posture-Analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shamiul5201%2FSitting-Posture-Analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shamiul5201%2FSitting-Posture-Analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shamiul5201","download_url":"https://codeload.github.com/shamiul5201/Sitting-Posture-Analysis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shamiul5201%2FSitting-Posture-Analysis/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31575483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","machine-learning","mediapipe","opencv","pygame","streamlit"],"created_at":"2024-12-07T03:18:00.934Z","updated_at":"2026-04-08T21:32:00.122Z","avatar_url":"https://github.com/shamiul5201.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Sitting-Posture-Analysis\nThis documentation provides an in-depth overview of a Python-based application for analyzing sitting posture using MediaPipe, OpenCV, Streamlit, and Pygame. It leverages computer vision and pose estimation to determine whether a user's posture is aligned correctly and provides feedback accordingly. Below is a breakdown of the code and its components.\n\n### Dependencies\nThe application requires the following libraries:\n\n* **OpenCV**: For video capture and image processing.\n* **Math**: For angle calculations.\n* **MediaPipe**: For pose detection.\n* **Pygame**: To play audio alerts.\n* **Streamlit**: For the user interface.\n* **NumPy**: For numerical operations.\n\n## Mediapipe Pose\nMediaPipe Pose is a machine learning solution for high-fidelity body pose tracking that infers 33 3D landmarks and a background segmentation mask on the entire body from RGB video frames using BlazePose research, which also drives the ML Kit Pose Detection API.\n\n**Scenary of The Points from Mediapipe Pose:**\n![77738pose_tracking_full_body_landmarks](https://github.com/user-attachments/assets/26d2cb7b-eecb-4cd2-ab91-fe1da617a692)\n\n\nBelow is the workflow of our Body Posture Detection System\n\n\n![workflow](https://github.com/user-attachments/assets/9692d790-31e1-471d-b5ad-5212e3fbf03a)\n\n\n## Core Functions\n### Camera Selection\nat first, imported the required libraries which are:\n```python\ndef get_camera_dict():\n    ...\n\n```\nDetects and lists available cameras (up to 5) on the system, assigning them unique labels (e.g., \"Camera 1\").\n\nInput: None.\nOutput: A dictionary mapping camera labels to their respective indices.\nKey Feature: Defaults to the first camera in the list.\n\n### Angle Calculation\n\nThe setup requires the individual to be positioned in the correct side view. The function find_angle determines the offset angle between three points, such as the hips, eyes, or shoulders, which are generally symmetric about the central axis of the human body.\n![angle](https://github.com/user-attachments/assets/6925702c-b4b5-4e94-8a3e-e7f2700b7e81)\n\nThe angle between three points, with one serving as the reference point, is calculated using the following equation:\n\n$$\n\\theta = \\arccos \\left( \\frac{\\overrightarrow{P_1 ref} \\cdot \\overrightarrow{P_2 ref}}{|\\overrightarrow{P_1 ref}| \\cdot |\\overrightarrow{P_2 ref}|} \\right)\n$$\n\n```python\ndef find_angle(p1, p2, ref_pt=np.array([0, 0])):\n    ...\n\n```\nCalculates the angle between two points relative to a reference point.\n\nInput: Two points `(p1, p2)` and a reference point `(ref_pt)`.\nOutput: The angle in degrees.\n\n### Landmark Handling\n* **`get_landmark_array`**: Converts normalized MediaPipe landmarks to pixel coordinates.\n* **`get_landmark_features`**: Extracts specific landmarks (nose, shoulder, ear, hip) based on user-specified features.\n\n### MediaPipe Pose Initialization\n```python\n@st.cache(allow_output_mutation=True)\ndef get_mediapipe_pose():\n    ...\n```\nInitializes the MediaPipe Pose estimator to detect body landmarks.\n\n## Streamlit Interface\nThe application uses **Streamlit** to create an interactive interface.\n\n### Camera Selection\n```python\ncamera_dict = get_camera_dict()\nselected_option = st.selectbox(\"Select Camera\", options=sorted(camera_dict.keys()))\n```\nDisplays available cameras for the user to choose from.\n\n### Threshold Controls\n```python\nOFFSET_THRESH = st.sidebar.slider(\"Offset Threshold:\", 0.0, 40.0, 30.0, 10.0)\n...\n\n```\nAllows users to adjust thresholds for:\n* Offset angle.\n* Neck and torso inclination angles.\n* Time delay before triggering an alarm.\n  \n### Posture Monitoring\nThe live camera feed is displayed using:\n```python\nFRAME_WINDOW = st.image([])\n```\nA \"START\" button toggles posture analysis, while a \"STOP\" button halts it.\n\n\n## Posture Analysis\n### Landmark Detection\n\nLandmarks for the nose, shoulders, ears, and hips are identified using MediaPipe.\n\n### Camera Alignment\nChecks the alignment of the camera based on the offset angle:\n```python\nif abs(offset_angle) \u003e OFFSET_THRESH:\n    ...\nelse:\n    ...\n```\n\n### Posture Evaluation\n* **Good Posture**: When neck and torso inclinations fall within the specified thresholds.\n* **Bad Posture**: When any threshold is exceeded.\n  \nVisualization:\n* Displays angle values and joins key landmarks with colored lines.\n* Colors indicate posture correctness (e.g., green for good, red for bad).\n\n## Alarms and Feedback\nIf a bad posture persists for a specified duration, an alarm sound is played:\n```python\nplay_sound.play()\n```\n\n## Key Features\n* **Real-time Posture Monitoring**: Detects and visualizes posture in live video.\n* **Customizable Thresholds**: Users can tweak posture thresholds and response times.\n* **Audio Feedback**: Alerts users when poor posture is detected.\n* **Streamlit Integration**: Provides an intuitive web-based interface.\n\n## Running the Application\n1. Save the code in a file, e.g., posture_analysis.py.\n2. Run the application with:\n```python\nstreamlit run posture_analysis.py\n```\n3. Adjust camera settings and thresholds in the interface.\n4. Start the posture analysis and observe feedback in real-time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshamiul5201%2Fsitting-posture-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshamiul5201%2Fsitting-posture-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshamiul5201%2Fsitting-posture-analysis/lists"}