← All posts

DanceBox: 174 Lines of Pose Estimation Meets Rhythm Gaming

2024CV · Python

Just Dance requires a console, a phone, and a subscription. I wanted to see how close a webcam and 174 lines of Python could get to the same experience.

DanceBox uses MediaPipe Pose to track your body and two scoring systems to reward movement. Green target boxes appear on screen. Hitting them with your body scores points. Performing the correct dance move scores more. The game runs at real time with no special hardware.

The Two Scoring Systems

The first system checks specific dance moves. Raise your left arm and the game detects it by comparing your elbow y-coordinate to your shoulder. Raise your right arm the same way. Shift your weight left or right by comparing your hip position to the frame center. Each correct move awards ten points.

The second system spawns target boxes in predefined body regions. Head, left arm, right arm, left leg, right leg, torso. Any body part that enters the box triggers a hit. The box disappears and respawns after half a second. Another ten points.

The two systems run independently. You can score from a correct move, a target hit, or both at the same time.

The Display Split

OpenCV shows the webcam feed with pose landmarks and target boxes drawn over it. Pygame runs a separate window with the score and move instructions in large text. Two windows, one game loop.

This split is not elegant. The player has to look at both windows to get the full picture. A single overlay would be better. But for 174 lines, it was the fastest way to get text rendering without fighting OpenCV font limitations.

What I Would Change

The move detection is oversimplified. It checks one joint relationship per move and calls it validated. A real dance game would track full pose sequences over time and score based on timing, not just position.

The scoring is decoupled from the move you are supposed to perform. Any body part in the target box counts as a hit, even if it is not the part the game asked you to move. The two systems reward different things and sometimes conflict.

There is no audio. No music, no beat, no cue sounds. A dance game without sound is missing the entire rhythm component. That was a scope decision that I would reverse in a second version.

It is not a great dance game. It is a proof that pose estimation can drive interactive play without a console. One webcam, 174 lines, and a few green boxes on screen. That is enough to make you move.

View all projects →View on GitHub ↗