Saturday, April 10, 2010

Hand isolation in OpenCV

This week I've been working on some hand-detection algorithms in Python and OpenCV. I have come up with a simple and fairly accurate combination of filters that can isolate my skin tone from a range of backgrounds in a range of lighting conditions.

Overhead artificial lighting (click to enlarge).

Natural back-lighting (click to enlarge).

The Python script separates (in real-time) the RGB image from the webcam into Hue, Saturation and Value. The hue is filtered to the red band (which is the base hue of my skin) and the saturation is filtered to discard the bottom 25% (the lower the saturation, the greater the chance of error in the hue calculation). The filtered saturation and hue are then combined with an AND operation to return a highlighting of the hand.