How to detect biggest face in Java [closed]

asked Jun 25 '14

Robby18 gravatar image

updated Jun 29 '14

Hi,

I have a question to ask, how do I find the biggest face in an image? When I did this program in C + + code was as follows:

cascade.detectMultiScale (Img, objects, 1.1f, 4, CASCADE_FIND_BIGGEST_OBJECT, Size (20, 20));

Where, exactly, I used the tag: CASCADE_FIND_BIGGEST_OBJECT

to identify the largest face.

But in Java as I do? In the documentation http://docs.opencv.org/java/org/opencv/objdetect/CascadeClassifier.html#detectMultiScale(org.opencv.core.Mat, org.opencv.core.MatOfRect, double, int, int, org.opencv.core.Size, org.opencv.core.Size))

I read this:

flags - Parameters with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.

So how do I?

Thank you.

[Edit.]

Solved:

I solved it this way:

MatOfRect faceDetections = new MatOfRect(); 
faceDetector.detectMultiScale (image, faceDetections);
Rect biggestFace=new Rect(); 
for (Rect rect: faceDetections.toArray ()) 
{ 
if (rect.area ()> biggestFace.area ()) 
{ 
biggestFace = rect; 
} 
}
Preview: (hide)

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-28 14:06:57.981725

Comments

2

http://docs.opencv.org/java/org/opencv/objdetect/Objdetect.html

bit hard to find, but it's Objectdetect.CASCADE_FIND_BIGGEST_OBJECT

berak gravatar imageberak (Jun 26 '14)edit

Thanks for the reply. However it does not work. In the documentation it says that: flags - Parameters with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.

So that means that tag does not work with the new version 2.4.9, right?

So how can I do?

Robby18 gravatar imageRobby18 (Jun 27 '14)edit

You should loop over detections like you do indeed and check for the largest size of rectangle. The parameter is kind of obsolete afaik.

StevenPuttemans gravatar imageStevenPuttemans (Jun 30 '14)edit