Banner
← Return to Projects

Posture Police

December 2025Vision LearningAppMacOSAISwiftPythonYOLOv8OpenCVrumpsSQLiteMatplotlibSeabornpandasSwiftSwiftUIApple VisionCoreMLMacOS
Project StatusIn Progress
RoleLead Developer (Solo)

Update: Posture Police got a full rebuild! This page starts with V1 (Python + YOLO). Scroll down for V2, the native Mac app 🚓

The Problem

Like most developers, I sometimes spend 12+ hours a day at my desk. My posture isn't perfect, and by the end of the day, my back can get a little sore...

I also forget to drink water for hours at a time during deep-focus sessions.

I couldn't really find any real solutions to my problem. Most existing solutions usually just set a timer (annoying) or require you to buy expensive hardware.

I realized I already have a camera pointing at my face all day, so I built Posture Police: an AI-powered menu bar app that watches my posture in real-time and forces me to stay healthy.

The Stack

  • Brain: Ultralytics YOLOv8 (Pose Estimation + Object Detection).
  • GUI: rumps (A simple python wrapper for macOS menu bar apps).
  • Database: SQLite (To log every second of my posture history).
  • Analytics: Matplotlib & Seaborn (For the dark-mode dashboard).
Project Github

How it Works

The app runs quietly in the macOS menu bar (🤖🟢). Every second (or more often, if I'm checking the HUD), it grabs a frame from the webcam and runs two inference models:

  1. Pose Estimation: Detects my nose and shoulders. If my nose drops too close to my shoulders relative to my "calibrated" good posture -> the score drops.
  2. Object Detection: Specifically trained to look for my water bottle, so the system knows the last time I drank water.
  3. Instant Feedback: The app icon changes color based on my posture. eg: Good posture: 🤖🟢 and bad posture: 🤖🔴
  4. Data Collection: Every second of data is stored in a secure local database.
  5. Data Visualization: When viewing the dashboard, statistics about posture quality are visible.
  6. Intant Reminders: As soon as posture quality is low for too long, the app sends a little notification telling you to straighten up 🤓.

The Build Process

I've used Python in the past, but this was my first time ever using the YOLO (You Only Look Once) family of models. Luckily, AI is always there to help me. I used OpenCV to manage my camera feed, and soon enough, we had YOLO up and running.

YOLO on human
The YOLOv8n-pose model identifying key body landmarks.

Data Collection

Next, I needed to collect pose data to teach the model what "Good" vs "Bad" posture actually looks like. The YOLO pose model tracks specific points across the body (nose, eyes, shoulders). I logged these normalized coordinates into a massive CSV file.

Data in CSV
Thousands of normalized coordinate points stored in a CSV.

Training the Classifier

Now for the "AI Magic." I recorded myself sitting with good posture and then with bad posture to create a labeled dataset.

I trained a custom classifier (using Scikit-Learn) on top of the YOLO embeddings. This allows the model to output a specific probability score (0-100%) for how "good" my posture is at any given millisecond.

The MacOS App (Rumps)

With the brain ready, I needed a body. I used the rumps library to wrap the python script into a native-feeling macOS Menu Bar app.

It sits quietly in the top bar. When I need to debug (or verify if it sees my water bottle), I can toggle the HUD (Heads Up Display), which draws the OpenCV visualizations in real-time.

In this video, you can see the AI calculating my posture score in real time.

Logic Problem

The hardest part wasn't the AI, it was the UI and the logic flow.

Initially, I had separate logic branches for "Checking Posture" and "Checking Water." This meant if I was drinking water, the app would stop tracking my posture stats, causing gaps in the database.

I had to refactor the main loop to run the logic linearly. Now, the database captures a complete timeline of my day, even when I'm drinking water.

The Dashboard

I didn't want a generic UI. I wanted a cool "Command Center" feel.

I built a custom dashboard using Matplotlib with a strict Dark Mode theme. It queries the local SQLite database to visualize:

  • Weekly Focus: A breakdown of how many hours I spent in "Good" vs. "Bad" posture.
  • Hydration Tracker: Large text showing minutes since the last sip.
  • Daily Score: An aggregated percentage of my sitting quality.
Posture Police Dashboard
The V3 Dashboard: Dark mode, hydration tracking, and historical data.

Future Plans

The current version works, but there's always room for improvement.

  • Gamification: Add a "Streak" system to the menu bar icon so I feel bad about breaking it.
  • Better Data Analytics: The dashboard can definitely be improved, to show posture improvement over weeks or months at a time. Right now, it can get a little cluttered.

🚓 Posture Police V2

V1 worked, but after months of use, the dashboard got pretty cluttered...

The V1 Matplotlib dashboard after months of data, with overlapping dates
V1 after months of data. Also, apparently I haven't had water in 284,818 minutes 💀

So I rebuilt it from scratch as a native macOS menu bar app.

  • No Python, no dock icon, and the whole app is about 22 MB.
  • Everything runs on-device with Apple's Vision framework.
  • Camera frames are never saved.
The Posture Police V2 menu bar icon showing a sitting figure and a score of 100
Sitting pretty: 100/100.

🧠 How V2 Works

Every second, the built-in camera frame goes through Apple Vision: 2D body pose, 3D body pose, face and hands.

No More Training

In V1, I had to record myself sitting well and sitting badly, then train a classifier. V2 needs no training at all.

It learns your upright posture by itself: the best quarter of your last ~30 minutes, only from moments where you face the laptop head-on (so glancing at a side monitor doesn't mess it up). Then it scores you against it:

  • Face getting bigger → you're leaning toward the screen.
  • Nose sinking toward the shoulders → you're slouching.
  • Neck bending forward in Apple's 3D body model (the screen angle doesn't affect this one).
  • Hand on face + tilted head → head on hand.
  • Head tipped down with the body upright → writing on paper. That one doesn't count as a slouch 📝

Camera Moved?

New lid angle, different table, laptop on your lap... When the background at the edges of the frame changes, V2 throws away the old baseline and learns a new one. There's also a manual Recalibrate button in the menu.

The Posture Meter

Your posture is a meter from 0 to 100. It drains while you slouch (faster the worse it is) and refills quickly when you sit back up.

Under 50, the edges of the screen glow red. Stay slouched long enough and you get a real notification.

💧 Water and Standing Up

  • Water: a bottle/cup detector (YOLOv8s converted to CoreML) sees the bottle at your mouth and counts a sip. There's also an I drank water button in the menu. The reminder only comes after 45 minutes on camera without a sip, counted from when you sat down. Never right when you open the laptop.
  • Stand up: sitting for 60 minutes without a 2-minute break triggers a reminder. Standing desk mode turns it off.
  • Quiet mode: no glow and no reminders while another app is using the mic (meetings) or a full-screen app is in front.

📊 The New Dashboard

Click the menu bar icon (or open the app from Spotlight) and you get the dashboard: today's score ring, streak, desk time, good-posture %, slouch time, sips and breaks.

The score chart has Today (hourly), Week, Month (daily) and Year (weekly). Bars are colored by score: Good 85+, OK 70 to 84, Slouchy 50 to 69, and Bad under 50, with a dashed goal line. Hover a bar for the details.

Posture Police V2 dashboard with today's hourly posture scores
Today: 95. Not bad.
Posture Police V2 dashboard with the week's daily posture scores
The week view. Tuesday was a little slouchy.

Remember the future plans from V1? A streak and better analytics over weeks and months. Both done ✅

The Settings tab holds every knob: sensitivity, glow strength, how long before it glows or notifies you, your daily goal, and the stand-up and water timers.

Posture Police V2 settings tab with posture and reminder options
All the knobs.

Pause in One Step

⌥-click the menu bar icon, or open posturepolice://toggle (there's also ://pause, ://resume and ://dashboard). In Alfred, you can make a workflow with a keyword or hotkey wired to an Open URL action with that URL.

🛠️ The V2 Stack

  • Swift and SwiftUI: the menu bar app, dashboard, charts and settings.
  • Apple Vision: body pose (2D and 3D), face and hands.
  • YOLOv8s → CoreML: the water bottle detector.
  • SQLite: one row per minute of posture data.
  • iCloud Drive: a daily backup of the database (when iCloud Drive is on).

It only needs the Xcode Command Line Tools (not full Xcode).

./scripts/install.sh   # build, install to ~/Applications, launch

The build is signed with a local identity, so macOS keeps the camera permission across rebuilds.

Thanks for reading! Remember to sit straight and drink water!

Back to Main Campaigns