1 | initial version |
As neat as contours are, you probably want to use connectedComponentsWithStats
You pass it the binary image and it returns the number of white spots. The stats it returns include width, height, X and Y centroid, and area. In other words, exactly what you want, in one function call.