HackMIT 2024 · with Sandro Gopal, Hector Astrom and Steven Zhang
GeomPT
Measuring range of motion for physical therapy with just a webcam. 2nd place overall at HackMIT 2024.
- 2nd
- overall, HackMIT 2024
- 1 webcam
- no special hardware
The problem
We built this at HackMIT 2024 as a team of four: Sandro Gopal, Hector Astrom, Steven Zhang and me.
Recovery after an injury depends on patients doing their exercises at home, and therapists mostly find out how it went at the next visit, when they measure range of motion by hand. We wanted therapists to see real measurements between visits without asking patients to buy anything.
How it works
The browser streams webcam frames over a websocket to a Flask server. There, MediaPipe’s pose model finds the joints, OpenCV draws vectors between the limbs, and we compute the joint angle, smoothed with a rolling average so it doesn’t jitter. When the angle crosses a threshold the measurement is captured automatically, so the patient doesn’t have to click anything mid-stretch.
Results are saved per patient and per exercise in Firebase, and the Next.js frontend has a live view, a progress page that charts range of motion over time, and a page of exercises aimed at improving it.
def calculateAngle(a, b, c):
"""Calculate the angle between three points (a, b, c), where b is the vertex."""
a, b, c = np.array(a), np.array(b), np.array(c)
ba = a - b
bc = c - b
# add epsilon to avoid division by zero
cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc) + 1e-6)
cosine_angle = np.clip(cosine_angle, -1.0, 1.0) # float error
return np.degrees(np.arccos(cosine_angle))What I learned
Getting a believable angle out of noisy pose landmarks in real time was most of the work: camera position, smoothing, and deciding when a reading counts. Doing it in a weekend meant picking the one flow that mattered (measure, save, show progress) and making that solid for the demo.