2

I got a requirement to display only face from an image. But, I am trying to use only android native methods to implement this.

I have gone through the following link

Crop Image with face detection in android

But, the code mentioned in the above link is not working for all images.

Please guide me if anyone has already got the same requirement.

Thanks.

Community
  • 1
  • 1
  • 1
    What exactly is not working? Does the face detection fail, or does it not extract a circle correctly? – GvS Jun 17 '14 at 12:39
  • Hi and welcome to Stack Overflow. Please edit your post to contain your code, including examples where it worked and where it didn't and error messages if there were any. – Noich Jun 17 '14 at 12:55
  • @GVS: Hi, I have used the code I have mentioned in the link, But the code is working only for some images and It is not working for Image containing more than 1 face. – user3748388 Jun 18 '14 at 05:05
  • @Noich: Hi Noich, I have used the same code mentioned in the below link http://stackoverflow.com/questions/22552027/crop-image-with-face-detection-in-android – user3748388 Jun 18 '14 at 05:11

2 Answers2

0

A face detection algorithm is never (and will never be) accurate. Even humans sometimes see the face of jezus in a toast. How can you expect computers to detect a face 100% correctly, if even the reference implementation (the human brain) contains bugs.

You should include a fallback scenario, when there is no (or more as one) face detected. Or do some quality check on the pictures before they are used.

GvS
  • 52,015
  • 16
  • 101
  • 139
-1

You can use this rounded rectangle code with bigger corner radius to achieve a circle (recipe by Romain Guy):

BitmapShader shader;
shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);

RectF rect = new RectF(0.0f, 0.0f, width, height);

// rect contains the bounds of the shape
// radius is the radius in pixels of the rounded corners
// paint contains the shader that will texture the shape
canvas.drawRoundRect(rect, radius, radius, paint);
Eran Goldin
  • 980
  • 12
  • 21
  • Hi Eran, Thanks for your reply, I have no problem in displaying bitmap in a circle. I am not able to detect only face from the image. Face detection part I need help, to convert only face to bitmap. – user3748388 Jun 18 '14 at 05:07
  • I would suggest rephrasing the question as what you're actually asking is not clear. – Eran Goldin Jun 18 '14 at 06:38