OpenCV returns the rectangles for the faces, and the areas that those "detected" faces cover. If I had to write the program that shows how many faces are there (people have faces, or faces are attached to the people), I would have simply
counted the number of faces returned.
For example, the following code shows a sample of what needs to be done; I modified it to fit your need,
this.faceCascade.detectMultiScale(grayFrame, faces, 1.1,
2, 0 | Objdetect.CASCADE_SCALE_IMAGE,
new Size(this.absoluteFaceSize,
this.absoluteFaceSize), new Size());
Rect[] facesArray = faces.toArray();
int people = facesArray.length;
Face Detection and Tracking — OpenCV Java Tutorials 1.0 documentation[
^]
The code sample can be captured from GitHub,
GitHub - opencv-java/face-detection: Face detection with OpenCV and JavaFX[
^]