This is an augmented reality snakeball game I wrote using C++,
the OpenCV library and
It can be played on Linux using a web camera and a flashlight. Better to turn off light sources
brighter than the flashlight while playing!
A video of the game where I collect balls that appear at random screen positions using a flashlight.
Looking at the screen is like looking at a "mirror" where balls appear:
Short algorithm description:
The program communicates with the user's web camera and takes frames periodically. A copy
of each frame is mirrored to be used as the background image (so that the user has the impression
that he/she sees himself/herself in the mirror while looking at the screen).
The frame is then converted to
grayscale. A Gaussian filter and a threshold are applied in order to get a binary image with
white "blobs" for the light sources and the lighted surfaces. Assuming that
the flashlight is the largest blob on the frame (since the room is dark and we don't use other
brighter or closer to the camera light sources) we calculate the largest
blob's AABB and use the position of its
center point as the mouse pointer position.
For the rendering part,
spheres are rendered in random positions in
front of the textured quad on which the rotated current frame appears.
Every time that a change occurs in the texture (current frame) we test
intersections between a sphere and the pointer. When an intersection
occurs the sphere is "collected" and rendered behind the others that follow the pointer.
A version of the source code that runs on Linux (might not work with all cameras) can be downloaded
from here. It needs OpenCV and its dependencies to compile properly.