← All posts

Hand Distance Tracker: What I Learned From 106 Lines of Hand Tracking

2023CV · Python

MediaPipe gives you 21 hand landmarks per frame. Coordinates for every knuckle, fingertip, and joint. I wanted to see what I could build with just those numbers before adding any real logic.

The Hand Distance Tracker was that experiment. It captures webcam video, detects hands through MediaPipe, and measures pixel distances between adjacent fingertips. Thumb to index. Index to middle. Middle to ring. Ring to pinky. The distances display on the feed in real time.

The Setup

Five fingertip indices in MediaPipe are 4, 8, 12, 16, and 20. The thumb tip, index tip, middle tip, ring tip, and pinky tip. The code extracts each coordinate, draws a circle at the point, connects adjacent tips with a line, and writes the pixel distance at the midpoint.

The hand skeleton comes from MediaPipe built-in drawing utilities. The fingertip markers are custom. Outer black circle, inner blue filled circle. Small visual choice, but it made the landmarks readable against different backgrounds.

The Scaling Problem

Pixel distances mean nothing without a reference. I used a hardcoded scaling factor of 30 pixels per centimeter. That is an estimate. It is not calibrated to any real world measurement.

The code calls it random_number. That name is honest. A real measurement tool would need a calibration step where the user holds their hand against a known distance. This project skips that. The numbers on screen are relative, not absolute.

What It Represented

This was one of the first projects where I used MediaPipe at all. Before this, computer vision meant training or downloading models. After this, I understood that a well designed API could make pose and hand tracking feel like calling a function.

The code has unused variables and an unused import. The scaling factor is a guess. The measurements are not accurate. None of that mattered. The project was never about measuring hands. It was about seeing what coordinates could do.

Twenty-one landmarks per frame. That is where every hand tracking project I built later started.

View all projects →View on GitHub ↗