1. A method for processing data, comprising: receiving a temporal sequence of depth maps of a scene containing a humanoid form, each depth map comprising a matrix of pixels, at least some of which have respective pixel depth values and correspond to respective locations in the scene; using a digital processor, processing the depth maps so as to identify three-dimensional (3D) connected components in the scene, each connected component comprising a set of the pixels that are mutually adjacent and have mutually-adjacent depth values; identifying separate, first and second connected components as both belonging to the humanoid form, wherein identifying the first and second connected components comprises tracking the connected components over multiple, successive depth maps in the sequence by assigning a common identifier to the first and second connected components in a first depth map in the sequence, and labeling the pixels of the first and second connected components in the depth map with the common identifier in order to determine that the first and second connected components belong to the humanoid form in a second, subsequent depth map; and generating a representation of the humanoid form comprising both of the first and second connected components, such that when the humanoid form in the second depth map is in contact with another object, thereby causing the second connected component to incorporate the other object, the common identifier is used to separate the labeled pixels of the second connected component that belong to the humanoid form from the pixels belonging to other object in order to generate the representation of the humanoid form appearing in the second depth map.