Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I agree with the answer by Balaji R. To answer your exact question, the Haar classifier can only detect that there is an object, but cannot detect the exact size. That is because each scale of the classifier will match objects that are the same size as the classifier window , or a bit smaller, or a bit larger. (This is a strength of Haar classifier, it does not miss objects that fall in the gap between 2 scales!) The classifier does not know the size of the match (even in pixels), only the size of the classifier window that matched, which will be very rough estimated.

As Balaji R said. You should do a threshold on your image in the area of the match (possibly adaptive threshold) to get the ball silhouette, then measure the ball area in pixels (it is more accurate than diameter), then determine the distance. You should also undistort the camera image, because otherwise the area and shape of the silhouette will change by lens distortion, and will not correspond accurate to distance.