How to detect biggest face in Java [closed]

asked 2014-06-25 17:18:59 -0600

Robby18 gravatar image

updated 2014-06-29 13:21:19 -0600

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; 
} 
}
edit retag flag offensive reopen merge delete

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 ( 2014-06-26 01:15:18 -0600 )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 ( 2014-06-26 18:48:52 -0600 )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 ( 2014-06-30 09:42:15 -0600 )edit