← All projects

HandTracked-Tennis-C

Webcam-controlled tennis game in C/C++. OpenCV tracks your hand in real time, SDL2 handles the rendering and physics.

Problem

Wanted a webcam-controlled tennis game where you wave your hand in front of the camera and the paddle follows. Tag on the GitHub repo is literally #bored.

Role

Solo.

How it works

main.c handles startup, the camera prompt, and CLI flags (hand_tennis [difficulty] [fps]). hand_tracker.cpp runs OpenCV capture at 640x480 with a multi-stage tracker: an optional YOLOv8 palm detector loaded from ONNX, YCrCb + HSV skin segmentation, MOG2 motion, a Kalman filter with an 8-frame coast for when tracking drops out, adaptive skin bounds, and a Haar face-cascade masking pass so your face doesn't get read as your hand. Coordinates normalise to 0-100.

physics.c runs the ball dynamics (gravity, damping, spin transfer, a max-speed cap). ai_opponent.c has four difficulty tiers with different reaction delay, prediction depth, and speed multipliers. rendering.c uses SDL2 for the 1520x720 window and the HUD, since the SDL preview behaves better on Windows than OpenCV's highgui. First to 11 wins.

Stack
C C++ OpenCV SDL2 SDL2_ttf CMake Computer Vision Game Dev
Result

Working with CMake builds for both Linux and Windows. Tuning knobs exposed as env vars: HAND_TENNIS_CAMERA_INDEX, HAND_TENNIS_MODEL, HAND_TENNIS_HAAR.