且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何计算java opencv中的人数

更新时间:2023-12-02 17:37:28

OpenCV返回面部的矩形和区域这些被发现的面孔覆盖。如果我必须编写显示有多少面孔的程序(人们有面孔,或面孔附着在人们身上),我只需要计算返回的面孔数量。



例如,以下代码显示了需要完成的示例;我修改它以满足您的需要,

  //  检测面 
.faceCascade.detectMultiScale(grayFrame,faces, 1 1
2 0 | Objdetect.CASCADE_SCALE_IMAGE,
new 大小( .absoluteFaceSize,
this .absoluteFaceSize), new Size());

Rect [] facesArray = faces.toArray(); // 将面转换为数组
int people = facesArray.length; // 人数



人脸检测和跟踪 - OpenCV Java Tutorials 1.0文档 [ ^ ]



代码示例可以从GitHub中获取, GitHub - opencv-java / face-detection:使用OpenCV和JavaFX进行人脸检测 [ ^ ]


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

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,
// 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[^]