Method carried out by a computer for training a tridimensional shape detection classifier for detecting tridimensional shapes from depth images in which each pixel represents a depth distance from a source to a scene, each depth image being divided into one or more patches (I p, I n) of given dimensions, the classifier comprising a forest of at least a binary tree for obtaining the class probability (p) of a given shape comprising nodes associated with a distance function (f) that taking at least a pixel position in a patch calculates a pixel distance, wherein the method comprises per each leaf node of each binary tree the configuration steps of: - creating candidate groups of parameters, each group comprising ∘ at least a pixel position (u, v) in a patch, ∘ a depth clipping window (k) in the patch, and ∘ a pixel distance threshold (θ); - obtaining one or more positive patches (I p) containing at least part of the shape to be detected; - obtaining one or more negative patches (I n) not containing at least part of the shape to be detected; - calculating in the leaf node the distance function (f) of the obtained positive and negative patches using the pixel position (u, v) and depth clipping window (k) of each candidate group of parameters, comparing the result of the distance function with its pixel distance threshold (θ) and computing its statistics as the proportion of positive and negative patches; and - selecting for the leaf node the candidate group of parameters that best separate, according to a predetermined criteria, the positive and negative patches into two groups for calculating the class probability of the shape in that leaf node using the distance function; characterized in that when more than a predefined number of positive or negative patches (I n,I p) are applied to a leaf node of the shape detection classifier, - a new level of the binary tree is created from said leaf node, comprising two newly created leaf nodes; - the statistics from the parent node are passed from the parent node to each respective newly created leaf nodes, wherein the statistics correspond to each of the candidate group of parameters that has been applied in the parent node configuration; and - the configuration steps are applied to the newly created leaf nodes by creating new candidate groups of parameters per leaf node. - creating candidate groups of parameters, each group comprising ∘ at least a pixel position (u, v) in a patch, ∘ a depth clipping window (k) in the patch, and ∘ a pixel distance threshold (θ); ∘ at least a pixel position (u, v) in a patch, ∘ a depth clipping window (k) in the patch, and ∘ a pixel distance threshold (θ); - obtaining one or more positive patches (I p) containing at least part of the shape to be detected; - obtaining one or more negative patches (I n) not containing at least part of the shape to be detected; - calculating in the leaf node the distance function (f) of the obtained positive and negative patches using the pixel position (u, v) and depth clipping window (k) of each candidate group of parameters, comparing the result of the distance function with its pixel distance threshold (θ) and computing its statistics as the proportion of positive and negative patches; and - selecting for the leaf node the candidate group of parameters that best separate, according to a predetermined criteria, the positive and negative patches into two groups for calculating the class probability of the shape in that leaf node using the distance function; - a new level of the binary tree is created from said leaf node, comprising two newly created leaf nodes; - the statistics from the parent node are passed from the parent node to each respective newly created leaf nodes, wherein the statistics correspond to each of the candidate group of parameters that has been applied in the parent node configuration; and - the configuration steps are applied to the newly created leaf nodes by creating new candidate groups of parameters per leaf node.