Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make library that show as how many people are using it so i think i should count the number of user by detecting their face through java openCv. I want to count number of people in the image, using that library.

What I have tried:

am using the defult OPenCV FACE detecthion but how can i count it
Posted
Updated 20-May-17 23:28pm
v2

1 solution

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,
Java
// Detects the faces
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(); // Converts the faces to array
int people = facesArray.length;      // Number of people

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900