'Counting each label in KMeans - OpenCV

So I have a program which takes an image and displays its most prominent colours and compactness.

double compactness = kmeans(data, k, labels, TermCriteria(TermCriteria::MAX_ITER, 10, 1.0), 3, KMEANS_PP_CENTERS, centers);

What I want to do now is to take the amount of data points initalized to a cluster and create a percentage. This involves the labels variable, which creates a bunch of "0s", "1s", and so forth depending on their cluster. How would I be able to count each of these labels?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source